当前位置: 首页>>代码示例>>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;未经允许,请勿转载。