List of usage examples for java.util Comparator compare
int compare(T o1, T o2);
From source file:org.springframework.web.reactive.result.HandlerResultHandlerSupport.java
private MediaType selectMoreSpecificMediaType(MediaType acceptable, MediaType producible) { producible = producible.copyQualityValue(acceptable); Comparator<MediaType> comparator = MediaType.SPECIFICITY_COMPARATOR; return (comparator.compare(acceptable, producible) <= 0 ? acceptable : producible); }
From source file:org.openvpms.archetype.rules.finance.till.TillBalanceQuery.java
/** * Executes the query.// w ww . j a v a 2 s. c om * Returns an empty page if any of the schedule, from or to dates are null. * * @return the query results. * @throws ArchetypeServiceException if the query fails */ public IPage<ObjectSet> query() { List<ObjectSet> result = new ArrayList<ObjectSet>(); ActBean bean = new ActBean(tillBalance, service); for (Act tillBalanceItem : bean.getActs()) { ActBean tillBalanceItemBean = new ActBean(tillBalanceItem, service); if (tillBalanceItemBean.isA("act.tillBalanceAdjustment")) { ObjectSet set = new ObjectSet(); set.set(TILL_BALANCE, tillBalance); set.set(ACT, tillBalanceItem); set.set(ACT_ITEM, null); set.set(AMOUNT, getAmount(tillBalanceItem).negate()); result.add(set); } else { for (Act item : tillBalanceItemBean.getActs()) { ActBean itemBean = new ActBean(item); if (!itemBean.isA("act.customerAccountPayment")) { ObjectSet set = new ObjectSet(); set.set(TILL_BALANCE, tillBalance); set.set(ACT, tillBalanceItem); set.set(ACT_ITEM, item); set.set(AMOUNT, getAmount(item).negate()); result.add(set); } } } } // sort on act start time Collections.sort(result, new Comparator<ObjectSet>() { public int compare(ObjectSet o1, ObjectSet o2) { Act a1 = (Act) o1.get(ACT); Act a2 = (Act) o2.get(ACT); Comparator<Date> compator = new NullComparator(); return compator.compare(a1.getActivityStartTime(), a2.getActivityStartTime()); } }); return new Page<ObjectSet>(result, 0, result.size(), result.size()); }
From source file:org.apache.solr.hadoop.ZooKeeperInspector.java
public List<Slice> getSortedSlices(Collection<Slice> slices) { List<Slice> sorted = new ArrayList(slices); Collections.sort(sorted, (slice1, slice2) -> { Comparator c = new AlphaNumericComparator(); return c.compare(slice1.getName(), slice2.getName()); });/* w ww .java 2s . com*/ LOG.trace("Sorted slices: {}", sorted); return sorted; }
From source file:uk.bl.wa.apache.solr.hadoop.ZooKeeperInspector.java
public List<Slice> getSortedSlices(Collection<Slice> slices) { List<Slice> sorted = new ArrayList(slices); Collections.sort(sorted, new Comparator<Slice>() { @Override/*from w ww. j av a2 s. c o m*/ public int compare(Slice slice1, Slice slice2) { Comparator c = new AlphaNumericComparator(); return c.compare(slice1.getName(), slice2.getName()); } }); LOG.trace("Sorted slices: {}", sorted); return sorted; }
From source file:Main.java
/** * @param a//from ww w. j ava 2 s . c om * @param b * @return */ public static boolean containsSome(Collection a, Collection b) { // fast paths if (a.size() == 0 || b.size() == 0) return false; if (a == b) return true; // must test after size test. if (a instanceof SortedSet && b instanceof SortedSet) { SortedSet aa = (SortedSet) a; SortedSet bb = (SortedSet) b; Comparator bbc = bb.comparator(); Comparator aac = aa.comparator(); if (bbc == null && aac == null) { Iterator ai = aa.iterator(); Iterator bi = bb.iterator(); Comparable ao = (Comparable) ai.next(); // these are ok, since the sizes are != 0 Comparable bo = (Comparable) bi.next(); while (true) { int rel = ao.compareTo(bo); if (rel < 0) { if (!ai.hasNext()) return false; ao = (Comparable) ai.next(); } else if (rel > 0) { if (!bi.hasNext()) return false; bo = (Comparable) bi.next(); } else { return true; } } } else if (bbc.equals(a)) { Iterator ai = aa.iterator(); Iterator bi = bb.iterator(); Object ao = ai.next(); // these are ok, since the sizes are != 0 Object bo = bi.next(); while (true) { int rel = aac.compare(ao, bo); if (rel < 0) { if (!ai.hasNext()) return false; ao = ai.next(); } else if (rel > 0) { if (!bi.hasNext()) return false; bo = bi.next(); } else { return true; } } } } for (Iterator it = a.iterator(); it.hasNext();) { if (b.contains(it.next())) return true; } return false; }
From source file:org.springframework.ldap.core.LdapRdn.java
/** * Compare this LdapRdn to another object. * /*from w w w. ja v a 2s.c om*/ * @param obj the object to compare to. * @throws ClassCastException if the supplied object is not an LdapRdn * instance. */ public int compareTo(Object obj) { LdapRdn that = (LdapRdn) obj; Comparator comparator = new ListComparator(); return comparator.compare(this.components, that.components); }
From source file:de.thm.arsnova.services.SessionServiceTest.java
@Test public void testShouldCompareSessionByName() { final Session sessionA = new Session(); sessionA.setName("TestSessionA"); sessionA.setShortName("TSA"); final Session sessionB = new Session(); sessionB.setName("TestSessionB"); sessionB.setShortName("TSB"); final Comparator<Session> comp = new SessionService.SessionNameComparator(); assertTrue(comp.compare(sessionA, sessionB) < 0); }
From source file:de.thm.arsnova.services.SessionServiceTest.java
@Test public void testShouldCompareSessionByShortName() { final Session sessionA = new Session(); sessionA.setName("TestSessionA"); sessionA.setShortName("TSA"); final Session sessionB = new Session(); sessionB.setName("TestSessionB"); sessionB.setShortName("TSB"); final Comparator<Session> comp = new SessionService.SessionShortNameComparator(); assertTrue(comp.compare(sessionA, sessionB) < 0); }
From source file:com.bigdata.dastor.db.filter.SliceQueryFilter.java
public SuperColumn filterSuperColumn(SuperColumn superColumn, int gcBefore) { // we clone shallow, then add, under the theory that generally we're interested in a relatively small number of subcolumns. // this may be a poor assumption. SuperColumn scFiltered = superColumn.cloneMeShallow(); Iterator<IColumn> subcolumns; if (reversed) { List<IColumn> columnsAsList = new ArrayList<IColumn>(superColumn.getSubColumns()); subcolumns = new ReverseListIterator(columnsAsList); } else {// www . j ava 2 s . co m subcolumns = superColumn.getSubColumns().iterator(); } // iterate until we get to the "real" start column Comparator<byte[]> comparator = reversed ? superColumn.getComparator().getReverseComparator() : superColumn.getComparator(); while (subcolumns.hasNext()) { IColumn column = subcolumns.next(); if (comparator.compare(column.name(), start) >= 0) { subcolumns = IteratorUtils.chainedIterator(IteratorUtils.singletonIterator(column), subcolumns); break; } } // subcolumns is either empty now, or has been redefined in the loop above. either is ok. collectReducedColumns(scFiltered, subcolumns, gcBefore); return scFiltered; }
From source file:org.apache.cassandra.db.filter.SliceQueryFilter.java
public SuperColumn filterSuperColumn(SuperColumn superColumn, int gcBefore) { // we clone shallow, then add, under the theory that generally we're interested in a relatively small number of subcolumns. // this may be a poor assumption. SuperColumn scFiltered = superColumn.cloneMeShallow(); Iterator<IColumn> subcolumns; if (reversed) { List<IColumn> columnsAsList = new ArrayList<IColumn>(superColumn.getSubColumns()); subcolumns = new ReverseListIterator(columnsAsList); } else {/*w ww . ja v a 2 s. c o m*/ subcolumns = superColumn.getSubColumns().iterator(); } // iterate until we get to the "real" start column Comparator<ByteBuffer> comparator = reversed ? superColumn.getComparator().reverseComparator : superColumn.getComparator(); while (subcolumns.hasNext()) { IColumn column = subcolumns.next(); if (comparator.compare(column.name(), start) >= 0) { subcolumns = IteratorUtils.chainedIterator(IteratorUtils.singletonIterator(column), subcolumns); break; } } // subcolumns is either empty now, or has been redefined in the loop above. either is ok. collectReducedColumns(scFiltered, subcolumns, gcBefore); return scFiltered; }