本文整理汇总了Java中java.util.Collection.clear方法的典型用法代码示例。如果您正苦于以下问题:Java Collection.clear方法的具体用法?Java Collection.clear怎么用?Java Collection.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collection
的用法示例。
在下文中一共展示了Collection.clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeEntriesIf
import java.util.Collection; //导入方法依赖的package包/类
boolean removeEntriesIf(Predicate<? super Entry<K, Collection<V>>> predicate) {
Iterator<Entry<K, Collection<V>>> entryIterator = unfiltered.asMap().entrySet().iterator();
boolean changed = false;
while (entryIterator.hasNext()) {
Entry<K, Collection<V>> entry = entryIterator.next();
K key = entry.getKey();
Collection<V> collection = filterCollection(entry.getValue(), new ValuePredicate(key));
if (!collection.isEmpty() && predicate.apply(Maps.immutableEntry(key, collection))) {
if (collection.size() == entry.getValue().size()) {
entryIterator.remove();
} else {
collection.clear();
}
changed = true;
}
}
return changed;
}
示例2: testValues
import java.util.Collection; //导入方法依赖的package包/类
public void testValues()
{
Map<String, Object> map = createMap();
_putTwo(map);
Collection<Object> values = map.values();
assertEquals(2, values.size());
assertTrue(values.contains(ONE));
assertTrue(values.contains(TWO));
// Can't really assert that this values collection is equal to
// any other, because we can't rely on the order of the collection
values.clear();
assertTrue(values.isEmpty());
assertTrue(map.isEmpty());
}
示例3: populateEcrfFieldStatusEntryCount
import java.util.Collection; //导入方法依赖的package包/类
public static void populateEcrfFieldStatusEntryCount(Collection<ECRFFieldStatusQueueCountVO> counts, Long listEntryId,
ECRFFieldStatusEntryDao ecrfFieldStatusEntryDao) {
if (counts != null) {
counts.clear();
if (listEntryId != null) {
ECRFFieldStatusQueue[] queues = ECRFFieldStatusQueue.values();
for (int i = 0; i < queues.length; i++) {
ECRFFieldStatusQueueCountVO count = new ECRFFieldStatusQueueCountVO();
count.setQueue(queues[i]);
count.setTotal(ecrfFieldStatusEntryDao.getCount(queues[i], listEntryId, false, null, null, null, null));
count.setInitial(ecrfFieldStatusEntryDao.getCount(queues[i], listEntryId, true, true, null, null, false));
count.setUpdated(ecrfFieldStatusEntryDao.getCount(queues[i], listEntryId, true, null, true, null, null));
count.setProposed(ecrfFieldStatusEntryDao.getCount(queues[i], listEntryId, true, null, null, true, null));
// count.setResolved(ecrfFieldStatusEntryDao.getCount(queues[i], listEntryId, true, false, null, null, true));
count.setResolved(ecrfFieldStatusEntryDao.getCount(queues[i], listEntryId, true, null, null, null, true));
count.setUnresolved(ecrfFieldStatusEntryDao.getCount(queues[i], listEntryId, true, null, null, null, false));
counts.add(count);
}
}
}
}
示例4: removeAll
import java.util.Collection; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* <p>The returned collection is immutable.
*/
@Override
public Collection<V> removeAll(@Nullable Object key) {
Collection<V> collection = map.remove(key);
if (collection == null) {
return createUnmodifiableEmptyCollection();
}
Collection<V> output = createCollection();
output.addAll(collection);
totalSize -= collection.size();
collection.clear();
return unmodifiableCollectionSubclass(output);
}
示例5: save
import java.util.Collection; //导入方法依赖的package包/类
public void save(MetadataMapping mapping)
{
Collection<LiteralMapping> col = mapping.getLiteralMapping();
col.clear();
Enumeration<?> enumeration = model.elements();
while( enumeration.hasMoreElements() )
{
ScriptedTarget target = (ScriptedTarget) enumeration.nextElement();
if( !target.getRules().isEmpty() )
{
LiteralMapping targetXml = new LiteralMapping();
targetXml.setValue(target.getTarget().toString());
getLiteralsXml(targetXml, target);
col.add(targetXml);
}
}
}
示例6: remove
import java.util.Collection; //导入方法依赖的package包/类
@Override
public int remove(@Nullable Object element, int occurrences) {
checkNonnegative(occurrences, "occurrences");
if (occurrences == 0) {
return count(element);
}
Collection<V> values = Maps.safeGet(multimap.asMap(), element);
if (values == null) {
return 0;
}
int oldCount = values.size();
if (occurrences >= oldCount) {
values.clear();
} else {
Iterator<V> iterator = values.iterator();
for (int i = 0; i < occurrences; i++) {
iterator.next();
iterator.remove();
}
}
return oldCount;
}
示例7: updateModel
import java.util.Collection; //导入方法依赖的package包/类
@Override
public void updateModel() {
Collection<T> choices = getModelObject();
Collection<T> selection = getConvertedInput();
if (choices == null) {
getModel().setObject(selection);
} else {
choices.clear();
choices.addAll(selection);
getModel().setObject(choices);
}
}
示例8: remove
import java.util.Collection; //导入方法依赖的package包/类
@Override public Collection<V> remove(Object key) {
Collection<V> collection = submap.remove(key);
if (collection == null) {
return null;
}
Collection<V> output = createCollection();
output.addAll(collection);
totalSize -= collection.size();
collection.clear();
return output;
}
示例9: fillCollectionFromShortIds
import java.util.Collection; //导入方法依赖的package包/类
private void fillCollectionFromShortIds(final Collection<ColouredPolygon> items, final String ids) {
items.clear();
StringTokenizer st = new StringTokenizer(ids);
while (st.hasMoreTokens()) {
items.add(retrievePolygon(st.nextToken()));
}
}
示例10: fill
import java.util.Collection; //导入方法依赖的package包/类
/**
* 用一个容器元素填充另一个容器
* @param dest 目标容器
* @param src 源容器
* @return
*/
public static <T> Collection<T> fill(Collection<T> dest, Collection<? extends T> src) {
if(dest == null) {
return null;
} else {
dest.clear();
addAll(dest, src);
return dest;
}
}
示例11: applyChanges
import java.util.Collection; //导入方法依赖的package包/类
void applyChanges(List<AccumulatedAnimationValue<V>> accumulatedAnimations) {
for(AccumulatedAnimationValue<V> accumulatedAnimationValue : accumulatedAnimations) {
V target = accumulatedAnimationValue.animation.getTarget();
mChangedTargets.add(target);
if(accumulatedAnimationValue.animation.getProperty() != null) {
accumulatedAnimationValue.animation.getProperty().set(target, accumulatedAnimationValue.tempValue);
} else {
if(mUnknownProperties == null) {
mUnknownProperties = new HashMap<>();
}
List<AccumulatedAnimationValue<V>> accumulatedValues = mUnknownProperties.get(target);
if(accumulatedValues == null) {
accumulatedValues = new ArrayList<>(1);
mUnknownProperties.put(target, accumulatedValues);
}
accumulatedValues.add(accumulatedAnimationValue);
}
}
// TODO: onChangedTargets method for subclasses
if(mUnknownProperties != null) {
for (V v : mUnknownProperties.keySet()) {
for(AccumulatedAnimationValue value : mUnknownProperties.get(v)) {
mChangedUnknownProperties.put(value.animation.getTag(), value.tempValue);
}
applyCustomProperties(mChangedUnknownProperties, v);
}
}
// reuse the set/map/lists
mChangedTargets.clear();
for(Collection<AccumulatedAnimationValue<V>> properties : mUnknownProperties.values()) {
properties.clear();
}
mChangedUnknownProperties.clear();
}
示例12: iterator
import java.util.Collection; //导入方法依赖的package包/类
@Override
public Iterator<K> iterator() {
final Iterator<Map.Entry<K, Collection<V>>> entryIterator = map().entrySet().iterator();
return new Iterator<K>() {
Map.Entry<K, Collection<V>> entry;
@Override
public boolean hasNext() {
return entryIterator.hasNext();
}
@Override
public K next() {
entry = entryIterator.next();
return entry.getKey();
}
@Override
public void remove() {
checkRemove(entry != null);
Collection<V> collection = entry.getValue();
entryIterator.remove();
totalSize -= collection.size();
collection.clear();
}
};
}
示例13: testClear
import java.util.Collection; //导入方法依赖的package包/类
/**
* clear removes all elements from the set
*/
public void testClear() {
Collection full = populatedSet(3);
full.clear();
assertEquals(0, full.size());
assertTrue(full.isEmpty());
}
示例14: clear
import java.util.Collection; //导入方法依赖的package包/类
@Override
public void clear() {
// Clear each collection, to make previously returned collections empty.
for (Collection<V> collection : map.values()) {
collection.clear();
}
map.clear();
totalSize = 0;
}
示例15: remove
import java.util.Collection; //导入方法依赖的package包/类
@Override public boolean remove(Object key) {
int count = 0;
Collection<V> collection = map().remove(key);
if (collection != null) {
count = collection.size();
collection.clear();
totalSize -= count;
}
return count > 0;
}