当前位置: 首页>>代码示例>>Java>>正文


Java TreeMultiset.create方法代码示例

本文整理汇总了Java中com.google.common.collect.TreeMultiset.create方法的典型用法代码示例。如果您正苦于以下问题:Java TreeMultiset.create方法的具体用法?Java TreeMultiset.create怎么用?Java TreeMultiset.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.TreeMultiset的用法示例。


在下文中一共展示了TreeMultiset.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPartitionSpread

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
@Test
public void testPartitionSpread() throws Exception {
    Multiset<Integer> results = TreeMultiset.create();
    Cluster c = Cluster.empty();
    try (Partitioner p = new DefaultPartitioner()) {
        PartitionKeyGenerator pkg = new PartitionKeyGenerator();

        mockPartitions(c);

        for (int i = 0; i < messages; i++) {
            results.add(p.partition("test", null, pkg.next(), null, null, c));
        }

        int expected = messages / partitions;
        double threshold = expected * 0.05;

        for (Multiset.Entry<Integer> e : results.entrySet()) {
            int offBy = Math.abs(e.getCount() - expected);
            assertTrue("Partition " + e.getElement() + " had " + e.getCount() + " elements, expected " + expected + ", threshold is " + threshold,
                    offBy < threshold);
        }
    }
}
 
开发者ID:opentable,项目名称:otj-logging,代码行数:24,代码来源:PartitionSpreadTest.java

示例2: context

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
public ScorerContext context( List<String> words ) {
    Multiset<String> counter = TreeMultiset.create();
    counter.addAll( words );

    int word_dim = word_model.dimensions();
    float[] word_vecs = new float[ counter.size() * word_dim ];
    IntArrayList word_counts = new IntArrayList();
    int n_words = 0;

    for( Multiset.Entry<String> entry : counter.entrySet() ) {
        if( word_model.get( entry.getElement(), word_vecs, n_words * word_dim ) ) {
            word_counts.add( entry.getCount() );
            n_words += 1;
        }
    }
    word_counts.trim();

    return create_context( word_vecs, word_counts.elements() );
}
 
开发者ID:yahoo,项目名称:FEL,代码行数:20,代码来源:EntityScorer.java

