Package com.groiss.ds
Class JsonComparator
java.lang.Object
com.groiss.ds.JsonComparator
- All Implemented Interfaces:
Comparator<JSONObject>
Compares json objects according to the passed attributes. If the attribute name starts with '-' this indicates descending
order. If not or if it starts with a blank this indicates ascending order.
Comparison is done as follows:
- if attribute holds Strings
StringUtil.getCollator()
will be used - if attribute holds Comparable its compare-method will be used
- for all other cases the toString() result will be compared - again with
StringUtil.getCollator()
-
Constructor Summary
ConstructorDescriptionJsonComparator
(String attributes) Creates a new comparator object to sort according to the passed attributesJsonComparator
(String[] attributes) Creates a new comparator object to sort according to the passed attributes -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
JsonComparator
Creates a new comparator object to sort according to the passed attributes- Parameters:
attributes
- the name of the attributes by which sorting should be performed, e.g. "firstAttr,-secondAttr" means first sort ascending by 'firstAttr' and then (if necessary) sort descending by 'secondAttr'
-
JsonComparator
Creates a new comparator object to sort according to the passed attributes- Parameters:
attributes
- the name of the attributes by which sorting should be performed, e.g. ["firstAttr","-secondAttr"] means first sort ascending by 'firstAttr' and then (if necessary) sort descending by 'secondAttr'
-
-
Method Details
-
compare
- Specified by:
compare
in interfaceComparator<JSONObject>
-