本文整理匯總了Java中com.google.common.collect.Multiset.Entry.getCount方法的典型用法代碼示例。如果您正苦於以下問題:Java Entry.getCount方法的具體用法?Java Entry.getCount怎麽用?Java Entry.getCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Multiset.Entry
的用法示例。
在下文中一共展示了Entry.getCount方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: retainOccurrencesImpl
import com.google.common.collect.Multiset.Entry; //導入方法依賴的package包/類
/**
* 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;
}
示例2: equalsImpl
import com.google.common.collect.Multiset.Entry; //導入方法依賴的package包/類
/**
* 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;
}
示例3: contains
import com.google.common.collect.Multiset.Entry; //導入方法依賴的package包/類
@Override
public boolean contains(@Nullable Object o) {
if (o instanceof Entry) {
/*
* The GWT compiler wrongly issues a warning here.
*/
@SuppressWarnings("cast")
Entry<?> entry = (Entry<?>) o;
if (entry.getCount() <= 0) {
return false;
}
int count = multiset().count(entry.getElement());
return count == entry.getCount();
}
return false;
}
示例4: remove
import com.google.common.collect.Multiset.Entry; //導入方法依賴的package包/類
@SuppressWarnings("cast")
@Override
public boolean remove(Object object) {
if (object instanceof Multiset.Entry) {
Entry<?> entry = (Entry<?>) object;
Object element = entry.getElement();
int entryCount = entry.getCount();
if (entryCount != 0) {
// Safe as long as we never add a new entry, which we won't.
@SuppressWarnings("unchecked")
Multiset<Object> multiset = (Multiset) multiset();
return multiset.setCount(element, entryCount, 0);
}
}
return false;
}
示例5: identifyDuplicates
import com.google.common.collect.Multiset.Entry; //導入方法依賴的package包/類
private void identifyDuplicates(List<ModContainer> mods)
{
TreeMultimap<ModContainer, File> dupsearch = TreeMultimap.create(new ModIdComparator(), Ordering.arbitrary());
for (ModContainer mc : mods)
{
if (mc.getSource() != null)
{
dupsearch.put(mc, mc.getSource());
}
}
ImmutableMultiset<ModContainer> duplist = Multisets.copyHighestCountFirst(dupsearch.keys());
SetMultimap<ModContainer, File> dupes = LinkedHashMultimap.create();
for (Entry<ModContainer> e : duplist.entrySet())
{
if (e.getCount() > 1)
{
FMLLog.severe("Found a duplicate mod %s at %s", e.getElement().getModId(), dupsearch.get(e.getElement()));
dupes.putAll(e.getElement(),dupsearch.get(e.getElement()));
}
}
if (!dupes.isEmpty())
{
throw new DuplicateModsFoundException(dupes);
}
}
示例6: containsOccurrences
import com.google.common.collect.Multiset.Entry; //導入方法依賴的package包/類
/**
* 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;
}
示例7: sizeImpl
import com.google.common.collect.Multiset.Entry; //導入方法依賴的package包/類
/**
* An implementation of {@link Multiset#size}.
*/
static int sizeImpl(Multiset<?> multiset) {
long size = 0;
for (Entry<?> entry : multiset.entrySet()) {
size += entry.getCount();
}
return Ints.saturatedCast(size);
}
示例8: totalSize
import com.google.common.collect.Multiset.Entry; //導入方法依賴的package包/類
private static int totalSize(Iterable<? extends Entry<?>> entries) {
int sum = 0;
for (Entry<?> entry : entries) {
sum += entry.getCount();
}
return sum;
}
示例9: removeOccurrences
import com.google.common.collect.Multiset.Entry; //導入方法依賴的package包/類
/**
* For each occurrence of an element {@code e} in {@code occurrencesToRemove},
* removes one occurrence of {@code e} in {@code multisetToModify}.
*
* <p>Equivalently, this method modifies {@code multisetToModify} so that
* {@code multisetToModify.count(e)} is set to
* {@code Math.max(0, multisetToModify.count(e) -
* occurrencesToRemove.count(e))}.
*
* <p>This is <i>not</i> the same as {@code multisetToModify.}
* {@link Multiset#removeAll removeAll}{@code (occurrencesToRemove)}, which
* removes all occurrences of elements that appear in
* {@code occurrencesToRemove}. However, this operation <i>is</i> equivalent
* to, albeit sometimes more efficient than, the following: <pre> {@code
*
* for (E e : occurrencesToRemove) {
* multisetToModify.remove(e);
* }}</pre>
*
* @return {@code true} if {@code multisetToModify} was changed as a result of
* this operation
* @since 10.0 (missing in 18.0 when only the overload taking an {@code Iterable} was present)
*/
@CanIgnoreReturnValue
public static boolean removeOccurrences(
Multiset<?> multisetToModify, Multiset<?> occurrencesToRemove) {
checkNotNull(multisetToModify);
checkNotNull(occurrencesToRemove);
boolean changed = false;
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;
}
}
return changed;
}
示例10: compare
import com.google.common.collect.Multiset.Entry; //導入方法依賴的package包/類
@Override public int compare(Entry<?> entry1, Entry<?> entry2) {
return entry2.getCount() - entry1.getCount(); // subtracting two nonnegative integers
}