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

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

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

HashMap.getOrDefault介绍

暂无

代码示例

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

public boolean isTrailingEquals(String key) {
  return trailingEquals.getOrDefault(key, false);
}

代码示例来源:origin: org.apache.poi/poi-ooxml

private int getAndStoreIndex(String samePath,String withoutNamespace) {
  String withPath = samePath+"/"+withoutNamespace;
  return indexMap.getOrDefault(withPath, -1);
}

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

public boolean isTrailingEquals(String key) {
  return trailingEquals.getOrDefault(key, false);
}

代码示例来源:origin: twosigma/beakerx

private static MIMEContainer IFrame(String srcTemplate, String id, HashMap params) {
 Object width = params.getOrDefault("width", DEFAULT_IFRAME_WIDTH);
 Integer height = Integer.parseInt(params.getOrDefault("height", DEFAULT_IFRAME_HEIGHT).toString());
 String src = String.format(srcTemplate, id, parseParams(params));
 return IFrame(src, width, height);
}

代码示例来源:origin: jenkinsci/jenkins

@Restricted(NoExternalUse.class)
@VisibleForTesting
public static Set<String> getAutoCompletionCandidates(List<String> loggerNamesList) {
  Set<String> loggerNames = new HashSet<>(loggerNamesList);
  // now look for package prefixes that make sense to offer for autocompletion:
  // Only prefixes that match multiple loggers will be shown.
  // Example: 'org' will show 'org', because there's org.apache, org.jenkinsci, etc.
  // 'io' might only show 'io.jenkins.plugins' rather than 'io' if all loggers starting with 'io' start with 'io.jenkins.plugins'.
  HashMap<String, Integer> seenPrefixes = new HashMap<>();
  SortedSet<String> relevantPrefixes = new TreeSet<>();
  for (String loggerName : loggerNames) {
    String[] loggerNameParts = loggerName.split("[.]");
    String longerPrefix = null;
    for (int i = loggerNameParts.length; i > 0; i--) {
      String loggerNamePrefix = StringUtils.join(Arrays.copyOf(loggerNameParts, i), ".");
      seenPrefixes.put(loggerNamePrefix, seenPrefixes.getOrDefault(loggerNamePrefix, 0) + 1);
      if (longerPrefix == null) {
        relevantPrefixes.add(loggerNamePrefix); // actual logger name
        longerPrefix = loggerNamePrefix;
        continue;
      }
      if (seenPrefixes.get(loggerNamePrefix) > seenPrefixes.get(longerPrefix)) {
        relevantPrefixes.add(loggerNamePrefix);
      }
      longerPrefix = loggerNamePrefix;
    }
  }
  return relevantPrefixes;
}

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

public Object getOrDefault(Object key, Object defaultValue) {
  return super.getOrDefault(upper(key), defaultValue);
}

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

