java.lang.Object | +--org.apache.commons.collections.comparators.FixedOrderComparatorAll Implemented Interfaces:
static int | Behavior when comparing unknown Objects: unknown objects compare as after known Objects. |
static int | Behavior when comparing unknown Objects: unknown objects compare as before known Objects. |
static int | Behavior when comparing unknown Objects: unknown objects cause a IllegalArgumentException to be thrown. |
Constructs an empty FixedOrderComparator. |
FixedOrderComparator(Object[] items) Constructs a FixedOrderComparator which uses the order of the given array to compare the objects. |
FixedOrderComparator(List items) Constructs a FixedOrderComparator which uses the order of the given list to compare the objects. |
boolean | add(Object obj) Adds an item, which compares as after all items known to the Comparator. |
boolean | addAsEqual(Object existingObj, Object newObj) Adds a new item, which compares as equal to the given existing item. |
void | Checks to see whether the comparator is now locked against further changes. |
int | compare(Object obj1, Object obj2) Compares two objects according to the order of this Comparator. |
int | Gets the behavior for comparing unknown objects. |
boolean | isLocked() Returns true if modifications cannot be made to the FixedOrderComparator. |
void | setUnknownObjectBehavior(int unknownObjectBehavior) Sets the behavior for comparing unknown objects. |
public static final int UNKNOWN_AFTER
public static final int UNKNOWN_BEFORE
public static final int UNKNOWN_THROW_EXCEPTION
public FixedOrderComparator()
public FixedOrderComparator(List items)
- if the list is nullpublic FixedOrderComparator(Object[] items)
- if the array is nullpublic boolean add(Object obj)
- if a comparison has already been madepublic boolean addAsEqual(Object existingObj, Object newObj)
- if existingObject is not in the
Comparator's set of known objects. - if a comparison has already been madeprotected void checkLocked()
- if the comparator is lockedpublic int compare(Object obj1, Object obj2)
- if o1 or o2 are not known
to this Comparator and an alternative behavior has not been set
via #setUnknownObjectBehavior(int).public int getUnknownObjectBehavior()
public boolean isLocked()
public void setUnknownObjectBehavior(int unknownObjectBehavior)
- if a comparison has been performed - if the unknown flag is not valid
String[] planets = {"Mercury", "Venus", "Earth", "Mars"}; FixedOrderComparator distanceFromSun = new FixedOrderComparator(planets); Arrays.sort(planets); // Sort to alphabetical order Arrays.sort(planets, distanceFromSun); // Back to original orderOnce compare has been called, the FixedOrderComparator is locked and attempts to modify it yield an UnsupportedOperationException. Instances of FixedOrderComparator are not synchronized. The class is not thread-safe at construction time, but it is thread-safe to perform multiple comparisons after all the setup operations are complete.