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


Java HashMultiset類代碼示例

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


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

示例1: checkAttributeNamesForDuplicates

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
private void checkAttributeNamesForDuplicates(ValueType type, Protoclass protoclass) {
  if (!type.attributes.isEmpty()) {
    Multiset<String> attributeNames = HashMultiset.create(type.attributes.size());
    for (ValueAttribute attribute : type.attributes) {
      attributeNames.add(attribute.name());
    }

    List<String> duplicates = Lists.newArrayList();
    for (Multiset.Entry<String> entry : attributeNames.entrySet()) {
      if (entry.getCount() > 1) {
        duplicates.add(entry.getElement());
      }
    }

    if (!duplicates.isEmpty()) {
      protoclass.report()
          .error("Duplicate attribute names %s. You should check if correct @Value.Style applied",
              duplicates);
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:ValueTypeComposer.java

示例2: getSiaSeed

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
@Test
    public void getSiaSeed() throws Exception {
        final SiaSeedService siaSeedService = new SiaSeedService(new StaticEncyptionKeyProvider("123"));
//        final List<String> strings = siaSeedService.buildSiaSeed("123");
        final Multiset<Long> counts;
        counts = HashMultiset.create();
        for (int i = 0; i < 100000; i++) {
            final String secretKey = "abc123782567825784__" + i;
            final List<String> words = siaSeedService.buildSiaSeed(secretKey);
            final String wordsList = Joiner.on(" ").join(words);
            final String errrorMessage = "secret produced unexpected length: " + secretKey + " words: " + wordsList;
            counts.add((long) words.size());
//            Assert.assertEquals(errrorMessage, 29, words.size());

        }
        counts.forEachEntry((length, count) -> System.out.println(length + " occurred " + count + " times"));
    }
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:18,代碼來源:SiaSeedServiceTest.java

示例3: shouldUpdateExpressionSetsInBean

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
@Test
public void shouldUpdateExpressionSetsInBean() throws Exception {
    // given
    ExpressionBean expression = new ExpressionBean();

    expression.setTemplate("'a'+'b'='c'");
    Response responseA = new ResponseBuilder().withIdentifier("a").withCorrectAnswers("1").build();
    expression.getResponses().add(responseA);
    Response responseB = new ResponseBuilder().withIdentifier("b").withCorrectAnswers("2").build();
    expression.getResponses().add(responseB);
    Response responseC = new ResponseBuilder().withIdentifier("c").withCorrectAnswers("3").build();
    expression.getResponses().add(responseC);

    // when
    expressionSetsFinder.updateResponsesSetsInExpression(expression);

    Multiset<Multiset<String>> corectResponsesSets = expression.getCorectResponses();
    assertEquals(3, corectResponsesSets.size());
    assertTrue(corectResponsesSets.contains(HashMultiset.create(Lists.newArrayList("3"))));
    assertTrue(corectResponsesSets.contains(HashMultiset.create(Lists.newArrayList("1", "2"))));
    assertTrue(corectResponsesSets.contains(HashMultiset.create(Lists.newArrayList("1", "2", "3"))));
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:23,代碼來源:ExpressionSetsFinderJUnitTest.java

示例4: evaluateCorrect

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
@Test
public void evaluateCorrect() {
    // given
    ExpressionBean bean = new ExpressionBean();

    List<Response> responses = Lists.newArrayList(correctResponse(), correctResponse(), correctResponse(), correctResponse(), correctResponse());
    bean.setTemplate("'0'+'2'+'3'='1'+'4'");
    bean.getResponses().addAll(responses);

    Multiset<Multiset<String>> correctAnswerMultiSet = HashMultiset.create(Lists.<Multiset<String>>newArrayList(
            HashMultiset.create(Lists.newArrayList("answer_1", "answer_4")),
            HashMultiset.create(Lists.newArrayList("answer_0", "answer_2", "answer_3")),
            HashMultiset.create(Lists.newArrayList("answer_0", "answer_2", "answer_3", "answer_1", "answer_4"))));
    bean.setCorectResponses(correctAnswerMultiSet);

    // when
    boolean result = testObj.evaluate(bean);

    // then
    assertThat(result, equalTo(true));
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:22,代碼來源:CommutationEvaluatorJUnitTest.java

示例5: evaluateCorrect_commutated

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
@Test
public void evaluateCorrect_commutated() {
    // given
    ExpressionBean bean = new ExpressionBean();

    List<Response> responses = Lists.newArrayList(response(0, 3), response(1, 4), response(2, 0), response(3, 2), (response(4, 1)));
    bean.setTemplate("'0'+'2'+'3'='1'+'4'");
    bean.getResponses().addAll(responses);

    Multiset<Multiset<String>> correctAnswerMultiSet = HashMultiset.create(Lists.<Multiset<String>>newArrayList(
            HashMultiset.<String>create(Lists.newArrayList("answer_1", "answer_4")),
            HashMultiset.<String>create(Lists.newArrayList("answer_0", "answer_2", "answer_3")),
            HashMultiset.<String>create(Lists.newArrayList("answer_0", "answer_2", "answer_3", "answer_1", "answer_4"))));
    bean.setCorectResponses(correctAnswerMultiSet);

    // when
    boolean result = testObj.evaluate(bean);

    // then
    assertThat(result, equalTo(true));
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:22,代碼來源:CommutationEvaluatorJUnitTest.java

示例6: evaluateCorrect_commutated_equalSignInGap

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
@Test
public void evaluateCorrect_commutated_equalSignInGap() {
    // given
    ExpressionBean bean = new ExpressionBean();

    List<Response> responses = Lists.newArrayList(response("=", "2", "id_equal"), response("1", "5", "id1"), response("5", "3", "id5"),
            response("3", "1", "id3"), (response("2", "=", "id2")));
    bean.setTemplate("'id1'+'id2'+'id3''id_equal'+'id5'");
    bean.getResponses().addAll(responses);

    Multiset<Multiset<String>> correctAnswerMultiSet = HashMultiset.create(Lists.<Multiset<String>>newArrayList(
            HashMultiset.create(Lists.newArrayList("5")), HashMultiset.create(Lists.newArrayList("1", "2", "3")),
            HashMultiset.create(Lists.newArrayList("1", "2", "3", "=", "5"))));
    bean.setCorectResponses(correctAnswerMultiSet);

    // when
    boolean result = testObj.evaluate(bean);

    // then
    assertThat(result, equalTo(true));
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:22,代碼來源:CommutationEvaluatorJUnitTest.java

示例7: evaluateCorrectWithCharsConversionAdapter_commutated_equalSignInGap

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
@Test
public void evaluateCorrectWithCharsConversionAdapter_commutated_equalSignInGap() {
    // given
    ExpressionBean bean = new ExpressionBean();

    List<Response> responses = Lists.newArrayList(response("=", "=", "id_equal"), response("/", ":", "id_oper"), response("15.1", "15,1", "id1"),
            response("5,1", "5.1", "id2"), response("2", "2", "id3"), response("12,5", "12,5", "id5"));
    bean.setTemplate("'id1'-'id2''id_oper''id3''id_equal''id5'");
    bean.getResponses().addAll(responses);

    Multiset<Multiset<String>> correctAnswerMultiSet = HashMultiset.create(Lists.<Multiset<String>>newArrayList(
            HashMultiset.create(Lists.newArrayList("12.5")), HashMultiset.create(Lists.newArrayList("15.1", "5,1", "/", "2")),
            HashMultiset.create(Lists.newArrayList("15.1", "5,1", "/", "2", "=", "12.5"))));
    bean.setCorectResponses(correctAnswerMultiSet);

    // when
    boolean result = testObj.evaluate(bean);

    // then
    assertThat(result, equalTo(true));
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:22,代碼來源:CommutationEvaluatorJUnitTest.java

示例8: evaluateWrong_someWrongs

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
@Test
public void evaluateWrong_someWrongs() {
    // given
    ExpressionBean bean = new ExpressionBean();
    List<Response> responses = Lists.newArrayList(correctResponse(), correctResponse(), correctResponse(), correctResponse(), wrongResponse());
    bean.setTemplate("'0'+'2'+'3'='1'+'4'");
    bean.getResponses().addAll(responses);

    Multiset<Multiset<String>> correctAnswerMultiSet = HashMultiset.create(Lists.<Multiset<String>>newArrayList(
            HashMultiset.<String>create(Lists.newArrayList("answer_1", "answer_4")),
            HashMultiset.<String>create(Lists.newArrayList("answer_0", "answer_2", "answer_3")),
            HashMultiset.<String>create(Lists.newArrayList("answer_0", "answer_2", "answer_3", "answer_1", "answer_4"))));
    bean.setCorectResponses(correctAnswerMultiSet);

    // when
    boolean result = testObj.evaluate(bean);

    // then
    assertThat(result, equalTo(false));
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:21,代碼來源:CommutationEvaluatorJUnitTest.java

示例9: evaluateWrong_commutated

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
@Test
public void evaluateWrong_commutated() {
    // given
    ExpressionBean bean = new ExpressionBean();
    List<Response> responses = Lists.newArrayList(response(0, 4), response(1, 3), response(2, 0), response(3, 2), (response(4, 1)));
    bean.setTemplate("'0'+'2'+'3'='1'+'4'");
    bean.getResponses().addAll(responses);

    Multiset<Multiset<String>> correctAnswerMultiSet = HashMultiset.create(Lists.<Multiset<String>>newArrayList(
            HashMultiset.<String>create(Lists.newArrayList("answer_1", "answer_4")),
            HashMultiset.<String>create(Lists.newArrayList("answer_0", "answer_2", "answer_3")),
            HashMultiset.<String>create(Lists.newArrayList("answer_0", "answer_2", "answer_3", "answer_1", "answer_4"))));
    bean.setCorectResponses(correctAnswerMultiSet);


    // when
    boolean result = testObj.evaluate(bean);

    // then
    assertThat(result, equalTo(false));
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:22,代碼來源:CommutationEvaluatorJUnitTest.java

示例10: intRange

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
@Test
public void intRange() throws Exception {
    Entropy e = new MutableEntropy(SEED);
    Range<Integer> range = Range.closedOpen(-5, 5);
    Multiset<Integer> distribution = HashMultiset.create();

    // Choose 1k values and check that they are in the range
    for(int i = 0; i < 10000; i++) {
        final int value = e.randomInt(range);
        assertContains(range, value);
        distribution.add(value);
        e.advance();
    }

    // Assert that each of the 10 values was chosen ~1000 times
    Ranges.forEach(range, value -> {
        assertEquals(1000D, distribution.count(value), 50D);
    });
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:20,代碼來源:EntropyTest.java

示例11: expressionsAreParallel

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
/**
 * Returns true if {@code atLeastM} of the expressions in the given column are the same kind.
 */
private static boolean expressionsAreParallel(
        List<List<ExpressionTree>> rows, int column, int atLeastM) {
    Multiset<Tree.Kind> nodeTypes = HashMultiset.create();
    for (List<? extends ExpressionTree> row : rows) {
        if (column >= row.size()) {
            continue;
        }
        nodeTypes.add(row.get(column).getKind());
    }
    for (Multiset.Entry<Tree.Kind> nodeType : nodeTypes.entrySet()) {
        if (nodeType.getCount() >= atLeastM) {
            return true;
        }
    }
    return false;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:20,代碼來源:JavaInputAstVisitor.java

示例12: tokenizeToMultiset

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
@Override
public Multiset<String> tokenizeToMultiset(String input) {

	// tokenizeToList is not reused here on purpose. Removing duplicate
	// words early means these don't have to be tokenized multiple
	// times. Increases performance.

	Multiset<String> tokens = HashMultiset.create(input.length());
	tokens.add(input);

	Multiset<String> newTokens = HashMultiset.create(input.length());
	for (Tokenizer t : tokenizers) {
		for (String token : tokens) {
			newTokens.addAll(t.tokenizeToList(token));
		}
		Multiset<String> swap = tokens;
		tokens = newTokens;
		newTokens = swap;
		newTokens.clear();
	}

	return tokens;
}
 
開發者ID:janmotl,項目名稱:linkifier,代碼行數:24,代碼來源:Tokenizers.java

示例13: gen_subgraph

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
/**
 * Generate a subgraph of size k starting at node_id using bfs
 */
public Multiset<Integer> gen_subgraph(int k, boolean bfs) {
    Multiset<Integer> result = HashMultiset.create();
    CFGFeature.logger.debug("Generating subgraphs using BFS with k = {} ...", k);
    if(this.nodes.size() == 0) {
        CFGFeature.logger.debug("Empty body.");
        return result;
    }
    for (CFGNode node : this.nodes) {
        // System.out.println(node.node.toString());
        int code = this.gen_subgraph_helper(node, k, bfs);
        // System.out.println("code : " + code + "\n\n");
        result.add(code);
    }

    CFGFeature.logger.debug("Done generating CFG feature.");
    return result;
}
 
開發者ID:capergroup,項目名稱:bayou,代碼行數:21,代碼來源:CFGFeature.java

示例14: getPreemptionSequence

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
/**
 * Creates execution sequence for pending task groups by interleaving their unique occurrences.
 * For example: {G1, G1, G1, G2, G2} will be converted into {G1, G2, G1, G2, G1}.
 *
 * @param groups Multiset of task groups.
 * @return A task group execution sequence.
 */
private static List<TaskGroupKey> getPreemptionSequence(Multiset<TaskGroupKey> groups) {
  Multiset<TaskGroupKey> mutableGroups = HashMultiset.create(groups);
  List<TaskGroupKey> instructions = Lists.newLinkedList();
  Set<TaskGroupKey> keys = ImmutableSet.copyOf(groups.elementSet());
  while (!mutableGroups.isEmpty()) {
    for (TaskGroupKey key : keys) {
      if (mutableGroups.contains(key)) {
        instructions.add(key);
        mutableGroups.remove(key);
      }
    }
  }

  return instructions;
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:23,代碼來源:PendingTaskProcessor.java

示例15: handleCompleted

import com.google.common.collect.HashMultiset; //導入依賴的package包/類
/**
 * Handling containers that are completed.
 */
private void handleCompleted(List<YarnContainerStatus> completedContainersStatuses) {
  Multiset<String> restartRunnables = HashMultiset.create();
  for (YarnContainerStatus status : completedContainersStatuses) {
    LOG.info("Container {} completed with {}:{}.",
             status.getContainerId(), status.getState(), status.getDiagnostics());
    runningContainers.handleCompleted(status, restartRunnables);
  }

  for (Multiset.Entry<String> entry : restartRunnables.entrySet()) {
    LOG.info("Re-request container for {} with {} instances.", entry.getElement(), entry.getCount());
    runnableContainerRequests.add(createRunnableContainerRequest(entry.getElement(),  entry.getCount()));
  }

  // For all runnables that needs to re-request for containers, update the expected count timestamp
  // so that the EventHandler would triggered with the right expiration timestamp.
  expectedContainers.updateRequestTime(restartRunnables.elementSet());
}
 
開發者ID:apache,項目名稱:twill,代碼行數:21,代碼來源:ApplicationMasterService.java


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