本文整理汇总了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);
}
}
}
示例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"));
}
示例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"))));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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);
});
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}