java.util.HashMap.clear()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(204)

本文整理了Java中java.util.HashMap.clear()方法的一些代码示例,展示了HashMap.clear()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashMap.clear()方法的具体详情如下:
包路径:java.util.HashMap
类名称:HashMap
方法名:clear

HashMap.clear介绍

[英]Removes all mappings from this hash map, leaving it empty.
[中]删除此哈希映射中的所有映射,将其保留为空。

代码示例

代码示例来源:origin: com.h2database/h2

/**
 * Set the source code for the specified class.
 * This will reset all compiled classes.
 *
 * @param className the class name
 * @param source the source code
 */
public void setSource(String className, String source) {
  sources.put(className, source);
  compiled.clear();
}

代码示例来源:origin: FudanNLP/fnlp

private void filter(int i) {
  HashMap<String, Integer> newwordsFreq = new HashMap<String, Integer>();
  for(Entry<String, Integer> e : wordsFreq.entrySet()){
    
    Integer v = e.getValue();
    if(v>i){
      String key = e.getKey();
      newwordsFreq.put(key, v);
    }
  }
  wordsFreq.clear();
  wordsFreq = newwordsFreq;
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Clear the map.
 * <p>
 * This clears each collection in the map, and so may be slow.
 */
public void clear() {
  // For gc, clear each list in the map
  Set pairs = super.entrySet();
  Iterator pairsIterator = pairs.iterator();
  while (pairsIterator.hasNext()) {
    Map.Entry keyValuePair = (Map.Entry) pairsIterator.next();
    Collection coll = (Collection) keyValuePair.getValue();
    coll.clear();
  }
  super.clear();
}

代码示例来源:origin: looly/hutool

super.clear();
BufferedReader reader = null;
try {
      valueSet = super.get(group);
      if (null == valueSet) {
        valueSet = new LinkedHashSet<String>();
      super.put(group, valueSet);
      continue;
      super.put(StrUtil.EMPTY, valueSet);

代码示例来源:origin: Sable/soot

protected void flowThrough(HashMap<Local, Set<NewExpr>> in, Unit unit, HashMap<Local, Set<NewExpr>> out) {
 Stmt s = (Stmt) unit;
 out.clear();
 out.putAll(in);
 if (s instanceof DefinitionStmt) {
  DefinitionStmt ds = (DefinitionStmt) s;
  Value lhs = ds.getLeftOp();
  Value rhs = ds.getRightOp();
  if (lhs instanceof Local) {
   HashSet<NewExpr> lv = new HashSet<NewExpr>();
   out.put((Local) lhs, lv);
   if (rhs instanceof NewExpr) {
    lv.add((NewExpr) rhs);
   } else if (rhs instanceof Local) {
    lv.addAll(in.get(rhs));
   } else {
    lv.add(UNKNOWN);
   }
  }
 }
}

代码示例来源:origin: commons-pool/commons-pool

/**
 * Clears the pool, removing all pooled instances.
 */
@Override
public synchronized void clear() {
  Iterator<K> it = _pools.keySet().iterator();
  while(it.hasNext()) {
    K key = it.next();
    Stack<V> stack = _pools.get(key);
    destroyStack(key,stack);
  }
  _totIdle = 0;
  _pools.clear();
  _activeCount.clear();
}

代码示例来源:origin: com.h2database/h2

private void removeOldTempIndexes() {
  if (tempObjects != null) {
    metaObjects.putAll(tempObjects);
    for (PageIndex index: tempObjects.values()) {
      if (index.getTable().isTemporary()) {
        index.truncate(pageStoreSession);
        index.remove(pageStoreSession);
      }
    }
    pageStoreSession.commit(true);
    tempObjects = null;
  }
  metaObjects.clear();
  metaObjects.put(-1, metaIndex);
}

代码示例来源:origin: i2p/i2p.i2p

/**
 * Remove and hard close all the socket handlers managed by this SAM
 * STREAM session.
 *
 */
private void removeAllSocketHandlers() {
  synchronized (handlersMap) {
    for (Map.Entry<Integer, SAMStreamSessionSocketReader> e : handlersMap.entrySet()) {
       Integer id = e.getKey();
       e.getValue().stopRunning();
       sendersMap.get(id).shutDownGracefully();
    }
    handlersMap.clear();
    sendersMap.clear();
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

builder.append("[");
CHOOSE_RANDOM_REASONS.get().clear();
boolean badTarget = false;
DatanodeStorageInfo firstChosen = null;
   if (includeType != null && entry.getKey() != includeType) {
    continue;
     chosenNode, blocksize, results, entry.getKey());
   if (storage != null) {
    numOfReplicas--;
    int num = entry.getValue();
    if (num == 1) {
     iter.remove();

代码示例来源:origin: looly/hutool

super.clear();
BufferedReader reader = null;
try {
      valueSet = super.get(group);
      if (null == valueSet) {
        valueSet = new LinkedHashSet<String>();
      super.put(group, valueSet);
      continue;
      super.put(StrUtil.EMPTY, valueSet);

代码示例来源:origin: lealone/Lealone

/**
 * Set the source code for the specified class.
 * This will reset all compiled classes.
 *
 * @param className the class name
 * @param source the source code
 */
public void setSource(String className, String source) {
  sources.put(className, source);
  compiled.clear();
}

代码示例来源:origin: apache/geode

nodeToBuckets.entrySet().iterator(); itr.hasNext();) {
Map.Entry<InternalDistributedMember, HashMap<Integer, HashSet>> entry = itr.next();
HashMap<Integer, HashSet> bucketKeys = entry.getValue();
FetchBulkEntriesResponse fber = null;
result = new HashSet();
for (Map.Entry<Integer, HashSet> e : bucketKeys.entrySet()) {
 result.clear();
 oneBucketKeys.clear();
 oneBucketKeys.put(e.getKey(), e.getValue());
 try {
  if (entry.getKey().getVersionObject().compareTo(Version.GFE_80) < 0) {
   failures.putAll(nodeToBuckets.get(entry.getKey()));
   continue;
  if (fber.getFailedBucketIds() != null && !fber.getFailedBucketIds().isEmpty()) {
   for (int id : fber.getFailedBucketIds()) {
    failures.put(id, nodeToBuckets.get(entry.getKey()).get(id));
  failures.put(e.getKey(), e.getValue());

代码示例来源:origin: fesh0r/fernflower

mapEdges.put(newedge.getDestination(), new ArrayList<>(Collections.singletonList(newedge)));
for (Entry<Statement, List<StatEdge>> entr : mapEdges.entrySet()) {
 if (entr.getKey() == next) {
  for (StatEdge edge : entr.getValue()) {
   edge.explicit = false;
 for (Entry<Statement, List<StatEdge>> entr : mapEdges.entrySet()) {
  if (entr.getKey().type != Statement.TYPE_DUMMYEXIT &&
    (lstEdges == null || entr.getValue().size() > lstEdges.size())) {
   lstEdges = entr.getValue();
mapEdges.clear();
mapEdges.put(statedge.getDestination(), new ArrayList<>(Collections.singletonList(statedge)));

代码示例来源:origin: prestodb/presto

deser = _incompleteDeserializers.get(type);
if (deser != null) {
  return deser;
  _incompleteDeserializers.clear();

代码示例来源:origin: wildfly/wildfly

/**
 * Clear the map.
 * <p>
 * This clears each collection in the map, and so may be slow.
 */
public void clear() {
  // For gc, clear each list in the map
  Set pairs = super.entrySet();
  Iterator pairsIterator = pairs.iterator();
  while (pairsIterator.hasNext()) {
    Map.Entry keyValuePair = (Map.Entry) pairsIterator.next();
    Collection coll = (Collection) keyValuePair.getValue();
    coll.clear();
  }
  super.clear();
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

String clientPortAddress = null;
for (Entry<Object, Object> entry : zkProp.entrySet()) {
  String key = entry.getKey().toString().trim();
  String value = entry.getValue().toString().trim();
  if (key.equals("dataDir")) {
    dataDir = value;
      observers.put(Long.valueOf(sid), new QuorumServer(sid, hostname, port, electionPort, type));
    } else {
      servers.put(Long.valueOf(sid), new QuorumServer(sid, hostname, port, electionPort, type));
        throw new ConfigException("Server " + sid + "is in multiple groups");
      else
        serverGroup.put(sid, gid);
  servers.clear();
} else if (servers.size() > 1) {
  if (servers.size() == 2) {

代码示例来源:origin: apache/accumulo

mincIdleThresholds.clear();
final MemoryManagementActions result = new MemoryManagementActions();
result.tabletsToMinorCompact = new ArrayList<>();
  for (TabletInfo largest : lastEntry.getValue()) {
   toBeCompacted += largest.memTableSize;
   result.tabletsToMinorCompact.add(largest.extent);
   i++;
  largestMemTablets.remove(lastEntry.getKey());

代码示例来源:origin: chentao0707/SimplifyReader

private void buildImagesBucketList() {
  getThumbnail();
  mBucketList.clear();
      String bucketId = cursor.getString(bucketIdIndex);
      ImageBucket bucket = mBucketList.get(bucketId);
      if (bucket == null) {
        bucket = new ImageBucket();
        mBucketList.put(bucketId, bucket);
        bucket.bucketList = new ArrayList<ImageItem>();
        bucket.bucketName = bucketName;
      imageItem.setImageId(_id);
      imageItem.setImagePath(path);
      imageItem.setThumbnailPath(mThumbnailList.get(_id));
      bucket.bucketList.add(imageItem);

代码示例来源:origin: chentao0707/SimplifyReader

private void getThumbnailColumnData(Cursor cur) {
  mThumbnailList.clear();
  if (cur.moveToFirst()) {
    int image_id;
    int image_idColumn = cur.getColumnIndex(Thumbnails.IMAGE_ID);
    int dataColumn = cur.getColumnIndex(Thumbnails.DATA);
    String image_path;
    do {
      image_id = cur.getInt(image_idColumn);
      image_path = cur.getString(dataColumn);
      mThumbnailList.put("" + image_id, image_path);
    } while (cur.moveToNext());
  }
}

代码示例来源:origin: Sable/soot

@Override
protected void flowThrough(HashMap<Value, Integer> in, Unit u, HashMap<Value, Integer> out) {
 Stmt s = (Stmt) u;
 out.clear();
   if (rhs instanceof Local) {
    Integer val = in.get(rhs);
    if (val != null) {
     out.put(lhs, val);
    out.put(lhs, thisRefNumber());
   } else if (rhs instanceof ParameterRef) {
    out.put(lhs, parameterRefNumber((ParameterRef) rhs));
   } else {

相关文章