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

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

本文整理了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

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

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

  1. public StringInterningAmazonInfoBuilder withMetadata(HashMap<String, String> metadata) {
  2. this.metadata = metadata;
  3. if (metadata.isEmpty()) {
  4. return this;
  5. }
  6. for (Map.Entry<String, String> entry : metadata.entrySet()) {
  7. String key = entry.getKey().intern();
  8. if (VALUE_INTERN_KEYS.containsKey(key)) {
  9. entry.setValue(StringCache.intern(entry.getValue()));
  10. }
  11. }
  12. return this;
  13. }

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

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

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

  1. public FindBrokerResult findBrokerAddressInSubscribe(
  2. final String brokerName,
  3. final long brokerId,
  4. final boolean onlyThisBroker
  5. ) {
  6. String brokerAddr = null;
  7. boolean slave = false;
  8. boolean found = false;
  9. HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
  10. if (map != null && !map.isEmpty()) {
  11. brokerAddr = map.get(brokerId);
  12. slave = brokerId != MixAll.MASTER_ID;
  13. found = brokerAddr != null;
  14. if (!found && !onlyThisBroker) {
  15. Entry<Long, String> entry = map.entrySet().iterator().next();
  16. brokerAddr = entry.getValue();
  17. slave = entry.getKey() != MixAll.MASTER_ID;
  18. found = true;
  19. }
  20. }
  21. if (found) {
  22. return new FindBrokerResult(brokerAddr, slave, findBrokerVersion(brokerName, brokerAddr));
  23. }
  24. return null;
  25. }

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

  1. /**
  2. * Get the class id, or null if not found.
  3. *
  4. * @param clazz the class
  5. * @return the class id or null
  6. */
  7. static Integer getCommonClassId(Class<?> clazz) {
  8. HashMap<Class<?>, Integer> map = COMMON_CLASSES_MAP;
  9. if (map.isEmpty()) {
  10. // lazy initialization
  11. for (int i = 0, size = COMMON_CLASSES.length; i < size; i++) {
  12. COMMON_CLASSES_MAP.put(COMMON_CLASSES[i], i);
  13. }
  14. }
  15. return map.get(clazz);
  16. }

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

  1. if (rsLogTimestampMap == null || rsLogTimestampMap.isEmpty()) {
  2. return null;
  3. HashMap<String, HashMap<TableName, Long>> rsLogTimestampMapByRS = new HashMap<>();
  4. for (Entry<TableName, HashMap<String, Long>> tableEntry : rsLogTimestampMap.entrySet()) {
  5. TableName table = tableEntry.getKey();
  6. HashMap<String, Long> rsLogTimestamp = tableEntry.getValue();
  7. for (Entry<String, Long> rsEntry : rsLogTimestamp.entrySet()) {
  8. String rs = rsEntry.getKey();
  9. Long ts = rsEntry.getValue();
  10. if (!rsLogTimestampMapByRS.containsKey(rs)) {
  11. rsLogTimestampMapByRS.put(rs, new HashMap<>());
  12. rsLogTimestampMapByRS.get(rs).put(table, ts);
  13. } else {
  14. rsLogTimestampMapByRS.get(rs).put(table, ts);
  15. for (Entry<String, HashMap<TableName, Long>> entry : rsLogTimestampMapByRS.entrySet()) {
  16. String rs = entry.getKey();
  17. rsLogTimestampMins.put(rs, BackupUtils.getMinValue(entry.getValue()));

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

  1. public static AnnotationMap merge(AnnotationMap primary, AnnotationMap secondary)
  2. {
  3. if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) {
  4. return secondary;
  5. }
  6. if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) {
  7. return primary;
  8. }
  9. HashMap<Class<?>,Annotation> annotations = new HashMap<Class<?>,Annotation>();
  10. // add secondary ones first
  11. for (Annotation ann : secondary._annotations.values()) {
  12. annotations.put(ann.annotationType(), ann);
  13. }
  14. // to be overridden by primary ones
  15. for (Annotation ann : primary._annotations.values()) {
  16. annotations.put(ann.annotationType(), ann);
  17. }
  18. return new AnnotationMap(annotations);
  19. }

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

  1. /**
  2. * Get current model.
  3. * @param forDeck If true, it tries to get the deck specified in deck by mid, otherwise or if the former is not
  4. * found, it uses the configuration`s field curModel.
  5. * @return The JSONObject of the model, or null if not found in the deck and in the configuration.
  6. */
  7. public JSONObject current(boolean forDeck) {
  8. JSONObject m = null;
  9. if (forDeck) {
  10. m = get(mCol.getDecks().current().optLong("mid", -1));
  11. }
  12. if (m == null) {
  13. m = get(mCol.getConf().optLong("curModel", -1));
  14. }
  15. if (m == null) {
  16. if (!mModels.isEmpty()) {
  17. m = mModels.values().iterator().next();
  18. }
  19. }
  20. return m;
  21. }

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

  1. @Override
  2. public HashMap<Integer, T_Sess> loadAllRawSessionsOf(OmemoDevice userDevice, BareJid contact) {
  3. HashMap<Integer, T_Sess> sessions = getCache(userDevice).sessions.get(contact);
  4. if (sessions == null) {
  5. sessions = new HashMap<>();
  6. getCache(userDevice).sessions.put(contact, sessions);
  7. }
  8. if (sessions.isEmpty() && persistent != null) {
  9. sessions.putAll(persistent.loadAllRawSessionsOf(userDevice, contact));
  10. }
  11. return new HashMap<>(sessions);
  12. }

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

  1. @Override
  2. public boolean visitFile(@NotNull VirtualFile file) {
  3. final HashMap<IgnoreEntry, Pattern> current = ContainerUtil.newHashMap(getCurrentValue());
  4. if (current.isEmpty()) {
  5. return false;
  6. }
  7. final String path = Utils.getRelativePath(root, file);
  8. if (path == null || Utils.isVcsDirectory(file)) {
  9. return false;
  10. }
  11. for (Map.Entry<IgnoreEntry, Pattern> item : current.entrySet()) {
  12. final Pattern value = item.getValue();
  13. boolean matches = false;
  14. if (value == null || matcher.match(value, path)) {
  15. matches = true;
  16. result.get(item.getKey()).add(file);
  17. }
  18. if (includeNested && matches) {
  19. current.put(item.getKey(), null);
  20. }
  21. }
  22. setValueForChildren(current);
  23. return true;
  24. }
  25. };

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

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

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

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

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

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

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

  1. /**
  2. * Nullable
  3. *
  4. * @return HashMap<String, String>
  5. */
  6. public HashMap<String, String> getPackagePropertiesIfPresent() {
  7. if (!packageProperties.isEmpty()) {
  8. return packageProperties;
  9. }
  10. String property = metaContentMap.get(ShareConstants.PACKAGE_META_FILE);
  11. if (property == null) {
  12. return null;
  13. }
  14. String[] lines = property.split("\n");
  15. for (final String line : lines) {
  16. if (line == null || line.length() <= 0) {
  17. continue;
  18. }
  19. //it is comment
  20. if (line.startsWith("#")) {
  21. continue;
  22. }
  23. final String[] kv = line.split("=", 2);
  24. if (kv == null || kv.length < 2) {
  25. continue;
  26. }
  27. packageProperties.put(kv[0].trim(), kv[1].trim());
  28. }
  29. return packageProperties;
  30. }

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

  1. if (serverToBucketsMap.get(server) == null) {
  2. HashSet<Integer> bucketSet = new HashSet<Integer>();
  3. bucketSet.add(bucketId);
  4. serverToBucketsMap.put(server, bucketSet);
  5. } else {
  6. HashSet<Integer> bucketSet = serverToBucketsMap.get(server);
  7. bucketSet.add(bucketId);
  8. serverToBucketsMap.put(server, bucketSet);
  9. if (serverToBucketsMap.isEmpty()) {
  10. return null;
  11. } else {
  12. (ServerLocation) serverToBucketsMap.keySet().toArray()[rand.nextInt(size)];
  13. HashSet<Integer> bucketSet = serverToBucketsMap.get(randomFirstServer);
  14. if (isDebugEnabled) {
  15. logger.debug(
  16. prunedServerToBucketsMap.put(randomFirstServer, bucketSet);
  17. serverToBucketsMap.remove(randomFirstServer);
  18. ServerLocation server = findNextServer(serverToBucketsMap.entrySet(), currentBucketSet);
  19. if (server == null) {
  20. break;

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

  1. public static AnnotationMap merge(AnnotationMap primary, AnnotationMap secondary)
  2. {
  3. if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) {
  4. return secondary;
  5. }
  6. if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) {
  7. return primary;
  8. }
  9. HashMap<Class<?>,Annotation> annotations = new HashMap<Class<?>,Annotation>();
  10. // add secondary ones first
  11. for (Annotation ann : secondary._annotations.values()) {
  12. annotations.put(ann.annotationType(), ann);
  13. }
  14. // to be overridden by primary ones
  15. for (Annotation ann : primary._annotations.values()) {
  16. annotations.put(ann.annotationType(), ann);
  17. }
  18. return new AnnotationMap(annotations);
  19. }

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

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

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

  1. /**
  2. * Remove the right for the given role.
  3. *
  4. * @param role the role to revoke
  5. */
  6. void revokeRole(Role role) {
  7. if (grantedRoles == null) {
  8. return;
  9. }
  10. Right right = grantedRoles.get(role);
  11. if (right == null) {
  12. return;
  13. }
  14. grantedRoles.remove(role);
  15. if (grantedRoles.isEmpty()) {
  16. grantedRoles = null;
  17. }
  18. }

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

  1. public String[][] getHeaders(Object value, Operation operation) throws ServiceException {
  2. Response delegate = (Response) value;
  3. HashMap map = new HashMap();
  4. if (delegate.getContentDisposition() != null) {
  5. map.put("Content-Disposition", delegate.getContentDisposition());
  6. }
  7. HashMap m = delegate.getResponseHeaders();
  8. if (m != null && !m.isEmpty()) {
  9. map.putAll(m);
  10. }
  11. if (map == null || map.isEmpty()) return null;
  12. String[][] headers = new String[map.size()][2];
  13. List keys = new ArrayList(map.keySet());
  14. for (int i = 0; i < headers.length; i++) {
  15. headers[i][0] = (String) keys.get(i);
  16. headers[i][1] = (String) map.get(keys.get(i));
  17. }
  18. return headers;
  19. }

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

  1. for (Map.Entry<String, TableScanOperator> topOpEntry : topOps.entrySet()) {
  2. if (topOpEntry.getValue() == tso) {
  3. String newAlias = topOpEntry.getKey();
  4. if (!newAlias.equals(alias)) {
  5. joinAliases.set(index, newAlias);
  6. baseBigAlias = newAlias;
  7. aliasToNewAliasMap.put(alias, newAlias);
  8. alias = newAlias;
  9. context.setBaseBigAlias(baseBigAlias);
  10. context.setBigTablePartitioned(bigTablePartitioned);
  11. if (!aliasToNewAliasMap.isEmpty()) {
  12. context.setAliasToNewAliasMap(aliasToNewAliasMap);

相关文章