本文整理汇总了Java中com.google.common.collect.Multiset类的典型用法代码示例。如果您正苦于以下问题:Java Multiset类的具体用法?Java Multiset怎么用?Java Multiset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Multiset类属于com.google.common.collect包,在下文中一共展示了Multiset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSiaSeed
import com.google.common.collect.Multiset; //导入依赖的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"));
}
示例2: shouldUpdateExpressionSetsInBean
import com.google.common.collect.Multiset; //导入依赖的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"))));
}
示例3: evaluateCorrect_commutated_equalSignInGap
import com.google.common.collect.Multiset; //导入依赖的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));
}
示例4: writeResult
import com.google.common.collect.Multiset; //导入依赖的package包/类
@Override
public void writeResult(final List<EALScorer2015Style.Result> perDocResults,
final File eventTypesDir) throws IOException {
final Multiset<Symbol> eventTypesSeen = gatherEventTypesSeen(perDocResults);
for (final Multiset.Entry<Symbol> typeEntry : Multisets.copyHighestCountFirst(eventTypesSeen)
.entrySet()) {
final Symbol type = typeEntry.getElement();
final Function<EALScorer2015Style.ArgResult, EALScorer2015Style.ArgResult>
filterFunction =
new Function<EALScorer2015Style.ArgResult, EALScorer2015Style.ArgResult>() {
@Override
public EALScorer2015Style.ArgResult apply(final
EALScorer2015Style.ArgResult input) {
return input.copyFiltered(compose(equalTo(type), type()));
}
};
final File eventTypeDir = new File(eventTypesDir, type.asString());
eventTypeDir.mkdirs();
writeOverallArgumentScoresForTransformedResults(perDocResults, filterFunction,
eventTypeDir);
}
}
示例5: assertSetCount
import com.google.common.collect.Multiset; //导入依赖的package包/类
private void assertSetCount(E element, int count) {
setCountCheckReturnValue(element, count);
assertEquals(
"multiset.count() should return the value passed to setCount()",
count,
getMultiset().count(element));
int size = 0;
for (Multiset.Entry<E> entry : getMultiset().entrySet()) {
size += entry.getCount();
}
assertEquals(
"multiset.size() should be the sum of the counts of all entries",
size,
getMultiset().size());
}
示例6: add
import com.google.common.collect.Multiset; //导入依赖的package包/类
public void add(Key<?> key, State state, Object source) {
if (backingMap == null) {
backingMap = Maps.newHashMap();
}
// if it's an instanceof Class, it was a JIT binding, which we don't
// want to retain.
if (source instanceof Class || source == SourceProvider.UNKNOWN_SOURCE) {
source = null;
}
Multiset<Object> sources = backingMap.get(key);
if (sources == null) {
sources = LinkedHashMultiset.create();
backingMap.put(key, sources);
}
Object convertedSource = Errors.convert(source);
sources.add(convertedSource);
// Avoid all the extra work if we can.
if (state.parent() != State.NONE) {
Set<KeyAndSource> keyAndSources = evictionCache.getIfPresent(state);
if (keyAndSources == null) {
evictionCache.put(state, keyAndSources = Sets.newHashSet());
}
keyAndSources.add(new KeyAndSource(key, convertedSource));
}
}
示例7: testEntrySet_iteratorRemovePropagates
import com.google.common.collect.Multiset; //导入依赖的package包/类
@CollectionSize.Require(ONE)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testEntrySet_iteratorRemovePropagates() {
Iterator<Multiset.Entry<E>> iterator = getMultiset().entrySet().iterator();
assertTrue(
"non-empty multiset.entrySet() iterator.hasNext() returned false", iterator.hasNext());
assertEquals(
"multiset.entrySet() iterator.next() returned incorrect entry",
Multisets.immutableEntry(e0(), 1),
iterator.next());
assertFalse(
"size 1 multiset.entrySet() iterator.hasNext() returned true after next()",
iterator.hasNext());
iterator.remove();
assertTrue(
"multiset isn't empty after multiset.entrySet() iterator.remove()",
getMultiset().isEmpty());
}
示例8: testEntryReflectsIteratorRemove
import com.google.common.collect.Multiset; //导入依赖的package包/类
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@MultisetFeature.Require(ENTRIES_ARE_VIEWS)
public void testEntryReflectsIteratorRemove() {
initThreeCopies();
assertEquals(3, getMultiset().count(e0()));
Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet());
assertEquals(3, entry.getCount());
Iterator<E> itr = getMultiset().iterator();
itr.next();
itr.remove();
assertEquals(2, entry.getCount());
itr.next();
itr.remove();
itr.next();
itr.remove();
assertEquals(0, entry.getCount());
}
示例9: testEnqueueAndDispatch_multithreaded
import com.google.common.collect.Multiset; //导入依赖的package包/类
public void testEnqueueAndDispatch_multithreaded() throws InterruptedException {
Object listener = new Object();
ExecutorService service = Executors.newFixedThreadPool(4);
ListenerCallQueue<Object> queue = new ListenerCallQueue<>();
try {
queue.addListener(listener, service);
final CountDownLatch latch = new CountDownLatch(1);
Multiset<Object> counters = ConcurrentHashMultiset.create();
queue.enqueue(incrementingEvent(counters, listener, 1));
queue.enqueue(incrementingEvent(counters, listener, 2));
queue.enqueue(incrementingEvent(counters, listener, 3));
queue.enqueue(incrementingEvent(counters, listener, 4));
queue.enqueue(countDownEvent(latch));
assertEquals(0, counters.size());
queue.dispatch();
latch.await();
assertEquals(multiset(listener, 4), counters);
} finally {
service.shutdown();
}
}
示例10: runQuery
import com.google.common.collect.Multiset; //导入依赖的package包/类
private QueryResult runQuery()
throws IOException, QueryEvaluationException,
QueryResultParseException, TupleQueryResultHandlerException,
QueryResultHandlerException {
TestResultHandler noninf = new TestResultHandler();
TestResultHandler actual = new TestResultHandler();
TestResultHandler expect = new TestResultHandler();
parser.setQueryResultHandler(expect);
parser.parseQueryResult(getResource(expected));
nonInfQuery.evaluate(noninf);
query.evaluate(actual);
Multiset<BindingSet> noninfset = noninf.getSolutions();
Multiset<BindingSet> expectset = expect.getSolutions();
Multiset<BindingSet> actualset = actual.getSolutions();
return new QueryResult(expectset, actualset, noninfset);
}
示例11: tokenizeToMultiset
import com.google.common.collect.Multiset; //导入依赖的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;
}
示例12: testKeysWithNullKey
import com.google.common.collect.Multiset; //导入依赖的package包/类
@CollectionSize.Require(SEVERAL)
@MapFeature.Require(ALLOWS_NULL_KEYS)
public void testKeysWithNullKey() {
resetContainer(
Helpers.mapEntry((K) null, v0()),
Helpers.mapEntry((K) null, v1()),
Helpers.mapEntry(k1(), v0()));
Multiset<K> keys = multimap().keys();
assertEquals(2, keys.count(null));
assertEquals(1, keys.count(k1()));
assertEquals(3, keys.size());
assertContainsAllOf(keys, null, k1());
assertContainsAllOf(
keys.entrySet(), Multisets.immutableEntry((K) null, 2), Multisets.immutableEntry(k1(), 1));
}
示例13: predecessorsMultiset
import com.google.common.collect.Multiset; //导入依赖的package包/类
private Multiset<N> predecessorsMultiset() {
Multiset<N> predecessors = getReference(predecessorsReference);
if (predecessors == null) {
predecessors = HashMultiset.create(inEdgeMap.values());
predecessorsReference = new SoftReference<Multiset<N>>(predecessors);
}
return predecessors;
}
示例14: evaluate
import com.google.common.collect.Multiset; //导入依赖的package包/类
@Override
public boolean evaluate(ExpressionBean bean) {
Multiset<Multiset<String>> correctAnswers = bean.getCorectResponses();
Multiset<Multiset<String>> userAnswers = responseFinder.getResponseMultiSet(bean, fetcherFunctions.getUserAnswerFetcher());
Multiset<Multiset<String>> adaptedUserAnswers = convertSpecialCharacters(userAnswers);
Multiset<Multiset<String>> adaptedCorrectAnswers = convertSpecialCharacters(correctAnswers);
return adaptedUserAnswers.equals(adaptedCorrectAnswers);
}
示例15: convertSpecialCharacters
import com.google.common.collect.Multiset; //导入依赖的package包/类
private Multiset<Multiset<String>> convertSpecialCharacters(Multiset<Multiset<String>> answers) {
Multiset<Multiset<String>> modifiedAnswers = HashMultiset.create();
for (Multiset<String> multiset : answers) {
Multiset<String> modifiedSubSet = HashMultiset.create();
for (String string : multiset) {
String modifiedString = expressionAdapter.process(string);
modifiedSubSet.add(modifiedString);
}
modifiedAnswers.add(modifiedSubSet);
}
return modifiedAnswers;
}