List of usage examples for com.google.common.collect ConcurrentHashMultiset create
@Beta public static <E> ConcurrentHashMultiset<E> create(MapMaker mapMaker)
From source file:com.github.fhirschmann.clozegen.lib.generators.CollocationGapGenerator.java
@Override public Optional<Gap> generate(final int count) { checkNotNull(model);/*from ww w. j a v a 2s .c om*/ Gap gap = new Gap(); gap.addValidAnswers(triplet.getValue1()); // Collect a list of possible candidates for this gap final Multiset<String> candidates = ConcurrentHashMultiset.create(MultisetUtils.mergeMultiSets( model.getTails().get(triplet.getValue2()), model.getHeads().get(triplet.getValue0()))); // Remove the correct answer from the candidate set candidates.remove(triplet.getValue1(), candidates.count(triplet.getValue1())); // Remove candidates p* which appear in the context (A, p*, B) for (Entry<String> entry : candidates.entrySet()) { if (model.getMultiset().contains( MiscUtils.WS_JOINER.join(triplet.getValue0(), entry.getElement(), triplet.getValue2()))) { candidates.remove(entry.getElement(), entry.getCount()); } } if (candidates.elementSet().size() > count - 2) { final Set<String> invalidAnswers = Sets .newHashSet(MultisetUtils.sortedElementList(candidates, count - 1)); gap.addInvalidAnswers(invalidAnswers); return Optional.of(gap); } else { return Optional.absent(); } }