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

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

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

HashMap.isEmpty介绍

[英]Returns whether this map is empty.
[中]返回此映射是否为空。

代码示例

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

public String findBrokerAddressInPublish(final String brokerName) {
  HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
  if (map != null && !map.isEmpty()) {
    return map.get(MixAll.MASTER_ID);
  }
  return null;
}

代码示例来源:origin: Netflix/eureka

public StringInterningAmazonInfoBuilder withMetadata(HashMap<String, String> metadata) {
  this.metadata = metadata;
  if (metadata.isEmpty()) {
    return this;
  }
  for (Map.Entry<String, String> entry : metadata.entrySet()) {
    String key = entry.getKey().intern();
    if (VALUE_INTERN_KEYS.containsKey(key)) {
      entry.setValue(StringCache.intern(entry.getValue()));
    }
  }
  return this;
}

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

@Override
public MapJoinKey getAnyKey() {
 return mHash.isEmpty() ? null : mHash.keySet().iterator().next();
}

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

public FindBrokerResult findBrokerAddressInSubscribe(
  final String brokerName,
  final long brokerId,
  final boolean onlyThisBroker
) {
  String brokerAddr = null;
  boolean slave = false;
  boolean found = false;
  HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
  if (map != null && !map.isEmpty()) {
    brokerAddr = map.get(brokerId);
    slave = brokerId != MixAll.MASTER_ID;
    found = brokerAddr != null;
    if (!found && !onlyThisBroker) {
      Entry<Long, String> entry = map.entrySet().iterator().next();
      brokerAddr = entry.getValue();
      slave = entry.getKey() != MixAll.MASTER_ID;
      found = true;
    }
  }
  if (found) {
    return new FindBrokerResult(brokerAddr, slave, findBrokerVersion(brokerName, brokerAddr));
  }
  return null;
}

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

/**
 * Get the class id, or null if not found.
 *
 * @param clazz the class
 * @return the class id or null
 */
static Integer getCommonClassId(Class<?> clazz) {
  HashMap<Class<?>, Integer> map = COMMON_CLASSES_MAP;
  if (map.isEmpty()) {
    // lazy initialization
    for (int i = 0, size = COMMON_CLASSES.length; i < size; i++) {
      COMMON_CLASSES_MAP.put(COMMON_CLASSES[i], i);
    }
  }
  return map.get(clazz);
}

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

