List of usage examples for com.google.common.collect Ordering binarySearch
public int binarySearch(List<? extends T> sortedList, @Nullable T key)
From source file:com.bigfatgun.fixjures.dao.DAOHelper.java
public final int findIndexOfObjectInOrder(final T object, final Ordering<? super T> ordering) { return ordering.binarySearch(findAllOrdered(ordering), object); }
From source file:com.b2international.snowowl.snomed.reasoner.server.diff.OntologyChangeProcessor.java
public void apply(final long conceptId, final Collection<T> oldCollection, final Collection<T> newCollection, final Ordering<T> ordering, final IProgressMonitor monitor) { final int unitsOfWork = oldCollection.size() + newCollection.size(); final SubMonitor subMonitor = SubMonitor.convert(monitor, "Processing changes...", unitsOfWork); final TreeSet<T> uniqueOlds = Sets.newTreeSet(ordering); final ImmutableList<T> sortedOld = ordering.immutableSortedCopy(oldCollection); final ImmutableList<T> sortedNew = ordering.immutableSortedCopy(newCollection); for (final T oldSubject : sortedOld) { if (subMonitor.isCanceled()) { throw new OperationCanceledException(); }/*from w w w . jav a 2s .c o m*/ final int idx = ordering.binarySearch(sortedNew, oldSubject); if (idx < 0 || !uniqueOlds.add(oldSubject)) { handleRemovedSubject(String.valueOf(conceptId), oldSubject); } subMonitor.worked(1); } for (final T newSubject : sortedNew) { if (subMonitor.isCanceled()) { throw new OperationCanceledException(); } if (ordering.binarySearch(sortedOld, newSubject) < 0) { handleAddedSubject(String.valueOf(conceptId), newSubject); } subMonitor.worked(1); } }