當前位置: 首頁>>代碼示例>>Java>>正文


Java Ordering類代碼示例

本文整理匯總了Java中com.google.common.collect.Ordering的典型用法代碼示例。如果您正苦於以下問題:Java Ordering類的具體用法?Java Ordering怎麽用?Java Ordering使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Ordering類屬於com.google.common.collect包,在下文中一共展示了Ordering類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRevisions

import com.google.common.collect.Ordering; //導入依賴的package包/類
public List<Revision> getRevisions(String id, Params params) {

        AuditReader reader = getAuditReader();

        List<Number> revisionNumbers = reader.getRevisions(type, id);
        Map<Number, Revision> revisionMap = reader.findRevisions(Revision.class, asSet(revisionNumbers));
        Collection<Revision> revisions = revisionMap.values();

        Comparator<Revision> timestampComparator = Comparator.comparingLong(Revision::getTimestamp);
        Comparator<Revision> authorComparator = Comparator.comparing(Revision::getAuthor);

        Comparator<Revision> comparator;
        if (AUTHOR.equals(params.getSort())) {
            comparator = authorComparator;
        } else {
            comparator = timestampComparator;
        }

        if (params.getOrder() == Order.DESC) {
            comparator = comparator.reversed();
        }

        return Ordering.from(comparator)
                       .sortedCopy(revisions);
    }
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:26,代碼來源:HistoricStore.java

示例2: identifyDuplicates

