Tabnine Logo
Multiset.entrySet
Code IndexAdd Tabnine to your IDE (free)

How to use
entrySet
method
in
com.google.common.collect.Multiset

Best Java code snippets using com.google.common.collect.Multiset.entrySet (Showing top 20 results out of 666)

Refine searchRefine arrow

  • Multiset.Entry.getCount
  • Multiset.Entry.getElement
origin: google/guava

SerializedForm(Multiset<?> multiset) {
 int distinct = multiset.entrySet().size();
 elements = new Object[distinct];
 counts = new int[distinct];
 int i = 0;
 for (Entry<?> entry : multiset.entrySet()) {
  elements[i] = entry.getElement();
  counts[i] = entry.getCount();
  i++;
 }
}
origin: google/guava

/**
 * Stores the contents of a multiset in an output stream, as part of serialization. It does not
 * support concurrent multisets whose content may change while the method is running.
 *
 * <p>The serialized output consists of the number of distinct elements, the first element, its
 * count, the second element, its count, and so on.
 */
static <E> void writeMultiset(Multiset<E> multiset, ObjectOutputStream stream)
  throws IOException {
 int entryCount = multiset.entrySet().size();
 stream.writeInt(entryCount);
 for (Multiset.Entry<E> entry : multiset.entrySet()) {
  stream.writeObject(entry.getElement());
  stream.writeInt(entry.getCount());
 }
}
origin: google/j2objc

@Override
Set<Entry<E>> createEntrySet() {
 return Sets.filter(
   unfiltered.entrySet(),
   new Predicate<Entry<E>>() {
    @Override
    public boolean apply(Entry<E> entry) {
     return predicate.apply(entry.getElement());
    }
   });
}
origin: google/guava

/**
 * Runs the specified action for each distinct element in this multiset, and the number of
 * occurrences of that element. For some {@code Multiset} implementations, this may be more
 * efficient than iterating over the {@link #entrySet()} either explicitly or with {@code
 * entrySet().forEach(action)}.
 *
 * @since 21.0
 */
@Beta
default void forEachEntry(ObjIntConsumer<? super E> action) {
 checkNotNull(action);
 entrySet().forEach(entry -> action.accept(entry.getElement(), entry.getCount()));
}
origin: google/guava

/**
 * {@inheritDoc}
 *
 * <p>Elements that occur multiple times in the multiset will be passed to the {@code Consumer}
 * correspondingly many times, though not necessarily sequentially.
 */
@Override
default void forEach(Consumer<? super E> action) {
 checkNotNull(action);
 entrySet()
   .forEach(
     entry -> {
      E elem = entry.getElement();
      int count = entry.getCount();
      for (int i = 0; i < count; i++) {
       action.accept(elem);
      }
     });
}
origin: google/guava

@Override
public Set<Multiset.Entry<E>> create(Object... entries) {
 List<Object> contents = new ArrayList<>();
 Set<E> elements = new HashSet<>();
 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();
}
origin: google/guava

/** An implementation of {@link Multiset#size}. */
static int linearTimeSizeImpl(Multiset<?> multiset) {
 long size = 0;
 for (Entry<?> entry : multiset.entrySet()) {
  size += entry.getCount();
 }
 return Ints.saturatedCast(size);
}
origin: google/guava

static void serialize(SerializationStreamWriter writer, Multiset<?> instance)
  throws SerializationException {
 int entryCount = instance.entrySet().size();
 writer.writeInt(entryCount);
 for (Multiset.Entry<?> entry : instance.entrySet()) {
  writer.writeObject(entry.getElement());
  writer.writeInt(entry.getCount());
 }
}
origin: google/j2objc

/**
 * Stores the contents of a multiset in an output stream, as part of serialization. It does not
 * support concurrent multisets whose content may change while the method is running.
 *
 * <p>The serialized output consists of the number of distinct elements, the first element, its
 * count, the second element, its count, and so on.
 */