示例3: visit

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
public void visit(NodeTraversal traversal, Node node, Node parent) {
  Collection<Definition> defs =
      passUnderTest.getDefinitionsReferencedAt(node);
  if (defs != null) {
    StringBuffer sb = new StringBuffer();
    sb.append("USE ");
    sb.append(Token.name(node.getType()));
    sb.append(" ");
    sb.append(node.getQualifiedName());
    sb.append(" -> ");
    Multiset<String> defstrs = TreeMultiset.create();
    for (Definition def : defs) {
      Node rValue = def.getRValue();
      if (rValue != null) {
        defstrs.add(Token.name(rValue.getType()));
      } else {
        defstrs.add("<null>");
      }
    }

    sb.append(defstrs.toString());
    found.add(sb.toString());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:SimpleDefinitionFinderTest.java

示例4: AppliedPTransformInputWatermark

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
public AppliedPTransformInputWatermark(Collection<? extends Watermark> inputWatermarks) {
  this.inputWatermarks = inputWatermarks;
  // The ordering must order elements by timestamp, and must not compare two distinct elements
  // as equal. This is built on the assumption that any element added as a pending element will
  // be consumed without modifications.
  //
  // The same logic is applied for pending timers
  Ordering<CommittedBundle<?>> pendingBundleComparator =
      new BundleByElementTimestampComparator().compound(Ordering.arbitrary());
  this.pendingElements =
      TreeMultiset.create(pendingBundleComparator);
  this.pendingTimers = TreeMultiset.create();
  this.objectTimers = new HashMap<>();
  this.existingTimers = new HashMap<>();
  currentWatermark = new AtomicReference<>(BoundedWindow.TIMESTAMP_MIN_VALUE);
}
 
开发者ID:apache,项目名称:beam,代码行数:17,代码来源:WatermarkManager.java

示例5: testPerf

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
@Test
void testPerf() {
    Map<String, Integer> map = IntStream.range(1, 10).boxed()
            .collect(toMap(it -> "s" + it, identity()));
    WeightFailover<String> failover = WeightFailover.<String> newGenericBuilder() //
            .checker(it -> 1.0) //
            .build(map);
    long s = currentTimeMillis();
    Multiset<String> counter = TreeMultiset.create();
    for (int i = 0; i < 100000; i++) {
        List<String> available = failover.getAvailable(2);
        counter.addAll(available);
    }
    // old 260~270
    System.out.println(counter + ", cost:" + (currentTimeMillis() - s));
    s = currentTimeMillis();
    counter = TreeMultiset.create();
    for (int i = 0; i < 100000; i++) {
        counter.add(failover.getOneAvailable());
    }
    // old 60~70
    System.out.println(counter + ", cost:" + (currentTimeMillis() - s));
}
 
开发者ID:PhantomThief,项目名称:simple-failover-java,代码行数:24,代码来源:WeightFailoverTest.java

示例6: main

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
public static void main(String[] args) {
    // Parse text to separate words
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Create Multiset
    Multiset<String> multiset = TreeMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));

    // Print count words
    System.out.println(multiset); // print [All!, Hello x 2, Hi, World! x 2]- in natural (alphabet) order
    // Print all unique words
    System.out.println(multiset.elementSet());    // print [All!, Hello, Hi, World!]- in natural (alphabet) order

    // Print count occurrences of words
    System.out.println("Hello = " + multiset.count("Hello"));    // print 2
    System.out.println("World = " + multiset.count("World!"));    // print 2
    System.out.println("All = " + multiset.count("All!"));    // print 1
    System.out.println("Hi = " + multiset.count("Hi"));    // print 1
    System.out.println("Empty = " + multiset.count("Empty"));    // print 0

    // Print count all words
    System.out.println(multiset.size());    //print 6

    // Print count unique words
    System.out.println(multiset.elementSet().size());    //print 4
}
 
开发者ID:Vedenin,项目名称:java_in_examples,代码行数:25,代码来源:GuavaTreeMultisetTest.java

示例7: main

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
public static void main(String[] args) {
    // Разберем текст на слова
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Создаем Multiset
    Multiset<String> multiset = TreeMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));

    // Выводим кол-вом вхождений слов
    System.out.println(multiset); // напечатает [All!, Hello x 2, Hi, World! x 2]- в алфавитном порядке
    // Выводим все уникальные слова
    System.out.println(multiset.elementSet());    // напечатает [All!, Hello, Hi, World!]- в алфавитном порядке

    // Выводим количество по каждому слову
    System.out.println("Hello = " + multiset.count("Hello"));    // напечатает 2
    System.out.println("World = " + multiset.count("World!"));    // напечатает 2
    System.out.println("All = " + multiset.count("All!"));    // напечатает 1
    System.out.println("Hi = " + multiset.count("Hi"));    // напечатает 1
    System.out.println("Empty = " + multiset.count("Empty"));    // напечатает 0

    // Выводим общее количества всех слов в тексте
    System.out.println(multiset.size());    //напечатает 6

    // Выводим общее количество всех уникальных слов
    System.out.println(multiset.elementSet().size());    //напечатает 4
}
 
开发者ID:Vedenin,项目名称:java_in_examples,代码行数:25,代码来源:GuavaTreeMultisetTest.java

示例8: getAlternativeNames

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
/**
 * @param relevantNgrams
 * @param currentName
 * @return
 */
