MCPcopy Create free account
hub / github.com/antlr/codebuff / retainOccurrencesImpl

Method retainOccurrencesImpl

output/java_guava/1.4.17/Multisets.java:711–729  ·  view source on GitHub ↗

Delegate implementation which cares about the element type.

(Multiset<E> multisetToModify, Multiset<?> occurrencesToRetain)

Source from the content-addressed store, hash-verified

709 */
710
711 private static <E> boolean retainOccurrencesImpl(Multiset<E> multisetToModify, Multiset<?> occurrencesToRetain) {
712 checkNotNull(multisetToModify);
713 checkNotNull(occurrencesToRetain);
714 // Avoiding ConcurrentModificationExceptions is tricky.
715 Iterator<Entry<E>> entryIterator = multisetToModify.entrySet().iterator();
716 boolean changed = false;
717 while (entryIterator.hasNext()) {
718 Entry<E> entry = entryIterator.next();
719 int retainCount = occurrencesToRetain.count(entry.getElement());
720 if (retainCount == 0) {
721 entryIterator.remove();
722 changed = true;
723 } else if (retainCount < entry.getCount()) {
724 multisetToModify.setCount(entry.getElement(), retainCount);
725 changed = true;
726 }
727 }
728 return changed;
729 }
730
731 /**
732 * For each occurrence of an element {@code e} in {@code occurrencesToRemove},

Callers 1

retainOccurrencesMethod · 0.95

Calls 10

iteratorMethod · 0.65
entrySetMethod · 0.65
nextMethod · 0.65
countMethod · 0.65
getElementMethod · 0.65
removeMethod · 0.65
getCountMethod · 0.65
setCountMethod · 0.65
checkNotNullMethod · 0.45
hasNextMethod · 0.45

Tested by

no test coverage detected