@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")); }
@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")))); }
@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)); }
@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); } }
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()); }
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)); } }
@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()); }
@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()); }
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(); } }
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); }
@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; }
@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)); }
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; }
@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); }
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; }
@Override public void addOutEdge(E edge, N node) { super.addOutEdge(edge, node); Multiset<N> successors = getReference(successorsReference); if (successors != null) { checkState(successors.add(node)); } }
private Multiset<N> successorsMultiset() { Multiset<N> successors = getReference(successorsReference); if (successors == null) { successors = HashMultiset.create(outEdgeMap.values()); successorsReference = new SoftReference<Multiset<N>>(successors); } return successors; }
public void add(String system, String gold, int count) { Multiset<String> set = confusions.get(gold); if (set == null) { set = HashMultiset.create(); confusions.put(gold, set); } set.add(system, count); }
private ExpressionBean buildCommutatedExpressionBean(List<Response> leftResponses, List<Response> rightResponses, List<Response> allResponses, String template) { ExpressionBean expressionBean = buildExpressionBean(allResponses, template); expressionBean.setMode(ExpressionMode.COMMUTATION); ResponseFinder responseFinder = new ResponseFinder(new ExpressionToPartsDivider(), new IdentifiersFromExpressionExtractor()); Multiset<Multiset<String>> correctAnswerMultiSet = createSetWithCorrectAnswer(responseFinder, expressionBean); expressionBean.setCorectResponses(correctAnswerMultiSet); return expressionBean; }
@Override public void observeSample(final Iterable<EALScorer2015Style.Result> perDocResults) { // TODO: refactor this with non-bootstrapped version final Multiset<Symbol> eventTypesSeen = ByEventTypeResultWriter.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), TypeRoleFillerRealisFunctions.type())); } }; final ImmutableList<EALScorer2015Style.ArgResult> relevantArgumentScores = FluentIterable.from(perDocResults).transform(ByEventTypeResultWriter.GET_ARG_SCORES_ONLY) .transform(filterFunction) .toList(); eventTypeToArgScores.put(typeEntry.getElement().asString(), AggregateResultWriter.computeArgScoresFromArgResults(relevantArgumentScores)); } }
private Multiset<N> adjacentNodesMultiset() { Multiset<N> adjacentNodes = getReference(adjacentNodesReference); if (adjacentNodes == null) { adjacentNodes = HashMultiset.create(incidentEdgeMap.values()); adjacentNodesReference = new SoftReference<Multiset<N>>(adjacentNodes); } return adjacentNodes; }
@Override public N removeOutEdge(Object edge) { N node = super.removeOutEdge(edge); Multiset<N> adjacentNodes = getReference(adjacentNodesReference); if (adjacentNodes != null) { checkState(adjacentNodes.remove(node)); } return node; }
ForMultiset(Metric<Multiset<String>> metric, Tokenizer tokenizer) { checkNotNull(metric); checkNotNull(tokenizer); this.metric = metric; this.tokenizer = tokenizer; }
@Override public N removeInEdge(Object edge, boolean isSelfLoop) { N node = super.removeInEdge(edge, isSelfLoop); Multiset<N> predecessors = getReference(predecessorsReference); if (predecessors != null) { checkState(predecessors.remove(node)); } return node; }
private void addToJson(DSubTree ast, List<Sequence> sequences, String javadoc, List<String> skeletons, List<Multiset<Integer>> cfg3_bfs, List<Multiset<Integer>> cfg4_bfs, List<Multiset<Integer>> cfg3_dfs, List<Multiset<Integer>> cfg4_dfs) { JSONOutputWrapper out = new JSONOutputWrapper(ast, sequences, javadoc, skeletons, cfg3_bfs, cfg4_bfs, cfg3_dfs, cfg4_dfs); _js.programs.add(out); }
@Override public Multiset<String> create(Object... elements) { String[] array = new String[elements.length]; int i = 0; for (Object e : elements) { array[i++] = (String) e; } return create(array); }
@CollectionSize.Require(absent = ZERO) public void testEquals_differentElements() { Multiset<E> other = HashMultiset.create(getSampleElements()); other.remove(e0()); other.add(e3()); assertFalse("multiset equals a multiset with different elements", getMultiset().equals(other)); }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) @MultisetFeature.Require(ENTRIES_ARE_VIEWS) public void testEntryReflectsEntrySetIteratorRemove() { initThreeCopies(); assertEquals(3, getMultiset().count(e0())); Iterator<Multiset.Entry<E>> entryItr = getMultiset().entrySet().iterator(); Multiset.Entry<E> entry = entryItr.next(); entryItr.remove(); assertEquals(0, entry.getCount()); }
@Override public Set<Multiset.Entry<E>> create(Object... entries) { List<Object> contents = new ArrayList<Object>(); Set<E> elements = new HashSet<E>(); for (Object o : entries) { @SuppressWarnings("unchecked") Multiset.Entry<E> entry = (Entry<E>) o; checkArgument( elements.add(entry.getElement()), "Duplicate keys not allowed in EntrySetGenerator"); for (int i = 0; i < entry.getCount(); i++) { contents.add(entry.getElement()); } } return ((Multiset<E>) gen.create(contents.toArray())).entrySet(); }
@Override public float compare(Multiset<T> a, Multiset<T> b) { if (a.isEmpty() && b.isEmpty()) { return 1.0f; } if (a.isEmpty() || b.isEmpty()) { return 0.0f; } return 1.0f - distance(a, b) / (a.size() + b.size()); }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_REMOVE) @MultisetFeature.Require(ENTRIES_ARE_VIEWS) public void testEntryViewReflectsRemove() { initThreeCopies(); assertEquals(3, getMultiset().count(e0())); Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet()); assertEquals(3, entry.getCount()); assertTrue(getMultiset().remove(e0())); assertEquals(2, entry.getCount()); assertTrue(getMultiset().elementSet().remove(e0())); assertEquals(0, entry.getCount()); }
public JSONOutputWrapper(DSubTree ast, List<Sequence> sequences, String javadoc, List<String> skeletons, List<Multiset<Integer>> cfgs3_bfs, List<Multiset<Integer>> cfgs4_bfs, List<Multiset<Integer>> cfgs3_dfs, List<Multiset<Integer>> cfgs4_dfs) { this.ast = ast; this.sequences = sequences; this.javadoc = javadoc; this.skeletons = skeletons; this.cfg3_bfs = cfgs3_bfs; this.cfg4_bfs = cfgs4_bfs; this.cfg3_dfs = cfgs3_dfs; this.cfg4_dfs = cfgs4_dfs; }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_REMOVE) @MultisetFeature.Require(ENTRIES_ARE_VIEWS) public void testEntryReflectsClear() { initThreeCopies(); assertEquals(3, getMultiset().count(e0())); Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet()); assertEquals(3, entry.getCount()); getMultiset().clear(); assertEquals(0, entry.getCount()); }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_REMOVE) @MultisetFeature.Require(ENTRIES_ARE_VIEWS) public void testEntryReflectsEntrySetClear() { initThreeCopies(); assertEquals(3, getMultiset().count(e0())); Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet()); assertEquals(3, entry.getCount()); getMultiset().entrySet().clear(); assertEquals(0, entry.getCount()); }
ForMultisetWithSimplifier(Metric<Multiset<String>> metric, Simplifier simplifier, Tokenizer tokenizer) { checkNotNull(metric); checkNotNull(simplifier); checkNotNull(tokenizer); this.metric = metric; this.simplifier = simplifier; this.tokenizer = tokenizer; }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_REMOVE) @MultisetFeature.Require(ENTRIES_ARE_VIEWS) public void testEntryReflectsElementSetClear() { initThreeCopies(); assertEquals(3, getMultiset().count(e0())); Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet()); assertEquals(3, entry.getCount()); getMultiset().elementSet().clear(); assertEquals(0, entry.getCount()); }
@CollectionSize.Require(SEVERAL) public void testKeys() { resetContainer( Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k1(), v0())); Multiset<K> keys = multimap().keys(); assertEquals(2, keys.count(k0())); assertEquals(1, keys.count(k1())); assertEquals(3, keys.size()); assertContainsAllOf(keys, k0(), k1()); assertContainsAllOf( keys.entrySet(), Multisets.immutableEntry(k0(), 2), Multisets.immutableEntry(k1(), 1)); }
ForMultiset(Distance<Multiset<String>> distance, Tokenizer tokenizer) { checkNotNull(distance); checkNotNull(tokenizer); this.distance = distance; this.tokenizer = tokenizer; }