view src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java @ 63:9f8c9611848a

fixed bug with new rectangle shapes. added limit, offset and sortBy parameters to annotator/ and annotator/search.
author casties
date Fri, 23 Nov 2012 17:55:04 +0100
parents 9f653697437e
children 2b1e6df5e21a
line wrap: on
line source

package de.mpiwg.itgroup.annotations.restlet.utils;

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);
		
		

	}        
	
}