当前位置: 首页>>代码示例>>Java>>正文


Java Collection.clear方法代码示例

本文整理汇总了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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:FilteredEntryMultimap.java

示例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());
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:17,代码来源:MapTestCase.java

示例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);
			}
		}
	}
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:22,代码来源:ServiceUtil.java

示例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);
}
 
开发者ID:s-store,项目名称:s-store,代码行数:21,代码来源:AbstractMapBasedMultimap.java

示例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);
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:18,代码来源:SchemaList.java

示例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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:26,代码来源:Multimaps.java

示例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);
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:14,代码来源:Select2MultiChoice.java

示例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;
}
 
开发者ID:s-store,项目名称:s-store,代码行数:13,代码来源:AbstractMapBasedMultimap.java

示例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()));
    }
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:8,代码来源:IncrementalStitcherTest.java

示例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;
	}
}
 
开发者ID:AnnyBaby,项目名称:Mvp-Retrofit-Rxjava-Rxbus,代码行数:16,代码来源:CollectionUtils.java

示例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();
}
 
开发者ID:wirecube,项目名称:android_additive_animations,代码行数:38,代码来源:BaseAdditiveAnimator.java

示例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();
    }
  };
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:28,代码来源:AbstractMapBasedMultimap.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:CopyOnWriteArraySetTest.java

示例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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:AbstractMapBasedMultimap.java

示例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;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:11,代码来源:AbstractMapBasedMultimap.java


注:本文中的java.util.Collection.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。