List of usage examples for com.google.common.collect Ordering from
@GwtCompatible(serializable = true) @Deprecated public static <T> Ordering<T> from(Ordering<T> ordering)
From source file:org.apache.druid.query.ResultGranularTimestampComparator.java
public static <T> Ordering<Result<T>> create(Granularity granularity, boolean descending) { Comparator<Result<T>> comparator = new ResultGranularTimestampComparator<>(granularity); return descending ? Ordering.from(comparator).reverse() : Ordering.from(comparator); }
From source file:org.lenskit.data.history.History.java
/** * Create a history for a particular user. * @param id The user ID.// www . ja va 2s. c o m * @param events The events. * @param <E> The root type of the events in the history. * @return A history object. */ @SuppressWarnings("deprecation") @Nonnull public static <E extends Event> UserHistory<E> forUser(long id, List<? extends E> events) { Ordering<Event> ord = Ordering.from(Events.TIMESTAMP_COMPARATOR); if (ord.isOrdered(events)) { return new BasicUserHistory<>(id, events); } else { return new BasicUserHistory<>(id, ord.immutableSortedCopy(events)); } }
From source file:org.grouplens.lenskit.data.history.History.java
/** * Create a history for a particular user. * @param id The user ID./*from www. j a v a2s .c o m*/ * @param events The events. * @param <E> The root type of the events in the history. * @return A history object. */ @SuppressWarnings("deprecation") @Nonnull public static <E extends Event> UserHistory<E> forUser(long id, List<? extends E> events) { Ordering<Event> ord = Ordering.from(Events.TIMESTAMP_COMPARATOR); if (ord.isOrdered(events)) { return new BasicUserHistory<E>(id, events); } else { return new BasicUserHistory<E>(id, ord.immutableSortedCopy(events)); } }
From source file:hu.bme.mit.trainbenchmark.benchmark.benchmarkcases.transformations.RepairTransformationLogic.java
@Override protected List<M> copyAndSort() { final Ordering<M> ordering = Ordering.from(comparator); final List<M> sortedMatches = ordering.sortedCopy(candidatesToModify); return sortedMatches; }
From source file:org.killbill.billing.plugin.analytics.utils.PaymentUtils.java
public static PaymentTransaction findLastPaymentTransaction(final Iterable<Payment> payments, final TransactionType... transactionTypes) { final Iterable<PaymentTransaction> paymentTransactions = findPaymentTransactions(payments, transactionTypes);//from w w w . j ava2 s. c o m if (!paymentTransactions.iterator().hasNext()) { return null; } return Ordering.from(PAYMENT_TRANSACTION_COMPARATOR).immutableSortedCopy(paymentTransactions).reverse() .get(0); }
From source file:org.haiku.haikudepotserver.support.VersionCoordinatesComparator.java
@Override public int compare(VersionCoordinates o1, VersionCoordinates o2) { ComparisonChain chain = ComparisonChain.start() .compare(o1.getMajor(), o2.getMajor(), naturalStringComparator) .compare(o1.getMinor(), o2.getMinor(), naturalStringComparator) .compare(o1.getMicro(), o2.getMicro(), naturalStringComparator); if (!ignorePrereleaseAndRevision) { chain = chain//w ww . j av a 2 s .c o m .compare(o1.getPreRelease(), o2.getPreRelease(), Ordering.from(naturalStringComparator).nullsLast()) .compare(o1.getRevision(), o2.getRevision(), Ordering.natural().nullsLast()); } return chain.result(); }
From source file:org.apache.cassandra.db.commitlog.ReplayPosition.java
/** * Convenience method to compute the replay position for a group of SSTables. * @param sstables//from www. j a v a 2 s. c o m * @return the most recent (highest) replay position */ public static ReplayPosition getReplayPosition(Iterable<? extends SSTable> sstables) { if (Iterables.isEmpty(sstables)) return NONE; Function<SSTable, ReplayPosition> f = new Function<SSTable, ReplayPosition>() { public ReplayPosition apply(SSTable sstable) { return sstable.replayPosition; } }; Ordering<ReplayPosition> ordering = Ordering.from(ReplayPosition.comparator); return ordering.max(Iterables.transform(sstables, f)); }
From source file:org.eclipse.xtext.ide.util.PositionComparator.java
@Override public int compare(final Position left, final Position right) { return Ordering.from(delegate).nullsLast().compare(left, right); }
From source file:dynamite.zafroshops.app.adapter.AllZopsGridViewAdapter.java
public AllZopsGridViewAdapter(Context context, int resource, ArrayList<MobileZop> objects) { super(context, resource, objects); this.objects = objects; ordering = Ordering.from(new Comparator<MobileZop>() { @Override/* ww w . j ava 2 s . c om*/ public int compare(MobileZop zop, MobileZop z1) { if (zop.Type.getText().compareTo(ZopType.Shop.getText()) == 0) { return -1; } else if (z1.Type.getText().compareTo(ZopType.Shop.getText()) == 0) { return 1; } else { return zop.Type.getText().compareTo(z1.Type.getText()); } } }); Collections.sort(objects, ordering); }
From source file:dynamite.zafroshops.app.adapter.ZopServiceAdapter.java
public ZopServiceAdapter(Context context, int resource, ArrayList<ZopServiceType> selection) { super(context, resource); this.objects = ZopServiceType.values(); final Ordering<ZopServiceType> ordering = Ordering.from(new Comparator<ZopServiceType>() { @Override/*w ww .j a va 2 s . c o m*/ public int compare(ZopServiceType zopServiceType, ZopServiceType t1) { if (zopServiceType.getText().compareTo(ZopServiceType.Shop.getText()) == 0) { return -1; } else if (t1.getText().compareTo(ZopServiceType.Shop.getText()) == 0) { return 1; } else { return zopServiceType.getText().compareTo(t1.getText()); } } }); Arrays.sort(objects, ordering); this.selection = selection; }