comparison 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
comparison
equal deleted inserted replaced
24:e208a7b1a37a 28:f4ed2ed33e5b
1 package de.mpiwg.itgroup.annotations.restlet.utils;
2
3 import java.util.Comparator;
4
5 import de.mpiwg.itgroup.annotations.Annotation;
6
7 import org.json.JSONException;
8 import org.json.JSONObject;
9
10 public class JSONObjectComparator implements Comparator<JSONObject>{
11
12 private String attributeToSort;
13 public JSONObjectComparator(String attribute){
14 this.attributeToSort=attribute;
15 }
16
17 public int compare( JSONObject a, JSONObject b ) {
18 // je quadratischer, desto grösser
19 String sortA;
20 try {
21 sortA = a.getString(attributeToSort);
22 } catch (JSONException e) {
23 sortA ="";
24 }
25 String sortB;
26 try {
27 sortB = b.getString(attributeToSort);
28 } catch (JSONException e) {
29 sortB="";
30 }
31
32
33 return sortA.compareToIgnoreCase(sortB);
34 }
35
36
37
38 }