diff src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java @ 28:f4ed2ed33e5b

Restinterface zur Anzeige von Tags hinzugefuegt-
author dwinter
date Tue, 25 Sep 2012 09:32:56 +0200
parents
children 9f653697437e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java	Tue Sep 25 09:32:56 2012 +0200
@@ -0,0 +1,38 @@
+package de.mpiwg.itgroup.annotations.restlet.utils;
+
+import java.util.Comparator;
+
+import de.mpiwg.itgroup.annotations.Annotation;
+
+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);
+    }
+        
+  
+	
+}
\ No newline at end of file