@Test public void testAddAsEqual() { final FixedOrderComparator<String> comparator = new FixedOrderComparator<String>(topCities); comparator.addAsEqual("New York", "Minneapolis"); assertEquals(0, comparator.compare("New York", "Minneapolis")); assertEquals(-1, comparator.compare("Tokyo", "Minneapolis")); assertEquals(1, comparator.compare("Shanghai", "Minneapolis")); }
public boolean addAsEqual(final T existingObj, final T newObj) { checkLocked(); final Integer position = map.get(existingObj); if (position == null) { throw new IllegalArgumentException(existingObj + " not known to " + this); } final Integer result = map.put(newObj, position); return result == null; }
FixedOrderComparator implements Comparator<T>, Serializable { public boolean addAsEqual(final T existingObj, final T newObj) { checkLocked(); final Integer position = map.get(existingObj); if (position == null) { throw new IllegalArgumentException(existingObj + " not known to " + this); } final Integer result = map.put(newObj, position); return result == null; } }
FixedOrderComparator implements Comparator<T>, Serializable { public boolean addAsEqual(final T existingObj, final T newObj) { checkLocked(); final Integer position = map.get(existingObj); if (position == null) { throw new IllegalArgumentException(existingObj + " not known to " + this); } final Integer result = map.put(newObj, position); return result == null; } FixedOrderComparator();  FixedOrderComparator(final T... items);  FixedOrderComparator(final List<T> items); }
FixedOrderComparator implements Comparator<T>, Serializable { public boolean addAsEqual(final T existingObj, final T newObj) { checkLocked(); final Integer position = map.get(existingObj); if (position == null) { throw new IllegalArgumentException(existingObj + " not known to " + this); } final Integer result = map.put(newObj, position); return result == null; } FixedOrderComparator();  FixedOrderComparator(final T... items);  FixedOrderComparator(final List<T> items); boolean isLocked(); UnknownObjectBehavior getUnknownObjectBehavior(); void setUnknownObjectBehavior(final UnknownObjectBehavior unknownObjectBehavior); boolean add(final T obj); boolean addAsEqual(final T existingObj, final T newObj); @Override int compare(final T obj1, final T obj2); @Override int hashCode(); @Override boolean equals(final Object object); }
FixedOrderComparator implements Comparator<T>, Serializable { public boolean addAsEqual(final T existingObj, final T newObj) { checkLocked(); final Integer position = map.get(existingObj); if (position == null) { throw new IllegalArgumentException(existingObj + " not known to " + this); } final Integer result = map.put(newObj, position); return result == null; } FixedOrderComparator();  FixedOrderComparator(final T... items);  FixedOrderComparator(final List<T> items); boolean isLocked(); UnknownObjectBehavior getUnknownObjectBehavior(); void setUnknownObjectBehavior(final UnknownObjectBehavior unknownObjectBehavior); boolean add(final T obj); boolean addAsEqual(final T existingObj, final T newObj); @Override int compare(final T obj1, final T obj2); @Override int hashCode(); @Override boolean equals(final Object object);  }