static <E> void writeMultiset(Multiset<E> multiset, ObjectOutputStream stream)
  throws IOException {
 int entryCount = multiset.entrySet().size();
 stream.writeInt(entryCount);
 for (Multiset.Entry<E> entry : multiset.entrySet()) {
  stream.writeObject(entry.getElement());
  stream.writeInt(entry.getCount());
 }
}
origin: wildfly/wildfly

SerializedForm(Multiset<?> multiset) {
 int distinct = multiset.entrySet().size();
 elements = new Object[distinct];
 counts = new int[distinct];
 int i = 0;
 for (Entry<?> entry : multiset.entrySet()) {
  elements[i] = entry.getElement();
  counts[i] = entry.getCount();
  i++;
 }
}
origin: google/guava

/** An implementation of {@link Multiset#equals}. */
static boolean equalsImpl(Multiset<?> multiset, @Nullable Object object) {
 if (object == multiset) {
  return true;
 }
 if (object instanceof Multiset) {
  Multiset<?> that = (Multiset<?>) object;
  /*
   * We can't simply check whether the entry sets are equal, since that
   * approach fails when a TreeMultiset has a comparator that returns 0
   * when passed unequal elements.
   */
  if (multiset.size() != that.size() || multiset.entrySet().size() != that.entrySet().size()) {
   return false;
  }
  for (Entry<?> entry : that.entrySet()) {
   if (multiset.count(entry.getElement()) != entry.getCount()) {
    return false;
   }
  }
  return true;
 }
 return false;
}
origin: wildfly/wildfly

/**
 * Stores the contents of a multiset in an output stream, as part of serialization. It does not
 * support concurrent multisets whose content may change while the method is running.
 *
 * <p>The serialized output consists of the number of distinct elements, the first element, its
 * count, the second element, its count, and so on.
 */
static <E> void writeMultiset(Multiset<E> multiset, ObjectOutputStream stream)
  throws IOException {
 int entryCount = multiset.entrySet().size();
 stream.writeInt(entryCount);
 for (Multiset.Entry<E> entry : multiset.entrySet()) {
  stream.writeObject(entry.getElement());
  stream.writeInt(entry.getCount());
 }
}
origin: google/guava

/** Delegate implementation which cares about the element type. */
private static <E> boolean retainOccurrencesImpl(
  Multiset<E> multisetToModify, Multiset<?> occurrencesToRetain) {
 checkNotNull(multisetToModify);
 checkNotNull(occurrencesToRetain);
 // Avoiding ConcurrentModificationExceptions is tricky.
 Iterator<Entry<E>> entryIterator = multisetToModify.entrySet().iterator();
 boolean changed = false;
 while (entryIterator.hasNext()) {
  Entry<E> entry = entryIterator.next();
  int retainCount = occurrencesToRetain.count(entry.getElement());
  if (retainCount == 0) {
   entryIterator.remove();
   changed = true;
  } else if (retainCount < entry.getCount()) {
   multisetToModify.setCount(entry.getElement(), retainCount);
   changed = true;
  }
 }
 return changed;
}
origin: opentripplanner/OpenTripPlanner

public void summarizeBuilderAnnotations() {
  List<GraphBuilderAnnotation> gbas = this.graphBuilderAnnotations;
  Multiset<Class<? extends GraphBuilderAnnotation>> classes = HashMultiset.create();
  LOG.info("Summary (number of each type of annotation):");
  for (GraphBuilderAnnotation gba : gbas)
    classes.add(gba.getClass());
  for (Multiset.Entry<Class<? extends GraphBuilderAnnotation>> e : classes.entrySet()) {
    String name = e.getElement().getSimpleName();
    int count = e.getCount();
    LOG.info("    {} - {}", name, count);
  }
}
origin: google/guava

/**
 * Returns {@code true} if {@code subMultiset.count(o) <= superMultiset.count(o)} for all {@code
 * o}.
 *
 * @since 10.0
 */
@CanIgnoreReturnValue
public static boolean containsOccurrences(Multiset<?> superMultiset, Multiset<?> subMultiset) {
 checkNotNull(superMultiset);
 checkNotNull(subMultiset);
 for (Entry<?> entry : subMultiset.entrySet()) {
  int superCount = superMultiset.count(entry.getElement());
  if (superCount < entry.getCount()) {
   return false;
  }
 }
 return true;
}
origin: google/google-java-format