public Multiset<String> getAlternativeNames(
		final Multiset<NGram<String>> relevantNgrams,
		final String currentName) {
	// Get all alternative namings
	final Multiset<String> nameAlternatives = ngramLM
			.getAlternativeNamings(relevantNgrams, WILDCARD_TOKEN);
	nameAlternatives.add(currentName); // Give the current identifier a
										// chance...

	// Prune naming alternatives
	final Multiset<String> toKeep = TreeMultiset.create();

	int seen = 0;
	for (final Entry<String> ent : Multisets.copyHighestCountFirst(
			nameAlternatives).entrySet()) {
		if (seen > 1000) {
			break;
		}
		toKeep.add(ent.getElement(), ent.getCount());
		seen++;
	}
	toKeep.add(AbstractNGramLM.UNK_SYMBOL);
	return toKeep;
}
 
开发者ID:mast-group,项目名称:naturalize,代码行数:30,代码来源:AbstractIdentifierRenamings.java

示例9: testSerialization

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
public void testSerialization() {
    BeanWithMultisetTypes bean = new BeanWithMultisetTypes();

    List<String> list = Arrays.asList( "foo", "abc", null, "abc" );
    List<String> listWithNonNull = Arrays.asList( "foo", "abc", "bar", "abc" );

    bean.multiset = LinkedHashMultiset.create( list );
    bean.hashMultiset = HashMultiset.create( Arrays.asList( "abc", "abc" ) );
    bean.linkedHashMultiset = LinkedHashMultiset.create( list );
    bean.sortedMultiset = TreeMultiset.create( listWithNonNull );
    bean.treeMultiset = TreeMultiset.create( listWithNonNull );
    bean.immutableMultiset = ImmutableMultiset.copyOf( listWithNonNull );
    bean.enumMultiset = EnumMultiset.create( Arrays.asList( AlphaEnum.B, AlphaEnum.A, AlphaEnum.D, AlphaEnum.A ) );

    String expected = "{" +
            "\"multiset\":[\"foo\",\"abc\",\"abc\",null]," +
            "\"hashMultiset\":[\"abc\",\"abc\"]," +
            "\"linkedHashMultiset\":[\"foo\",\"abc\",\"abc\",null]," +
            "\"sortedMultiset\":[\"abc\",\"abc\",\"bar\",\"foo\"]," +
            "\"treeMultiset\":[\"abc\",\"abc\",\"bar\",\"foo\"]," +
            "\"immutableMultiset\":[\"foo\",\"abc\",\"abc\",\"bar\"]," +
            "\"enumMultiset\":[\"A\",\"A\",\"B\",\"D\"]" +
            "}";

    assertEquals( expected, BeanWithMultisetTypesMapper.INSTANCE.write( bean ) );
}
 
开发者ID:nmorel,项目名称:gwt-jackson,代码行数:27,代码来源:MultisetGwtTest.java

示例10: testSchema

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
@Test
public void testSchema() throws IOException {
    SchemaSampler s = new SchemaSampler(Resources.asCharSource(Resources.getResource("schema014.json"), Charsets.UTF_8).read());

    Multiset<String> prefixCounts = TreeMultiset.create();
    Multiset<String> otherCounts = TreeMultiset.create();
    for (int i = 0; i < 100; i++) {
        JsonNode r = s.sample();
        assertEquals(r.get("v1").asText(), r.get("v2").get("VIN").asText());
        prefixCounts.add(r.get("v1").asText().substring(0, 2));
        otherCounts.add(r.get("v3").asText().substring(0, 2));
        System.out.printf("%s\n", r);
    }
    assertEquals("[1F, 2F, 3F]", prefixCounts.elementSet().toString());
    assertEquals("[2F, 3F]", otherCounts.elementSet().toString());
}
 
开发者ID:tdunning,项目名称:log-synth,代码行数:17,代码来源:VinSamplerTest.java

示例11: selectNext

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
private <T extends Comparable<?>> Multiset<T> selectNext(RandomSelector<T> selector, Random random, int size) {
  Multiset<T> selectedElements = TreeMultiset.create();
  for (int i = 0; i < size; i++) {
    selectedElements.add(selector.next(random));
  }
  return selectedElements;
}
 
开发者ID:ogregoire,项目名称:fror-common,代码行数:8,代码来源:RandomSelectorTest.java

