List of usage examples for com.google.common.collect Ordering max
public <E extends T> E max(@Nullable E a, @Nullable E b)
From source file:com.palantir.common.base.BatchingVisitables.java
/** * This will return the first maximal element in the visitable. This method * takes a default element and will return that if the visitable is empty. * If the visitable is non-empty it will return the largest value in the * visitable./*from ww w. j a v a 2s.com*/ * <p> * A common way to use this would be to pass <code>null</code> as the * defaultElement and have the ordering throw on null elements so you know * the visitable doesn't have any nulls. */ public static <T> T getMax(BatchingVisitable<T> v, final Ordering<? super T> o, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); v.batchAccept(DEFAULT_BATCH_SIZE, AbortingVisitors.batching(new AbortingVisitor<T, RuntimeException>() { boolean hasSeenFirst = false; @Override public boolean visit(T item) throws RuntimeException { if (hasSeenFirst) { ret.set(o.max(ret.get(), item)); } else { // Call o.max here so it will throw if item is null and this // ordering hates on nulls. ret.set(o.max(item, item)); hasSeenFirst = true; } return true; } })); return ret.get(); }
From source file:com.google.gerrit.server.notedb.ChangeBundle.java
private Timestamp getLatestTimestamp() { Ordering<Timestamp> o = Ordering.natural().nullsFirst(); Timestamp ts = null;/*from w w w . ja v a2 s . com*/ for (ChangeMessage cm : filterChangeMessages()) { ts = o.max(ts, cm.getWrittenOn()); } for (PatchSet ps : getPatchSets()) { ts = o.max(ts, ps.getCreatedOn()); } for (PatchSetApproval psa : filterPatchSetApprovals().values()) { ts = o.max(ts, psa.getGranted()); } for (PatchLineComment plc : filterPatchLineComments().values()) { // Ignore draft comments, as they do not show up in the change meta graph. if (plc.getStatus() != PatchLineComment.Status.DRAFT) { ts = o.max(ts, plc.getWrittenOn()); } } return firstNonNull(ts, change.getLastUpdatedOn()); }