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

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

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

HashMap.remove介绍

[英]Removes the mapping with the specified key from this map.
[中]从此映射中删除具有指定键的映射。

代码示例

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

@Override
  public Double remove(Object key) {
    if (super.containsKey(key)) {
      return super.remove(key);
    } else {
      return 0.0;
    }
  }
};

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

public void setBroadcastVariable(String name, List<?> value) {
  this.uninitializedBroadcastVars.put(name, value);
  this.initializedBroadcastVars.remove(name);
}

代码示例来源:origin: alibaba/jstorm

public synchronized void stop(Flusher flusher, long flushInterval) {
  ArrayList<Flusher> pending = pendingFlushMap.get(flushInterval);
  pending.remove(flusher);
  if (pending.size() == 0) {
    pendingFlushMap.remove(flushInterval);
    timerTaskMap.remove(flushInterval).cancel();
  }
}

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

final HashMap<String, TaggedValue> resultMapping = new HashMap<String, TaggedValue>(keys.size());
final List<String> filteredMappings = new ArrayList<String>(keys.size());
for (TaggedValue tv : returnValues) {
      else if (!resultMapping.containsKey(key) && !filteredMappings.contains(key)) {
        resultMapping.put(key, cm.get(key));
      else if (resultMapping.containsKey(key)
          && filteredMappings.contains(key)) {
        resultMapping.remove(key);
      else if (resultMapping.containsKey(key)
          && !filteredMappings.contains(key)
          && !cm.get(key).equals(resultMapping.get(key))) {
        filteredMappings.add(key);
        resultMapping.remove(key);
while (it.hasNext()) {
  Map.Entry<String, TaggedValue> entry = it.next();
  TaggedValue value = mergeReturnValues(Collections.singletonList(entry.getValue()));
  if (value == null) {

代码示例来源:origin: naman14/Timber

mExtraData = new ArrayList<Object>();
mMapCursorPositions = new HashMap<Long, Integer>(mCursor.getCount());
final int idPosition = mCursor.getColumnIndex(columnName);
    mMapCursorPositions.put(mCursor.getLong(idPosition), mCursor.getPosition());
  } while (mCursor.moveToNext());
    if (mMapCursorPositions.containsKey(id)) {
      mOrderedPositions.add(mMapCursorPositions.get(id));
      mMapCursorPositions.remove(id);
      if (extraData != null) {
        mExtraData.add(extraData.get(i));

代码示例来源:origin: ethereum/ethereumj

HashMap<String, String> testerMap = new HashMap<>();
  testerMap.put(word1, word2);
  String word1 = randomWords.get(randomIndex).trim();
  testerMap.remove(word1);
  trie.delete(word1);
Iterator<String> keys = testerMap.keySet().iterator();
while (keys.hasNext()) {
  String mapWord1 = keys.next();
  String mapWord2 = testerMap.get(mapWord1);
  String treeWord2 = new String(trie.get(mapWord1));

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

public void put(K key, V value) {
  Iterator<HashMap<K, V>> it = _buckets.iterator();
  HashMap<K, V> bucket = it.next();
  bucket.put(key, value);
  while (it.hasNext()) {
    bucket = it.next();
    bucket.remove(key);
  }
}

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

/**
 * @param nodeToBuckets A map with InternalDistributedSystem as key and either HashSet or
 *        HashMap<Integer, HashSet> as value.
 * @return Map of <old members, set/map of bucket ids they host>.
 */
private HashMap filterOldMembers(HashMap nodeToBuckets) {
 ClusterDistributionManager dm = (ClusterDistributionManager) getDistributionManager();
 HashMap oldGuys = new HashMap();
 Set<InternalDistributedMember> oldMembers =
   new HashSet<InternalDistributedMember>(nodeToBuckets.keySet());
 dm.removeMembersWithSameOrNewerVersion(oldMembers, Version.CURRENT);
 Iterator<InternalDistributedMember> oldies = oldMembers.iterator();
 while (oldies.hasNext()) {
  InternalDistributedMember old = oldies.next();
  if (nodeToBuckets.containsKey(old)) {
   oldGuys.put(old, nodeToBuckets.remove(old));
  } else {
   oldies.remove();
  }
 }
 return oldGuys;
}

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

synchronized ChannelSftp getFromPool(ConnectionInfo info) throws IOException {
 Set<ChannelSftp> cons = idleConnections.get(info);
 ChannelSftp channel;
 if (cons != null && cons.size() > 0) {
  Iterator<ChannelSftp> it = cons.iterator();
  if (it.hasNext()) {
   channel = it.next();
   idleConnections.remove(info);
   return channel;
  } else {
   throw new IOException("Connection pool error.");
  }
 }
 return null;
}

代码示例来源:origin: json-iterator/java

public synchronized static void addNewEncoder(String cacheKey, Encoder encoder) {
  HashMap<String, Encoder> newCache = new HashMap<String, Encoder>(encoders);
  if (encoder == null) {
    newCache.remove(cacheKey);
  } else {
    newCache.put(cacheKey, encoder);
  }
  encoders = newCache;
}

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

public void clear() {
 Iterator kcit = key_chain.iterator();
 while (kcit.hasNext()) {
  content_map.remove(kcit.next());
 }
 Iterator vcit = value_chain.iterator();
 while (vcit.hasNext()) {
  back_map.remove(vcit.next());
 }
 key_chain.clear();
 value_chain.clear();
}

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

private void mapKey(int orikey, int key) throws Exception {
  int orivalue = map.get(orikey);
  int value = map.get(key);
  ArrayList<Integer> oriKeyList = mapList.get(orivalue);
  ArrayList<Integer> keyList = mapList.get(value);
  for (Integer temp : oriKeyList) {
    map.put(temp, value);
    keyList.add(temp);
  }
  mapList.remove(orivalue);
}

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

public void test3Bugs(HashMap<? extends CharSequence, ? extends CharSequence> map) {
  map.containsValue(3);
  map.containsKey(4.0);
  map.get(5.0);
  map.remove('r');
}

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

/**
 * Get the web session object for the given session id.
 *
 * @param sessionId the session id
 * @return the web session or null
 */
WebSession getSession(String sessionId) {
  long now = System.currentTimeMillis();
  if (lastTimeoutCheck + SESSION_TIMEOUT < now) {
    for (String id : new ArrayList<>(sessions.keySet())) {
      WebSession session = sessions.get(id);
      if (session.lastAccess + SESSION_TIMEOUT < now) {
        trace("timeout for " + id);
        sessions.remove(id);
      }
    }
    lastTimeoutCheck = now;
  }
  WebSession session = sessions.get(sessionId);
  if (session != null) {
    session.lastAccess = System.currentTimeMillis();
  }
  return session;
}

代码示例来源:origin: internetarchive/heritrix3

for(String jobName: jobConfigs.keySet().toArray(new String[0])) {
  CrawlJob cj = jobConfigs.get(jobName);
  if(!cj.getJobDir().exists()) {
    jobConfigs.remove(jobName); 
  if (jobConfigs.containsKey(jobFile.getName())) {
    continue;

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

/**
 * Rename a database object.
 *
 * @param session the session
 * @param obj the object
 * @param newName the new name
 */
public synchronized void renameDatabaseObject(Session session,
    DbObject obj, String newName) {
  checkWritingAllowed();
  int type = obj.getType();
  HashMap<String, DbObject> map = getMap(type);
  if (SysProperties.CHECK) {
    if (!map.containsKey(obj.getName())) {
      DbException.throwInternalError("not found: " + obj.getName());
    }
    if (obj.getName().equals(newName) || map.containsKey(newName)) {
      DbException.throwInternalError("object already exists: " + newName);
    }
  }
  obj.checkRename();
  int id = obj.getId();
  lockMeta(session);
  removeMeta(session, id);
  map.remove(obj.getName());
  obj.rename(newName);
  map.put(newName, obj);
  updateMetaAndFirstLevelChildren(session, obj);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void updateRigidBodies() {
  HashMap<PhysicsRigidBody, Spatial> oldObjects = bodies;
  bodies = new HashMap<PhysicsRigidBody, Spatial>();
  Collection<PhysicsRigidBody> current = space.getRigidBodyList();
  //create new map
  for (Iterator<PhysicsRigidBody> it = current.iterator(); it.hasNext();) {
    PhysicsRigidBody physicsObject = it.next();
    //copy existing spatials
    if (oldObjects.containsKey(physicsObject)) {
      Spatial spat = oldObjects.get(physicsObject);
      bodies.put(physicsObject, spat);
      oldObjects.remove(physicsObject);
    } else {
      if (filter == null || filter.displayObject(physicsObject)) {
        logger.log(Level.FINE, "Create new debug RigidBody");
        //create new spatial
        Node node = new Node(physicsObject.toString());
        node.addControl(new BulletRigidBodyDebugControl(this, physicsObject));
        bodies.put(physicsObject, node);
        physicsDebugRootNode.attachChild(node);
      }
    }
  }
  //remove leftover spatials
  for (Map.Entry<PhysicsRigidBody, Spatial> entry : oldObjects.entrySet()) {
    PhysicsRigidBody object = entry.getKey();
    Spatial spatial = entry.getValue();
    spatial.removeFromParent();
  }
}

代码示例来源:origin: aa112901/remusic

mExtraData = new ArrayList<Object>();
mMapCursorPositions = new HashMap<Long, Integer>(mCursor.getCount());
final int idPosition = mCursor.getColumnIndex(columnName);
    mMapCursorPositions.put(mCursor.getLong(idPosition), mCursor.getPosition());
  } while (mCursor.moveToNext());
    if (mMapCursorPositions.containsKey(id)) {
      mOrderedPositions.add(mMapCursorPositions.get(id));
      mMapCursorPositions.remove(id);
      if (extraData != null) {
        mExtraData.add(extraData.get(i));

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

Set<Integer> bucketSet = new HashSet<Integer>();
Iterator<Integer> itr = this.getRegionAdvisor().getBucketSet().iterator();
while (itr.hasNext()) {
 try {
  bucketSet.add(itr.next());
 } catch (NoSuchElementException ignore) {
 Set memberKeySet = memberToBuckets.keySet();
 RetryTimeKeeper retryTime = new RetryTimeKeeper(this.retryTimeout);
 while (iterator.hasNext()) {
  if (execution.getFailedNodes().contains(((DistributedMember) iterator.next()).getId())) {
   hasRemovedNode = true;
Set<InternalDistributedMember> dest = memberToBuckets.keySet();
execution.validateExecution(function, dest);
execution.setExecutionNodes(dest);
final Set<Integer> localBucketSet = memberToBuckets.remove(getMyId());
if (localBucketSet != null) {
 isSelf = true;
  new HashMap<InternalDistributedMember, FunctionRemoteContext>();
for (InternalDistributedMember recip : memberToBuckets.keySet()) {
 FunctionRemoteContext context = new FunctionRemoteContext(function,
   execution.getArgumentsForMember(recip.getId()), null, memberToBuckets.get(recip),
   execution.isReExecute(), execution.isFnSerializationReqd());
 recipMap.put(recip, context);

代码示例来源:origin: alibaba/jstorm

@Override
public void put(K key, V value) {
  synchronized (lock) {
    Iterator<HashMap<K, V>> it = buckets.iterator();
    HashMap<K, V> bucket = it.next();
    bucket.put(key, value);
    while (it.hasNext()) {
      bucket = it.next();
      bucket.remove(key);
    }
  }
}

相关文章