import com.google.common.collect.Ordering; //導入依賴的package包/類
private void identifyDuplicates(List<ModContainer> mods)
{
    TreeMultimap<ModContainer, File> dupsearch = TreeMultimap.create(new ModIdComparator(), Ordering.arbitrary());
    for (ModContainer mc : mods)
    {
        if (mc.getSource() != null)
        {
            dupsearch.put(mc, mc.getSource());
        }
    }

    ImmutableMultiset<ModContainer> duplist = Multisets.copyHighestCountFirst(dupsearch.keys());
    SetMultimap<ModContainer, File> dupes = LinkedHashMultimap.create();
    for (Entry<ModContainer> e : duplist.entrySet())
    {
        if (e.getCount() > 1)
        {
            FMLLog.severe("Found a duplicate mod %s at %s", e.getElement().getModId(), dupsearch.get(e.getElement()));
            dupes.putAll(e.getElement(),dupsearch.get(e.getElement()));
        }
    }
    if (!dupes.isEmpty())
    {
        throw new DuplicateModsFoundException(dupes);
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:27,代碼來源:Loader.java

示例3: testSelfDataOrdered

import com.google.common.collect.Ordering; //導入依賴的package包/類
/**
 * 測試 TreeMultimap,自定義數據結構的排序
 */
@Test
public void testSelfDataOrdered() {
    // 創建TreeMultimap,使用Ordering.natural()指定自然排序,Ordering.from指定排序規則
    // Order4TreeMultimap::compareTo 是lambda的簡寫形式
    TreeMultimap<String, Order4TreeMultimap> treeMultimap = TreeMultimap
            .create(Ordering.natural(),
                    Ordering.from(Order4TreeMultimap::compareTo));

    // 列表2
    treeMultimap.put("order_list1", new Order4TreeMultimap(1, "haha1"));
    treeMultimap.put("order_list1", new Order4TreeMultimap(5, "haha2"));
    treeMultimap.put("order_list1", new Order4TreeMultimap(9, "haha3"));
    treeMultimap.put("order_list1", new Order4TreeMultimap(10, "haha3"));
    treeMultimap.put("order_list1", new Order4TreeMultimap(22, "haha4"));
    treeMultimap.put("order_list1", new Order4TreeMultimap(444, "haha5"));

    // 列表2
    treeMultimap.put("order_list2", new Order4TreeMultimap(1, "haha3"));
    treeMultimap.put("order_list2", new Order4TreeMultimap(3, "haha4"));
    treeMultimap.put("order_list3", new Order4TreeMultimap(2, "haha5"));

    // 輸出
    treeMultimap.forEach((key, order) -> System.out.println("key=" + key + ",order=" + order));
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:28,代碼來源:TreeMultimapDemo.java

示例4: setPoints

import com.google.common.collect.Ordering; //導入依賴的package包/類
/**
 * Sets the points a {@link PlayerFaction} has gained for this {@link ConquestTracker}.
 *
 * @param faction the faction to set for
 * @param amount  the amount to set
 * @return the new points of the {@link PlayerFaction}
 */
public int setPoints(PlayerFaction faction, int amount) {
    if (amount <= 0) return amount;

    synchronized (factionPointsMap) {
        factionPointsMap.put(faction, amount);
        List<Map.Entry<PlayerFaction, Integer>> entries = Ordering.from(POINTS_COMPARATOR).sortedCopy(factionPointsMap.entrySet());

        factionPointsMap.clear();
        for (Map.Entry<PlayerFaction, Integer> entry : entries) {
            factionPointsMap.put(entry.getKey(), entry.getValue());
        }
    }

    return amount;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:23,代碼來源:ConquestTracker.java

示例5: getItemsComparator

import com.google.common.collect.Ordering; //導入依賴的package包/類
@Override
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
protected Comparator getItemsComparator() {
	return Ordering.natural().nullsLast().from(new Comparator() {

		@Override
		public int compare(final Object o1, final Object o2) {
			if (o1 instanceof IEObjectDescription && o2 instanceof IEObjectDescription) {
				final IEObjectDescription d1 = (IEObjectDescription) o1;
				final IEObjectDescription d2 = (IEObjectDescription) o2;
				final QualifiedName fqn1 = d1.getQualifiedName();
				final QualifiedName fqn2 = d2.getQualifiedName();
				if (null != fqn1 && null != fqn2) {
					return nullToEmpty(fqn1.getLastSegment()).compareToIgnoreCase(
							nullToEmpty(fqn2.getLastSegment()));
				}
			}
			return Objects.hashCode(o1) - Objects.hashCode(o2);
		}
	});
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:22,代碼來源:OpenTypeSelectionDialog.java

示例6: OrderingByPosition

import com.google.common.collect.Ordering; //導入依賴的package包/類
private OrderingByPosition (int position, boolean reverse, @Nullable Boolean nullFirst) {
    this.position = position;

    // note, that we are reverse for the queue so this conditional is by intent
    Ordering<Comparable> ordering;
    nullFirst = nullFirst != null ? !nullFirst : null; // swap because queue is reverse
    if (reverse) {
        ordering = Ordering.natural();
        if (nullFirst == null || !nullFirst) {
            ordering = ordering.nullsLast();
        } else {
            ordering = ordering.nullsFirst();
        }
    } else {
        ordering = Ordering.natural().reverse();
        if (nullFirst == null || nullFirst) {
            ordering = ordering.nullsFirst();
        } else {
            ordering = ordering.nullsLast();
        }
    }
    this.ordering = ordering;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:24,代碼來源:OrderingByPosition.java

示例7: hasNoOtherValues

import com.google.common.collect.Ordering; //導入依賴的package包/類
/**
 * Asserts that the metric has no (non-default) values other than those about which an assertion
 * has already been made.
 */
public And<S> hasNoOtherValues() {
  for (MetricPoint<T> metricPoint : actual().getTimestampedValues()) {
    if (!expectedNondefaultLabelTuples.contains(metricPoint.labelValues())) {
      if (!hasDefaultValue(metricPoint)) {
        failWithBadResults(
            "has",
            "no other nondefault values",
            "has labeled values",
            Lists.transform(
                Ordering.<MetricPoint<T>>natural().sortedCopy(actual().getTimestampedValues()),
                metricPointConverter));
      }
      return andChainer();
    }
  }
  return andChainer();
}
 
開發者ID:google,項目名稱:java-monitoring-client-library,代碼行數:22,代碼來源:AbstractMetricSubject.java

示例8: topKProbabilities

import com.google.common.collect.Ordering; //導入依賴的package包/類
private List<Integer> topKProbabilities(final float[] labelProbabilities, int k) {

		List<Integer> list = new ArrayList<>(labelProbabilities.length);
		for (int i = 0; i < labelProbabilities.length; i++) {
			list.add(i);
		}

		List<Integer> topK = new Ordering<Integer>() {
			@Override
			public int compare(Integer left, Integer right) {
				return Floats.compare(labelProbabilities[left], labelProbabilities[right]);
			}
		}.greatestOf(list, k);

		return topK;
	}
 
開發者ID:tzolov,項目名稱:tensorflow-spring-cloud-stream-app-starters,代碼行數:17,代碼來源:LabelImageTensorflowOutputConverter.java

示例9: pickSuggestions

import com.google.common.collect.Ordering; //導入依賴的package包/類
private List<SuggestItem> pickSuggestions(String searchWord, int editDistanceMax, List<SuggestItem> suggestions) {
	int k = suggestions.size();
	if ((accuracyLevel == AccuracyLevel.topHit) && (suggestions.size() > 1))
		k = 1;
	else if (suggestions.size() > topK) {
		k = topK;
	}

	List<SuggestItem> returnSuggestions;
	if (k >= suggestions.size()) {
		returnSuggestions = suggestions;
	} else {
		returnSuggestions = Ordering.from(distanceCountComparator).leastOf(suggestions, k);
	}
	
	return customizing.adjustFinalResult(searchWord, returnSuggestions);
}
 
開發者ID:searchhub,項目名稱:preDict,代碼行數:18,代碼來源:PreDict.java

示例10: withNeutralizedJustifications

import com.google.common.collect.Ordering; //導入依賴的package包/類
public final CorpusQueryAssessments withNeutralizedJustifications() {
  return CorpusQueryAssessments.builder()
      .queryReponses(Iterables.transform(queryReponses(), neutralizeRealisFunction()))
      .queryResponsesToSystemIDs(
          copyWithTransformedKeys(queryResponsesToSystemIDs(), neutralizeRealisFunction()))
      .assessments(
          reduceToMap(
              transformKeys(assessments(), neutralizeRealisFunction()),
              // if multiple assessments on the same doc are collapsed together,
              // the ones higher in rank "trump" others
              maxFunction(Ordering.<QueryAssessment2016>natural())))
      // we arbitrarily take the first metadata, which is a bit of a hack
      .metadata(reduceToMap(transformKeys(metadata(), neutralizeRealisFunction()),
          _CorpusQueryAssessments.<String>getFirstFunction()))
      .build();
}
 
開發者ID:isi-nlp,項目名稱:tac-kbp-eal,代碼行數:17,代碼來源:_CorpusQueryAssessments.java

示例11: SortingTopNProjector

import com.google.common.collect.Ordering; //導入依賴的package包/類
/**
 * @param inputs             contains output {@link io.crate.operation.Input}s and orderBy {@link io.crate.operation.Input}s
 * @param collectExpressions gathered from outputs and orderBy inputs
 * @param numOutputs         <code>inputs</code> contains this much output {@link io.crate.operation.Input}s starting form index 0
 * @param ordering           ordering that is used to compare the rows
 * @param limit              the number of rows to gather, pass to upStream
 * @param offset             the initial offset, this number of rows are skipped
 */
public SortingTopNProjector(Collection<? extends Input<?>> inputs,
                            Iterable<? extends CollectExpression<Row, ?>> collectExpressions,
                            int numOutputs,
                            Ordering<Object[]> ordering,
                            int limit,
                            int offset) {
    Preconditions.checkArgument(limit >= TopN.NO_LIMIT, "invalid limit");
    Preconditions.checkArgument(offset >= 0, "invalid offset");

    this.inputs = inputs;
    this.numOutputs = numOutputs;
    this.collectExpressions = collectExpressions;
    this.offset = offset;

    if (limit == TopN.NO_LIMIT) {
        limit = Constants.DEFAULT_SELECT_LIMIT;
    }
    int maxSize = this.offset + limit;
    pq = new RowPriorityQueue<>(maxSize, ordering);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:29,代碼來源:SortingTopNProjector.java

示例12: customComparable

import com.google.common.collect.Ordering; //導入依賴的package包/類
@Test
public void customComparable() {
  MutableGraph<ComparableSubClass> graph =
      GraphBuilder.undirected().nodeOrder(ElementOrder.<ComparableSubClass>natural()).build();

  ComparableSubClass node2 = new ComparableSubClass(2);
  ComparableSubClass node4 = new ComparableSubClass(4);
  ComparableSubClass node6 = new ComparableSubClass(6);
  ComparableSubClass node8 = new ComparableSubClass(8);

  graph.addNode(node4);
  graph.addNode(node2);
  graph.addNode(node6);
  graph.addNode(node8);

  assertThat(graph.nodeOrder().comparator()).isEqualTo(Ordering.natural());
  assertThat(graph.nodes()).containsExactly(node2, node4, node6, node8).inOrder();
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:19,代碼來源:ElementOrderTest.java

示例13: getValueCapacity

import com.google.common.collect.Ordering; //導入依賴的package包/類
@Override
public int getValueCapacity() {
  if (size() == 0) {
    return 0;
  }

  final Ordering<ValueVector> natural = new Ordering<ValueVector>() {
    @Override
    public int compare(@Nullable ValueVector left, @Nullable ValueVector right) {
      return Ints.compare(
          Preconditions.checkNotNull(left).getValueCapacity(),
          Preconditions.checkNotNull(right).getValueCapacity()
      );
    }
  };

  return natural.min(getChildren()).getValueCapacity();
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:19,代碼來源:MapVector.java

示例14: computeBreakdowns

import com.google.common.collect.Ordering; //導入依賴的package包/類
/**
 * @return A mapping from each breakdown type to inner maps. These inner maps map from the
 * categories for that breakdown type to confusion matrices for only that category.
 */
public static <SignatureType, ProvenanceType>
ImmutableMap<String, BrokenDownProvenancedConfusionMatrix<SignatureType, ProvenanceType>>
computeBreakdowns(
    ProvenancedConfusionMatrix<ProvenanceType> corpusConfusionMatrix,
    Map<String, Function<? super ProvenanceType, SignatureType>> breakdowns,
    Ordering<SignatureType> resultKeyOrdering) {
  final ImmutableMap.Builder<String, BrokenDownProvenancedConfusionMatrix<SignatureType, ProvenanceType>>
      printModes =
      ImmutableMap.builder();

  for (final Map.Entry<String, Function<? super ProvenanceType, SignatureType>> breakdownEntry : breakdowns
      .entrySet()) {
    printModes.put(breakdownEntry.getKey(),
        corpusConfusionMatrix.breakdown(breakdownEntry.getValue(),
            resultKeyOrdering));
  }
  return printModes.build();
}
 
開發者ID:isi-nlp,項目名稱:tac-kbp-eal,代碼行數:23,代碼來源:BreakdownFunctions.java

示例15: combineBreakdowns

import com.google.common.collect.Ordering; //導入依賴的package包/類
public static ImmutableMap<String, BrokenDownSummaryConfusionMatrix<Symbol>> combineBreakdowns(
    Iterator<Map<String, BrokenDownSummaryConfusionMatrix<Symbol>>> breakdowns) {

  final Map<String, BrokenDownSummaryConfusionMatrix.Builder<Symbol>> ret = Maps.newHashMap();
  while (breakdowns.hasNext()) {
    final Map<String, BrokenDownSummaryConfusionMatrix<Symbol>> breakdown = breakdowns.next();
    for (final Map.Entry<String, BrokenDownSummaryConfusionMatrix<Symbol>> breakdownEntry : breakdown
        .entrySet()) {
      if (!ret.containsKey(breakdownEntry.getKey())) {
        ret.put(breakdownEntry.getKey(), BrokenDownSummaryConfusionMatrix.<Symbol>builder(
            Ordering.from(new SymbolUtils.ByString())));
      }
      ret.get(breakdownEntry.getKey()).combine(breakdownEntry.getValue());
    }
  }

  final ImmutableMap.Builder<String, BrokenDownSummaryConfusionMatrix<Symbol>> trueRet =
      ImmutableMap.builder();
  // return map in alphabetical order
  for (final String key : Ordering.natural().sortedCopy(ret.keySet())) {
    trueRet.put(key, ret.get(key).build());
  }
  return trueRet.build();
}
 
開發者ID:isi-nlp,項目名稱:tac-kbp-eal,代碼行數:25,代碼來源:EAScoringObserver.java


注:本文中的com.google.common.collect.Ordering類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。