本文整理了Java中com.google.common.collect.Multiset.setCount()
方法的一些代码示例,展示了Multiset.setCount()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Multiset.setCount()
方法的具体详情如下:
包路径:com.google.common.collect.Multiset
类名称:Multiset
方法名:setCount
[英]Adds or removes the necessary occurrences of an element such that the element attains the desired count.
[中]添加或删除元素的必要引用,以使元素达到所需的计数。
代码示例来源:origin: google/guava
@Override
public boolean setCount(E element, int oldCount, int newCount) {
synchronized (mutex) {
return delegate().setCount(element, oldCount, newCount);
}
}
代码示例来源:origin: google/guava
@Override
public int setCount(E element, int count) {
synchronized (mutex) {
return delegate().setCount(element, count);
}
}
代码示例来源:origin: google/guava
private int setCount(E element, int count) {
return getMultiset().setCount(element, count);
}
}
代码示例来源:origin: google/guava
/**
* Adds or removes the necessary occurrences of an element such that the element attains the
* desired count.
*
* @param element the element to add or remove occurrences of
* @param count the desired count of the element in this multiset
* @return this {@code Builder} object
* @throws NullPointerException if {@code element} is null
* @throws IllegalArgumentException if {@code count} is negative
*/
@CanIgnoreReturnValue
public Builder<E> setCount(E element, int count) {
contents.setCount(checkNotNull(element), count);
return this;
}
代码示例来源:origin: google/guava
@CanIgnoreReturnValue
@Override
public int setCount(E element, int count) {
return delegate().setCount(element, count);
}
代码示例来源:origin: google/guava
@CanIgnoreReturnValue
@Override
public boolean setCount(E element, int oldCount, int newCount) {
return delegate().setCount(element, oldCount, newCount);
}
代码示例来源:origin: wildfly/wildfly
@Override
public int setCount(E element, int count) {
synchronized (mutex) {
return delegate().setCount(element, count);
}
}
代码示例来源: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: google/guava
private void assertSetCountNegativeOldCount() {
try {
getMultiset().setCount(e3(), -1, 1);
fail("calling setCount() with a negative oldCount should throw IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
}
代码示例来源:origin: google/guava
/** An implementation of {@link Multiset#setCount(Object, int, int)}. */
static <E> boolean setCountImpl(Multiset<E> self, E element, int oldCount, int newCount) {
checkNonnegative(oldCount, "oldCount");
checkNonnegative(newCount, "newCount");
if (self.count(element) == oldCount) {
self.setCount(element, newCount);
return true;
} else {
return false;
}
}
代码示例来源:origin: google/j2objc
@CanIgnoreReturnValue
@Override
public boolean setCount(E element, int oldCount, int newCount) {
return delegate().setCount(element, oldCount, newCount);
}
代码示例来源:origin: google/j2objc
@CanIgnoreReturnValue
@Override
public int setCount(E element, int count) {
return delegate().setCount(element, count);
}
代码示例来源:origin: google/guava
private boolean setCount(E element, int count) {
return getMultiset().setCount(element, getMultiset().count(element), count);
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: wildfly/wildfly
@CanIgnoreReturnValue
@Override
public int setCount(E element, int count) {
return delegate().setCount(element, count);
}
代码示例来源:origin: wildfly/wildfly
@CanIgnoreReturnValue
@Override
public boolean setCount(E element, int oldCount, int newCount) {
return delegate().setCount(element, oldCount, newCount);
}
代码示例来源:origin: google/guava
@CollectionFeature.Require(SUPPORTS_ADD)
public void testSetCountConditional_oldCountTooLarge() {
assertFalse(
"setCount() with a too-large oldCount should return false",
getMultiset().setCount(e0(), 2, 3));
expectUnchanged();
}
代码示例来源:origin: google/j2objc
@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;
}
代码示例来源:origin: google/guava
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_ADD)
public void testSetCountConditional_oldCountTooSmallNonzero() {
initThreeCopies();
assertFalse(
"setCount() with a too-small oldCount should return false",
getMultiset().setCount(e0(), 1, 5));
expectContents(nCopies(3, e0()));
}
代码示例来源:origin: google/guava
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_ADD)
public void testSetCountConditional_oldCountTooSmallZero() {
assertFalse(
"setCount() with a too-small oldCount should return false",
getMultiset().setCount(e0(), 0, 2));
expectUnchanged();
}
内容来源于网络,如有侵权,请联系作者删除!