本文整理了Java中com.google.common.collect.Multiset.entrySet()
方法的一些代码示例,展示了Multiset.entrySet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Multiset.entrySet()
方法的具体详情如下:
包路径:com.google.common.collect.Multiset
类名称:Multiset
方法名:entrySet
[英]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.
[中]返回此多集内容的视图,并将其分组为多集。条目实例,每个实例提供多集合的一个元素和该元素的计数。对于multiset中的每个不同元素,该集合只包含一个条目(因此它始终与#elementSet具有相同的大小)。未指定元素集中元素的顺序。
条目集由与multiset相同的数据支持,因此对其中一个的任何更改都会立即反映在另一个中。但是,多集更改可能会也可能不会反映在已经从条目集检索到的任何条目实例中(这取决于实现)。此外,实现根本不需要支持对条目集的修改,条目实例本身甚至没有修改的方法。有关其条目集如何处理修改的更多详细信息,请参见特定的实现类。
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!