示例12: visit

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
public void visit(NodeTraversal traversal, Node node, Node parent) {
  Collection<Definition> defs =
      passUnderTest.getDefinitionsReferencedAt(node);
  if (defs != null) {
    StringBuilder sb = new StringBuilder();
    sb.append("USE ");
    sb.append(Token.name(node.getType()));
    sb.append(" ");
    sb.append(node.getQualifiedName());
    sb.append(" -> ");
    Multiset<String> defstrs = TreeMultiset.create();
    for (Definition def : defs) {
      String defstr;

      Node rValue = def.getRValue();
      if (rValue != null) {
        defstr = Token.name(rValue.getType());
      } else {
        defstr = "<null>";
      }

      if (def.isExtern()) {
        defstr = "EXTERN " + defstr;
      }

      defstrs.add(defstr);
    }

    sb.append(defstrs.toString());
    found.add(sb.toString());
  }
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:33,代码来源:SimpleDefinitionFinderTest.java

示例13: computeGrammarTreeSizeStats

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
@Override
public SortedMultiset<Integer> computeGrammarTreeSizeStats() {
	// Get tree size distribution.
	final SortedMultiset<Integer> treeSizes = TreeMultiset.create();
	for (final Entry<T, ConcurrentHashMultiset<TreeNode<T>>> entry : grammar
			.entrySet()) {
		for (final Multiset.Entry<TreeNode<T>> rule : entry.getValue()
				.entrySet()) {
			treeSizes.add(rule.getElement().getTreeSize(), rule.getCount());
		}
	}
	return treeSizes;
}
 
开发者ID:mast-group,项目名称:codemining-treelm,代码行数:14,代码来源:TSGrammar.java

示例14: printStatisticsFor

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
public void printStatisticsFor(final int[] minPatternSizes,
		final int[] minPatternCounts) {
	Arrays.sort(minPatternCounts);
	Arrays.sort(minPatternSizes);

	loadPatternsForFiles();

	Multiset<Integer> prunedByCount = TreeMultiset.create();
	for (final Entry<TreeNode<Integer>> pattern : patterns.entrySet()) {
		prunedByCount.add(patternDictionary.get(pattern.getElement()),
				pattern.getCount());
	}
	System.out
			.println("minCount,minSize,nSeenPatterns,patternRecall,avgPatternSizeSeen,avgCoverage,avgFileRecall,avgSitesMatched,avgPatternSizePerFile");

	for (int i = 0; i < minPatternCounts.length; i++) {
		prunedByCount = getRulesWithMinCount(prunedByCount,
				minPatternCounts[i]);

		Multiset<Integer> prunedByCountBySize = prunedByCount;
		for (int j = 0; j < minPatternSizes.length; j++) {
			prunedByCountBySize = getRulesWithMinSize(prunedByCountBySize,
					minPatternSizes[j]);
			// Great now our patterns are in prunedByCountBySize
			printPatternStatistics(prunedByCountBySize,
					minPatternCounts[i], minPatternSizes[j]);
		}
	}
}
 
开发者ID:mast-group,项目名称:codemining-treelm,代码行数:30,代码来源:PatternStatsCalculator.java

示例15: getAlternativeNamings

import com.google.common.collect.TreeMultiset; //导入方法依赖的package包/类
public Multiset<String> getAlternativeNamings(
		final Multiset<NGram<String>> ngrams, final String tokenToSubstitute) {
	final Multiset<String> namings = TreeMultiset.create();
	final LongTrie<String> globalTrie = getTrie();

	for (final Multiset.Entry<NGram<String>> ngramEntry : ngrams.entrySet()) {
		final NGram<String> ngram = ngramEntry.getElement();

		final Set<String> alternatives = checkNotNull(getAlternativesForNGram(
				globalTrie, ngram, tokenToSubstitute));
		namings.addAll(alternatives);
	}

	return namings;
}
 
开发者ID:mast-group,项目名称:codemining-sequencelm,代码行数:16,代码来源:AbstractNGramLM.java


注:本文中的com.google.common.collect.TreeMultiset.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。