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:io.druid.query.topn.TopNQueryQueryToolChest.java
@Override public QueryRunner<Result<TopNResultValue>> mergeResults(QueryRunner<Result<TopNResultValue>> runner) { return new ResultMergeQueryRunner<Result<TopNResultValue>>(runner) { @Override//from w ww.j av a 2s. co m protected Ordering<Result<TopNResultValue>> makeOrdering(Query<Result<TopNResultValue>> query) { return Ordering.from(new ResultGranularTimestampComparator<TopNResultValue>( ((TopNQuery) query).getGranularity())); } @Override protected BinaryFn<Result<TopNResultValue>, Result<TopNResultValue>, Result<TopNResultValue>> createMergeFn( Query<Result<TopNResultValue>> input) { TopNQuery query = (TopNQuery) input; return new TopNBinaryFn(TopNResultMerger.identity, query.getGranularity(), query.getDimensionSpec(), query.getTopNMetricSpec(), query.getThreshold(), query.getAggregatorSpecs(), query.getPostAggregatorSpecs()); } }; }
From source file:com.google.api.ads.adwords.keywordoptimizer.KeywordCollection.java
/** * Returns a list of all contained {@link KeywordInfo}s sorted by keywords (alphabetic order). *///from w w w .jav a 2s . c o m public List<KeywordInfo> getListSortedByKeyword() { return Ordering.from(new KeywordComparator()).sortedCopy(keywords.values()); }
From source file:de.cosmocode.collections.compare.Comparators.java
/** * Makes a comparator trimming his stirng comparees before * actually comparing them.// ww w. j a v a 2 s . c o m * * @deprecated use {@link Ordering#onResultOf(com.google.common.base.Function)} instead * @param comparator the comparator to rely on * @param trimMode the {@link TrimMode} to use for trim operations * @return a trimming version of the given comparator * @throws NullPointerException if comparator is null */ @Deprecated public static Ordering<String> trimming(Comparator<String> comparator, TrimMode trimMode) { LOG.debug("Making {} trimming using {}", comparator, trimMode); return Ordering.from(comparator).onResultOf(trimMode); }
From source file:com.yahoo.elide.jsonapi.document.processors.SortProcessor.java
/** * Attribute comparator.// ww w .j a va2 s. co m * * @param field - name of attribute field to compare * @return a comparison between resources for the given attribute field */ private Comparator<Resource> attributeComparison(String field) { return (a, b) -> // Compare requested attribute using an object comparison Ordering.from(this::compareObjects).nullsFirst().compare(a.getAttributes().get(field), b.getAttributes().get(field)); }
From source file:org.codice.ddf.ui.searchui.query.controller.search.SourceQueryRunnable.java
private void sort(List<Result> responseResults) { List<Result> sortedResults = Ordering.from(sortComparator).immutableSortedCopy(results.values()); responseResults.clear();/*from w w w .j a v a 2 s.c o m*/ responseResults .addAll(sortedResults.size() > maxResults ? sortedResults.subList(0, maxResults) : sortedResults); }
From source file:net.pterodactylus.sone.web.KnownSonesPage.java
/** * {@inheritDoc}//www. j av a2 s. co m */ @Override protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String sortField = request.getHttpRequest().getParam("sort"); String sortOrder = request.getHttpRequest().getParam("order"); String filter = request.getHttpRequest().getParam("filter"); templateContext.set("sort", (sortField != null) ? sortField : "name"); templateContext.set("order", (sortOrder != null) ? sortOrder : "asc"); templateContext.set("filter", filter); final Sone currentSone = getCurrentSone(request.getToadletContext(), false); Collection<Sone> knownSones = Collections2.filter(webInterface.getCore().getSones(), Sone.EMPTY_SONE_FILTER); if ((currentSone != null) && "followed".equals(filter)) { knownSones = Collections2.filter(knownSones, new Predicate<Sone>() { @Override public boolean apply(Sone sone) { return currentSone.hasFriend(sone.getId()); } }); } else if ((currentSone != null) && "not-followed".equals(filter)) { knownSones = Collections2.filter(knownSones, new Predicate<Sone>() { @Override public boolean apply(Sone sone) { return !currentSone.hasFriend(sone.getId()); } }); } else if ("new".equals(filter)) { knownSones = Collections2.filter(knownSones, new Predicate<Sone>() { /** * {@inheritDoc} */ @Override public boolean apply(Sone sone) { return !sone.isKnown(); } }); } else if ("not-new".equals(filter)) { knownSones = Collections2.filter(knownSones, new Predicate<Sone>() { /** * {@inheritDoc} */ @Override public boolean apply(Sone sone) { return sone.isKnown(); } }); } else if ("own".equals(filter)) { knownSones = Collections2.filter(knownSones, Sone.LOCAL_SONE_FILTER); } else if ("not-own".equals(filter)) { knownSones = Collections2.filter(knownSones, Predicates.not(Sone.LOCAL_SONE_FILTER)); } List<Sone> sortedSones = new ArrayList<Sone>(knownSones); if ("activity".equals(sortField)) { if ("asc".equals(sortOrder)) { Collections.sort(sortedSones, Ordering.from(Sone.LAST_ACTIVITY_COMPARATOR).reverse()); } else { Collections.sort(sortedSones, Sone.LAST_ACTIVITY_COMPARATOR); } } else if ("posts".equals(sortField)) { if ("asc".equals(sortOrder)) { Collections.sort(sortedSones, Ordering.from(Sone.POST_COUNT_COMPARATOR).reverse()); } else { Collections.sort(sortedSones, Sone.POST_COUNT_COMPARATOR); } } else if ("images".equals(sortField)) { if ("asc".equals(sortOrder)) { Collections.sort(sortedSones, Ordering.from(Sone.IMAGE_COUNT_COMPARATOR).reverse()); } else { Collections.sort(sortedSones, Sone.IMAGE_COUNT_COMPARATOR); } } else { if ("desc".equals(sortOrder)) { Collections.sort(sortedSones, Ordering.from(Sone.NICE_NAME_COMPARATOR).reverse()); } else { Collections.sort(sortedSones, Sone.NICE_NAME_COMPARATOR); } } Pagination<Sone> sonePagination = new Pagination<Sone>(sortedSones, 25) .setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", sonePagination); templateContext.set("knownSones", sonePagination.getItems()); }
From source file:com.netxforge.netxstudio.server.logic.retention.RetentionEngine.java
public void initialize(boolean re_initialize) { if (LogicActivator.DEBUG) { LogicActivator.TRACE.trace(LogicActivator.TRACE_RETENTION_OPTION, "Initializing Retention engine"); }/*from w w w . j av a 2 s . co m*/ Resource resource = this.getDataProvider().getResource(MetricsPackage.Literals.METRIC_SOURCE); metricSources = new NonModelUtils.CollectionForObjects<MetricSource>() .collectionForObjects(resource.getContents()); // Rules should execute considering the order of the smallest // interval first, // as to allow aggregation. // Order the rules by smallest interval. if (metricRulesSortedList == null) { metricRulesSortedList = Ordering.from(StudioUtils.retentionRuleCompare()) .sortedCopy(rules.getMetricRetentionRules()); if (LogicActivator.DEBUG) { LogicActivator.TRACE.trace(LogicActivator.TRACE_RETENTION_OPTION, "Processing aggreagation rule in order: "); for (MetricRetentionRule rule : metricRulesSortedList) { StringBuilder sb = new StringBuilder(); sb.append(rule.getName()); sb.append(" interval:" + rule.getIntervalHint()); sb.append(" rule: " + rule.getPeriod()); // sb.append(rule.getRetentionExpression() + " "); LogicActivator.TRACE.trace(LogicActivator.TRACE_RETENTION_OPTION, sb.toString()); } } } addonHandler.initializeModelAddon(re_initialize); }
From source file:com.google.gerrit.server.schema.Schema_124.java
private Collection<AccountSshKey> fixInvalidSequenceNumbers(Collection<AccountSshKey> keys) { Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get())); List<AccountSshKey> fixedKeys = new ArrayList<>(keys); AccountSshKey minKey = o.min(keys);/*www. j a va 2s .c om*/ while (minKey.getKey().get() <= 0) { AccountSshKey fixedKey = new AccountSshKey(new AccountSshKey.Id(minKey.getKey().getParentKey(), Math.max(o.max(keys).getKey().get() + 1, 1)), minKey.getSshPublicKey()); Collections.replaceAll(fixedKeys, minKey, fixedKey); minKey = o.min(fixedKeys); } return fixedKeys; }
From source file:com.google.api.ads.adwords.keywordoptimizer.KeywordCollection.java
/** * Returns the best x {@link KeywordInfo}s in this collection. * //from w w w .ja va 2 s . c o m * @param count the number of {@link KeywordInfo}s to return (=x) */ public KeywordCollection getBest(int count) { List<KeywordInfo> bestKeywordList = Ordering.from(new ScoreComparator()).greatestOf(keywords.values(), count); KeywordCollection bestKeywords = new KeywordCollection(campaignConfiguration); bestKeywords.addAll(bestKeywordList); return bestKeywords; }
From source file:com.ning.billing.invoice.dao.CBADao.java
private void useExistingCBAFromTransaction(final List<InvoiceModelDao> invoices, final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory, final InternalCallContext context) throws InvoiceApiException, EntityPersistenceException { final BigDecimal accountCBA = getAccountCBAFromTransaction(invoices); if (accountCBA.compareTo(BigDecimal.ZERO) <= 0) { return;/*from w w w . ja v a 2s . c o m*/ } final List<InvoiceModelDao> unpaidInvoices = invoiceDaoHelper .getUnpaidInvoicesByAccountFromTransaction(invoices, null); // We order the same os BillingStateCalculator-- should really share the comparator final List<InvoiceModelDao> orderedUnpaidInvoices = Ordering.from(new Comparator<InvoiceModelDao>() { @Override public int compare(final InvoiceModelDao i1, final InvoiceModelDao i2) { return i1.getInvoiceDate().compareTo(i2.getInvoiceDate()); } }).immutableSortedCopy(unpaidInvoices); BigDecimal remainingAccountCBA = accountCBA; for (InvoiceModelDao cur : orderedUnpaidInvoices) { final BigDecimal curInvoiceBalance = InvoiceModelDaoHelper.getBalance(cur); final BigDecimal cbaToApplyOnInvoice = remainingAccountCBA.compareTo(curInvoiceBalance) <= 0 ? remainingAccountCBA : curInvoiceBalance; remainingAccountCBA = remainingAccountCBA.subtract(cbaToApplyOnInvoice); final InvoiceItemModelDao cbaAdjItem = new InvoiceItemModelDao(new CreditBalanceAdjInvoiceItem( cur.getId(), cur.getAccountId(), context.getCreatedDate().toLocalDate(), cbaToApplyOnInvoice.negate(), cur.getCurrency())); final InvoiceItemSqlDao transInvoiceItemDao = entitySqlDaoWrapperFactory .become(InvoiceItemSqlDao.class); transInvoiceItemDao.create(cbaAdjItem, context); if (remainingAccountCBA.compareTo(BigDecimal.ZERO) <= 0) { break; } } }