/** 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;
}
origin: wildfly/wildfly

/**
 * Runs the specified action for each distinct element in this multiset, and the number of
 * occurrences of that element. For some {@code Multiset} implementations, this may be more
 * efficient than iterating over the {@link #entrySet()} either explicitly or with {@code
 * entrySet().forEach(action)}.
 *
 * @since 21.0
 */
@Beta
default void forEachEntry(ObjIntConsumer<? super E> action) {
 checkNotNull(action);
 entrySet().forEach(entry -> action.accept(entry.getElement(), entry.getCount()));
}
origin: wildfly/wildfly

/**
 * {@inheritDoc}
 *
 * <p>Elements that occur multiple times in the multiset will be passed to the {@code Consumer}
 * correspondingly many times, though not necessarily sequentially.
 */
@Override
default void forEach(Consumer<? super E> action) {
 checkNotNull(action);
 entrySet()
   .forEach(
     entry -> {
      E elem = entry.getElement();
      int count = entry.getCount();
      for (int i = 0; i < count; i++) {
       action.accept(elem);
      }
     });
}
origin: google/guava

Iterator<? extends Entry<?>> entryIterator = multisetToModify.entrySet().iterator();
while (entryIterator.hasNext()) {
 Entry<?> entry = entryIterator.next();
 int removeCount = occurrencesToRemove.count(entry.getElement());
 if (removeCount >= entry.getCount()) {
  entryIterator.remove();
  changed = true;
 } else if (removeCount > 0) {
  multisetToModify.remove(entry.getElement(), removeCount);
  changed = true;
origin: wildfly/wildfly

/** An implementation of {@link Multiset#size}. */
static int linearTimeSizeImpl(Multiset<?> multiset) {
 long size = 0;
 for (Entry<?> entry : multiset.entrySet()) {
  size += entry.getCount();
 }
 return Ints.saturatedCast(size);
}
com.google.common.collectMultisetentrySet

Javadoc

Returns a view of the contents of this multiset, grouped into Multiset.Entry instances, each providing an element of the multiset and the count of that element. This set contains exactly one entry for each distinct element in the multiset (thus it always has the same size as the #elementSet). The order of the elements in the element set is unspecified.

The entry set is backed by the same data as the multiset, so any change to either is immediately reflected in the other. However, multiset changes may or may not be reflected in any Entry instances already retrieved from the entry set (this is implementation-dependent). Furthermore, implementations are not required to support modifications to the entry set at all, and the Entry instances themselves don't even have methods for modification. See the specific implementation class for more details on how its entry set handles modifications.

Popular methods of Multiset

  • add
    Adds a number of occurrences of an element to this multiset. Note that if occurrences == 1, this met
  • count
    Returns the number of occurrences of an element in this multiset (thecount of the element). Note tha
  • elementSet
    Returns the set of distinct elements contained in this multiset. The element set is backed by the sa
  • remove
    Removes a number of occurrences of the specified element from this multiset. If the multiset contain
  • size
    Returns the total number of all occurrences of all elements in this multiset. Note: this method does
  • isEmpty
  • clear
  • contains
    Determines whether this multiset contains the specified element.This method refines Collection#conta
  • addAll
  • setCount
    Conditionally sets the count of an element to a new value, as described in #setCount(Object,int), pr
  • iterator
    Elements that occur multiple times in the multiset will appear multiple times in this iterator, thou
  • equals
    Compares the specified object with this multiset for equality. Returns true if the given object is a
  • iterator,
  • equals,
  • containsAll,
  • hashCode,
  • removeAll,
  • toString,
  • stream,
  • forEachEntry,
  • retainAll

Popular in Java

  • Start an intent from android
  • setScale (BigDecimal)
  • startActivity (Activity)
  • setRequestProperty (URLConnection)
  • Menu (java.awt)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • Path (java.nio.file)
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • JLabel (javax.swing)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now