@Override
public Map<Errors, Integer> errorCounts() {
  HashMap<Errors, Integer> counts = new HashMap<>();
  for (ReplicaElectionResult result : data.replicaElectionResults()) {
    for (PartitionResult partitionResult : result.partitionResult()) {
      Errors error = Errors.forCode(partitionResult.errorCode());
      counts.put(error, counts.getOrDefault(error, 0) + 1);
    }
  }
  return counts;
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

@POST
@Path("/graphql")
@Consumes(MediaType.APPLICATION_JSON)
public Response getGraphQL (HashMap<String, Object> queryParameters) {
  String query = (String) queryParameters.get("query");
  Object queryVariables = queryParameters.getOrDefault("variables", null);
  String operationName = (String) queryParameters.getOrDefault("operationName", null);
  Map<String, Object> variables;
  if (queryVariables instanceof Map) {
    variables = (Map) queryVariables;
  } else if (queryVariables instanceof String && !((String) queryVariables).isEmpty()) {
    try {
      variables = deserializer.readValue((String) queryVariables, Map.class);
    } catch (IOException e) {
      LOG.error("Variables must be a valid json object");
      return Response.status(Status.BAD_REQUEST).entity(MSG_400).build();
    }
  } else {
    variables = new HashMap<>();
  }
  return index.getGraphQLResponse(query, variables, operationName);
}

代码示例来源:origin: uber/okbuck

private boolean isPrebuiltDependency(ExternalDependency dependency) {
 return !skipPrebuiltDependencyMap.getOrDefault(dependency.getVersionless(), false)
   && (dependency.getPackaging().equals(AAR) || dependency.getPackaging().equals(JAR));
}

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

protected void updateMethodCountAndSizeByQueue(BlockingQueue<Runnable> queue,
  HashMap<String, Long> methodCount, HashMap<String, Long> methodSize) {
 for (Runnable r : queue) {
  FifoCallRunner mcr = (FifoCallRunner) r;
  RpcCall rpcCall = mcr.getCallRunner().getRpcCall();
  String method = getCallMethod(mcr.getCallRunner());
  if (StringUtil.isNullOrEmpty(method)) {
   method = "Unknown";
  }
  long size = rpcCall.getSize();
  methodCount.put(method, 1 + methodCount.getOrDefault(method, 0L));
  methodSize.put(method, size + methodSize.getOrDefault(method, 0L));
 }
}

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

public Map<String, Long> getCallQueueCountsSummary() {
 HashMap<String, Long> callQueueMethodTotalCount = new HashMap<>();
 for(BlockingQueue<CallRunner> queue: queues) {
  for (CallRunner cr:queue) {
   RpcCall rpcCall = cr.getRpcCall();
   String method;
   if (null==rpcCall.getMethod() ||
      StringUtil.isNullOrEmpty(method = rpcCall.getMethod().getName())) {
    method = "Unknown";
   }
   callQueueMethodTotalCount.put(method, 1+callQueueMethodTotalCount.getOrDefault(method, 0L));
  }
 }
 return callQueueMethodTotalCount;
}

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

public Map<String, Long> getCallQueueSizeSummary() {
 HashMap<String, Long> callQueueMethodTotalSize = new HashMap<>();
 for(BlockingQueue<CallRunner> queue: queues) {
  for (CallRunner cr:queue) {
   RpcCall rpcCall = cr.getRpcCall();
   String method;
   if (null==rpcCall.getMethod() ||
    StringUtil.isNullOrEmpty(method = rpcCall.getMethod().getName())) {
    method = "Unknown";
   }
   long size = rpcCall.getSize();
   callQueueMethodTotalSize.put(method, size+callQueueMethodTotalSize.getOrDefault(method, 0L));
  }
 }
 return callQueueMethodTotalSize;
}

代码示例来源:origin: loklak/loklak_server

boolean fetchAllClasses = call.get("all", false);
if (fetchAllClasses) {
  List<String> allClasses = classInformation.getOrDefault(classifier, new ArrayList<>());
  classes = allClasses.toArray(new String[classes.length]);

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String getOrDefault(Object key, String defaultValue) {
  return super.getOrDefault(key, defaultValue);
}

代码示例来源:origin: com.typesafe.play/play_2.11

/**
 * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String getOrDefault(Object key, String defaultValue) {
  return super.getOrDefault(key, defaultValue);
}

代码示例来源:origin: com.typesafe.play/play

/**
 * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String getOrDefault(Object key, String defaultValue) {
  return super.getOrDefault(key, defaultValue);
}

代码示例来源:origin: com.typesafe.play/play_2.11

/**
 * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String getOrDefault(Object key, String defaultValue) {
  return super.getOrDefault(key, defaultValue);
}

代码示例来源:origin: com.typesafe.play/play

/**
 * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String getOrDefault(Object key, String defaultValue) {
  return super.getOrDefault(key, defaultValue);
}

代码示例来源:origin: magefree/mage

@Override
public void watch(GameEvent event, Game game) {
  if (event.getType() == EventType.BEGIN_COMBAT_STEP_PRE) {
    this.playersAttacked.clear();
  }
  else if (event.getType() == EventType.ATTACKER_DECLARED) {
    Set<UUID> attackedPlayers = this.playersAttacked.getOrDefault(event.getPlayerId(), new HashSet<>(1));
    attackedPlayers.add(event.getTargetId());
    this.playersAttacked.put(event.getPlayerId(), attackedPlayers);
  }
}

代码示例来源:origin: magefree/mage

@Override
public void watch(GameEvent event, Game game) {
  if (event.getType() == EventType.BEGIN_COMBAT_STEP_PRE) {
    this.playersAttacked.clear();
  } else if (event.getType() == EventType.ATTACKER_DECLARED) {
    Set<UUID> attackedPlayers = this.playersAttacked.getOrDefault(event.getPlayerId(), new HashSet<>(1));
    attackedPlayers.add(event.getTargetId());
    this.playersAttacked.put(event.getPlayerId(), attackedPlayers);
  }
}

相关文章