if (rsLogTimestampMap == null || rsLogTimestampMap.isEmpty()) {
 return null;
HashMap<String, HashMap<TableName, Long>> rsLogTimestampMapByRS = new HashMap<>();
for (Entry<TableName, HashMap<String, Long>> tableEntry : rsLogTimestampMap.entrySet()) {
 TableName table = tableEntry.getKey();
 HashMap<String, Long> rsLogTimestamp = tableEntry.getValue();
 for (Entry<String, Long> rsEntry : rsLogTimestamp.entrySet()) {
  String rs = rsEntry.getKey();
  Long ts = rsEntry.getValue();
  if (!rsLogTimestampMapByRS.containsKey(rs)) {
   rsLogTimestampMapByRS.put(rs, new HashMap<>());
   rsLogTimestampMapByRS.get(rs).put(table, ts);
  } else {
   rsLogTimestampMapByRS.get(rs).put(table, ts);
for (Entry<String, HashMap<TableName, Long>> entry : rsLogTimestampMapByRS.entrySet()) {
 String rs = entry.getKey();
 rsLogTimestampMins.put(rs, BackupUtils.getMinValue(entry.getValue()));

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

public static AnnotationMap merge(AnnotationMap primary, AnnotationMap secondary)
{
  if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) {
    return secondary;
  }
  if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) {
    return primary;
  }
  HashMap<Class<?>,Annotation> annotations = new HashMap<Class<?>,Annotation>();
  // add secondary ones first
  for (Annotation ann : secondary._annotations.values()) {
    annotations.put(ann.annotationType(), ann);
  }
  // to be overridden by primary ones
  for (Annotation ann : primary._annotations.values()) {
    annotations.put(ann.annotationType(), ann);
  }
  return new AnnotationMap(annotations);
}

代码示例来源:origin: ankidroid/Anki-Android

/**
 * Get current model.
 * @param forDeck If true, it tries to get the deck specified in deck by mid, otherwise or if the former is not
 *                found, it uses the configuration`s field curModel.
 * @return The JSONObject of the model, or null if not found in the deck and in the configuration.
 */
public JSONObject current(boolean forDeck) {
  JSONObject m = null;
  if (forDeck) {
    m = get(mCol.getDecks().current().optLong("mid", -1));
  }
  if (m == null) {
    m = get(mCol.getConf().optLong("curModel", -1));
  }
  if (m == null) {
    if (!mModels.isEmpty()) {
      m = mModels.values().iterator().next();
    }
  }
  return m;
}

代码示例来源:origin: igniterealtime/Smack

@Override
public HashMap<Integer, T_Sess> loadAllRawSessionsOf(OmemoDevice userDevice, BareJid contact) {
  HashMap<Integer, T_Sess> sessions = getCache(userDevice).sessions.get(contact);
  if (sessions == null) {
    sessions = new HashMap<>();
    getCache(userDevice).sessions.put(contact, sessions);
  }
  if (sessions.isEmpty() && persistent != null) {
    sessions.putAll(persistent.loadAllRawSessionsOf(userDevice, contact));
  }
  return new HashMap<>(sessions);
}

代码示例来源:origin: hsz/idea-gitignore

@Override
  public boolean visitFile(@NotNull VirtualFile file) {
    final HashMap<IgnoreEntry, Pattern> current = ContainerUtil.newHashMap(getCurrentValue());
    if (current.isEmpty()) {
      return false;
    }
    final String path = Utils.getRelativePath(root, file);
    if (path == null || Utils.isVcsDirectory(file)) {
      return false;
    }
    for (Map.Entry<IgnoreEntry, Pattern> item : current.entrySet()) {
      final Pattern value = item.getValue();
      boolean matches = false;
      if (value == null || matcher.match(value, path)) {
        matches = true;
        result.get(item.getKey()).add(file);
      }
      if (includeNested && matches) {
        current.put(item.getKey(), null);
      }
    }
    setValueForChildren(current);
    return true;
  }
};

代码示例来源:origin: stanfordnlp/CoreNLP

enhancedDependencies.put(parent.toCopyIndex(), relationString);
      enhancedDependencies.put(govIdx, reln.toString());
if (enhancedDependencies.isEmpty() && enhancedSg != null && enhancedSg.getRoots().contains(token)) {
  additionalDepsString = "0:root";

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

/**
 * For each entry that is not dirty (all we did was read it) decrement its refcount (so it can be
 * evicted as we apply our writes) and remove it from entryMods (so we don't keep iterating over
 * it and se we don't try to clean it up again later).
 */
void cleanupNonDirtyEntries(InternalRegion r) {
 if (!this.entryMods.isEmpty()) {
  Iterator it = this.entryMods.entrySet().iterator();
  while (it.hasNext()) {
   Map.Entry me = (Map.Entry) it.next();
   // Object eKey = me.getKey();
   TXEntryState txes = (TXEntryState) me.getValue();
   if (txes.cleanupNonDirty(r)) {
    it.remove();
   }
  }
 }
}

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

@Override
public MapJoinKey getAnyKey() {
 return mHash.isEmpty() ? null : mHash.keySet().iterator().next();
}

代码示例来源:origin: Tencent/tinker

/**
 * Nullable
 *
 * @return HashMap<String, String>
 */
public HashMap<String, String> getPackagePropertiesIfPresent() {
  if (!packageProperties.isEmpty()) {
    return packageProperties;
  }
  String property = metaContentMap.get(ShareConstants.PACKAGE_META_FILE);
  if (property == null) {
    return null;
  }
  String[] lines = property.split("\n");
  for (final String line : lines) {
    if (line == null || line.length() <= 0) {
      continue;
    }
    //it is comment
    if (line.startsWith("#")) {
      continue;
    }
    final String[] kv = line.split("=", 2);
    if (kv == null || kv.length < 2) {
      continue;
    }
    packageProperties.put(kv[0].trim(), kv[1].trim());
  }
  return packageProperties;
}

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

if (serverToBucketsMap.get(server) == null) {
   HashSet<Integer> bucketSet = new HashSet<Integer>();
   bucketSet.add(bucketId);
   serverToBucketsMap.put(server, bucketSet);
  } else {
   HashSet<Integer> bucketSet = serverToBucketsMap.get(server);
   bucketSet.add(bucketId);
   serverToBucketsMap.put(server, bucketSet);
if (serverToBucketsMap.isEmpty()) {
 return null;
} else {
   (ServerLocation) serverToBucketsMap.keySet().toArray()[rand.nextInt(size)];
HashSet<Integer> bucketSet = serverToBucketsMap.get(randomFirstServer);
if (isDebugEnabled) {
 logger.debug(
prunedServerToBucketsMap.put(randomFirstServer, bucketSet);
serverToBucketsMap.remove(randomFirstServer);
 ServerLocation server = findNextServer(serverToBucketsMap.entrySet(), currentBucketSet);
 if (server == null) {
  break;

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

public static AnnotationMap merge(AnnotationMap primary, AnnotationMap secondary)
{
  if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) {
    return secondary;
  }
  if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) {
    return primary;
  }
  HashMap<Class<?>,Annotation> annotations = new HashMap<Class<?>,Annotation>();
  // add secondary ones first
  for (Annotation ann : secondary._annotations.values()) {
    annotations.put(ann.annotationType(), ann);
  }
  // to be overridden by primary ones
  for (Annotation ann : primary._annotations.values()) {
    annotations.put(ann.annotationType(), ann);
  }
  return new AnnotationMap(annotations);
}

代码示例来源:origin: GlowstoneMC/Glowstone

private boolean getPickedUp(GlowPlayer player) {
  // todo: fire PlayerPickupItemEvent in a way that allows for 'remaining' calculations
  HashMap<Integer, ItemStack> map = player.getInventory().addItem(getItemStack());
  player
      .updateInventory(); // workaround for player editing slot & it immediately being
  // filled again
  if (!map.isEmpty()) {
    setItemStack(map.values().iterator().next());
    return false;
  } else {
    CollectItemMessage message = new CollectItemMessage(getEntityId(), player.getEntityId(),
        getItemStack().getAmount());
    world.playSound(location, Sound.ENTITY_ITEM_PICKUP, 0.3f, (float) (1 + Math.random()));
    world.getRawPlayers().stream().filter(other -> other.canSeeEntity(this))
        .forEach(other -> other.getSession().send(message));
    remove();
    return true;
  }
}

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

/**
 * Remove the right for the given role.
 *
 * @param role the role to revoke
 */
void revokeRole(Role role) {
  if (grantedRoles == null) {
    return;
  }
  Right right = grantedRoles.get(role);
  if (right == null) {
    return;
  }
  grantedRoles.remove(role);
  if (grantedRoles.isEmpty()) {
    grantedRoles = null;
  }
}

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

public String[][] getHeaders(Object value, Operation operation) throws ServiceException {
  Response delegate = (Response) value;
  HashMap map = new HashMap();
  if (delegate.getContentDisposition() != null) {
    map.put("Content-Disposition", delegate.getContentDisposition());
  }
  HashMap m = delegate.getResponseHeaders();
  if (m != null && !m.isEmpty()) {
    map.putAll(m);
  }
  if (map == null || map.isEmpty()) return null;
  String[][] headers = new String[map.size()][2];
  List keys = new ArrayList(map.keySet());
  for (int i = 0; i < headers.length; i++) {
    headers[i][0] = (String) keys.get(i);
    headers[i][1] = (String) map.get(keys.get(i));
  }
  return headers;
}

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

for (Map.Entry<String, TableScanOperator> topOpEntry : topOps.entrySet()) {
   if (topOpEntry.getValue() == tso) {
    String newAlias = topOpEntry.getKey();
    if (!newAlias.equals(alias)) {
     joinAliases.set(index, newAlias);
      baseBigAlias = newAlias;
     aliasToNewAliasMap.put(alias, newAlias);
     alias = newAlias;
context.setBaseBigAlias(baseBigAlias);
context.setBigTablePartitioned(bigTablePartitioned);
if (!aliasToNewAliasMap.isEmpty()) {
 context.setAliasToNewAliasMap(aliasToNewAliasMap);

相关文章