Mercurial > hg > AnnotationManagerN4J
view src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java @ 84:6bf38b5e30a8
also stores polygon shape image annotations.
author | casties |
---|---|
date | Fri, 23 Jan 2015 17:24:53 +0100 |
parents | 2b1e6df5e21a |
children |
line wrap: on
line source
package de.mpiwg.itgroup.annotations.restlet.utils; /* * #%L * AnnotationManager * %% * Copyright (C) 2012 - 2014 MPIWG Berlin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. * #L% * Author: Dirk Wintergruen (dwinter@mpiwg-berlin.mpg.de) */ import java.util.Comparator; import java.util.List; import org.json.JSONException; import org.json.JSONObject; public class JSONObjectComparator implements Comparator<JSONObject>{ private String attributeToSort; public JSONObjectComparator(String attribute){ this.attributeToSort=attribute; } public int compare( JSONObject a, JSONObject b ) { // je quadratischer, desto grösser String sortA; try { sortA = a.getString(attributeToSort); } catch (JSONException e) { sortA =""; } String sortB; try { sortB = b.getString(attributeToSort); } catch (JSONException e) { sortB=""; } return sortA.compareToIgnoreCase(sortB); } /** * Sortiere array nach einem Parameter in den Annotationen * @param results * @return */ public static void sortAnnotations(List<JSONObject> results,String attribute) { JSONObjectComparator comp = new JSONObjectComparator(attribute); java.util.Collections.sort( results, comp); } }