Tabnine Logo
Map.getOrDefault
Code IndexAdd Tabnine to your IDE (free)

How to use
getOrDefault
method
in
java.util.Map

Best Java code snippets using java.util.Map.getOrDefault (Showing top 20 results out of 16,686)

Refine searchRefine arrow

  • Map.put
  • Map.get
  • Map.entrySet
  • Map.Entry.getValue
  • Map.Entry.getKey
  • List.add
origin: hs-web/hsweb-framework

protected ResponseConvertHandler getConvertHandler(String id, String provider) {
  ResponseConvertHandler convertHandler = convertHandlerMap.get("serverId:" + id);
  if (convertHandler == null) {
    convertHandler = convertHandlerMap.getOrDefault("provider:" + provider, defaultConvertHandler);
  }
  return convertHandler;
}
origin: square/javapoet

void add(T t) {
 int count = map.getOrDefault(t, 0);
 map.put(t, count + 1);
}
origin: prestodb/presto

private static int mergeMaps(Map<String, Integer> map, Map<String, Integer> other)
{
  int deltaSize = 0;
  for (Map.Entry<String, Integer> entry : other.entrySet()) {
    if (!map.containsKey(entry.getKey())) {
      deltaSize += entry.getKey().getBytes().length + SIZE_OF_INT;
    }
    map.put(entry.getKey(), map.getOrDefault(entry.getKey(), 0) + other.getOrDefault(entry.getKey(), 0));
  }
  return deltaSize;
}
origin: twosigma/beakerx

public void taskStart(int stageId, long taskId) {
 if (!stages.containsKey(stageId)) {
  logger.warning(String.format("Spark stage %d could not be found for task progress reporting.", stageId));
  return;
 }
 
 removeTask(stageId, taskId);
 List<Long> at = activeTasks.getOrDefault(stageId, new ArrayList<Long>());
 at.add(taskId);
 activeTasks.put(stageId, at);
}
origin: ctripcorp/apollo

Map<String, Long> latestNotifications = Maps.newHashMap();
for (ReleaseMessage releaseMessage : latestReleaseMessages) {
 latestNotifications.put(releaseMessage.getMessage(), releaseMessage.getId());
 long clientSideId = clientSideNotifications.get(namespace);
 long latestId = ConfigConsts.NOTIFICATION_ID_PLACEHOLDER;
 Collection<String> namespaceWatchedKeys = watchedKeysMap.get(namespace);
 for (String namespaceWatchedKey : namespaceWatchedKeys) {
  long namespaceNotificationId =
    latestNotifications.getOrDefault(namespaceWatchedKey, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER);
  if (namespaceNotificationId > latestId) {
   latestId = namespaceNotificationId;
  ApolloConfigNotification notification = new ApolloConfigNotification(namespace, latestId);
  namespaceWatchedKeys.stream().filter(latestNotifications::containsKey).forEach(namespaceWatchedKey ->
    notification.addMessage(namespaceWatchedKey, latestNotifications.get(namespaceWatchedKey)));
  newNotifications.add(notification);
origin: apache/storm

private Map<String, Double> mkSupervisorCapacities(Map<String, Object> conf) {
  Map<String, Double> ret = new HashMap<String, Double>();
  // Put in legacy values
  Double mem = ObjectReader.getDouble(conf.get(Config.SUPERVISOR_MEMORY_CAPACITY_MB), 4096.0);
  ret.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
  Double cpu = ObjectReader.getDouble(conf.get(Config.SUPERVISOR_CPU_CAPACITY), 400.0);
  ret.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
  // If configs are present in Generic map and legacy - the legacy values will be overwritten
  Map<String, Number> rawResourcesMap = (Map<String, Number>) conf.getOrDefault(
    Config.SUPERVISOR_RESOURCES_MAP, Collections.emptyMap()
  );
  for (Map.Entry<String, Number> stringNumberEntry : rawResourcesMap.entrySet()) {
    ret.put(stringNumberEntry.getKey(), stringNumberEntry.getValue().doubleValue());
  }
  return NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(ret);
}
origin: graphql-java/graphql-java

int increaseExpectedFetchCount(int level, int count) {
  expectedFetchCountPerLevel.put(level, expectedFetchCountPerLevel.getOrDefault(level, 0) + count);
  return expectedFetchCountPerLevel.get(level);
}
origin: apache/storm

@VisibleForTesting
void prepare(Cluster cluster) {
  this.cluster = cluster;
  nodes = new RAS_Nodes(cluster);
  networkTopography = cluster.getNetworkTopography();
  Map<String, String> hostToRack = new HashMap<>();
  for (Map.Entry<String, List<String>> entry : networkTopography.entrySet()) {
    String rackId = entry.getKey();
    for (String hostName: entry.getValue()) {
      hostToRack.put(hostName, rackId);
    }
  }
  for (RAS_Node node: nodes.getNodes()) {
    String superId = node.getId();
    String hostName = node.getHostname();
    String rackId = hostToRack.getOrDefault(hostName, DNSToSwitchMapping.DEFAULT_RACK);
    superIdToHostname.put(superId, hostName);
    superIdToRack.put(superId, rackId);
    hostnameToNodes.computeIfAbsent(hostName, (hn) -> new ArrayList<>()).add(node);
    rackIdToNodes.computeIfAbsent(rackId, (hn) -> new ArrayList<>()).add(node);
  }
  logClusterInfo();
}
origin: graphhopper/graphhopper

List<Transfer> getTransfersFromStop(String fromStopId, String fromRouteId) {
  final List<Transfer> allOutboundTransfers = transfersFromStop.getOrDefault(fromStopId, Collections.emptyList());
  final Map<String, List<Transfer>> byToStop = allOutboundTransfers.stream()
      .filter(t -> t.transfer_type == 0 || t.transfer_type == 2)
      .filter(t -> t.from_route_id == null || fromRouteId.equals(t.from_route_id))
      .collect(Collectors.groupingBy(t -> t.to_stop_id));
  final List<Transfer> result = new ArrayList<>();
  byToStop.forEach((toStop, transfers) -> {
    routesByStop.getOrDefault(toStop, Collections.emptySet()).forEach(toRouteId -> {
      final Transfer mostSpecificRule = findMostSpecificRule(transfers, fromRouteId, toRouteId);
      final Transfer myRule = new Transfer();
      myRule.to_route_id = toRouteId;
      myRule.from_route_id = fromRouteId;
      myRule.to_stop_id = mostSpecificRule.to_stop_id;
      myRule.from_stop_id = mostSpecificRule.from_stop_id;
      myRule.transfer_type = mostSpecificRule.transfer_type;
      myRule.min_transfer_time = mostSpecificRule.min_transfer_time;
      myRule.from_trip_id = mostSpecificRule.from_trip_id;
      myRule.to_trip_id = mostSpecificRule.to_trip_id;
      result.add(myRule);
    });
  });
  return result;
}
origin: apache/storm

public ColumnsFileReporter(String path, Map<String, String> query, Map<String, MetricExtractor> extractorsMap,
              String defaultPreceision) throws FileNotFoundException {
  super(path, query, extractorsMap);
  targetUnit = UNIT_MAP.get(query.getOrDefault("time", "MILLISECONDS").toUpperCase());
  if (targetUnit == null) {
    throw new IllegalArgumentException(query.get("time") + " is not a supported time unit");
    List<String> extractors = handleExtractorCleanup(Arrays.asList(query.get("columns").split("\\s*,\\s*")));
        extractors.add(extractor);
  String strPrecision = query.getOrDefault("precision", defaultPreceision);
  if (strPrecision == null) {
    precision = -1;
origin: apache/incubator-druid

private Map<String, Long> getDeltaValues(Map<String, Long> total, Map<String, Long> prev)
{
 return total.entrySet()
       .stream()
       .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue() - prev.getOrDefault(e.getKey(), 0L)));
}
origin: apache/storm

/**
 * Constructs a {@link DefaultStateSerializer} instance with the given list of classes registered in kryo.
 *
 * @param classesToRegister the classes to register.
 */
public DefaultStateSerializer(Map<String, Object> topoConf, TopologyContext context, List<Class<?>> classesToRegister) {
  this.context = context;
  this.topoConf = topoConf;
  registrations.addAll(classesToRegister.stream().map(Class::getName).collect(Collectors.toSet()));
  // other classes from config
  registrations.addAll((List<String>) topoConf.getOrDefault(Config.TOPOLOGY_STATE_KRYO_REGISTER, Collections.emptyList()));
  // defaults
  registrations.add(Optional.class.getName());
}
origin: testcontainers/testcontainers-java

/**
 * Attach an output consumer at container startup, enabling stdout and stderr to be followed, waited on, etc.
 * <p>
 * More than one consumer may be registered.
 *
 * @param serviceName the name of the service as set in the docker-compose.yml file
 * @param consumer consumer that output frames should be sent to
 * @return this instance, for chaining
 */
public SELF withLogConsumer(String serviceName, Consumer<OutputFrame> consumer) {
  String serviceInstanceName = getServiceInstanceName(serviceName);
  final List<Consumer<OutputFrame>> consumers = this.logConsumers.getOrDefault(serviceInstanceName, new ArrayList<>());
  consumers.add(consumer);
  this.logConsumers.putIfAbsent(serviceInstanceName, consumers);
  return self();
}
origin: prestodb/presto

  @Override
  public final RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint)
  {
    TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId();

    InMemoryRecordSet.Builder table = InMemoryRecordSet.builder(tableMetadata);
    Map<ConnectorId, Map<String, PropertyMetadata<?>>> connectorProperties = propertySupplier.get();
    for (Entry<String, ConnectorId> entry : new TreeMap<>(transactionManager.getCatalogNames(transactionId)).entrySet()) {
      String catalog = entry.getKey();
      Map<String, PropertyMetadata<?>> properties = new TreeMap<>(connectorProperties.getOrDefault(entry.getValue(), ImmutableMap.of()));
      for (PropertyMetadata<?> propertyMetadata : properties.values()) {
        table.addRow(
            catalog,
            propertyMetadata.getName(),
            firstNonNull(propertyMetadata.getDefaultValue(), "").toString(),
            propertyMetadata.getSqlType().toString(),
            propertyMetadata.getDescription());
      }
    }
    return table.build().cursor();
  }
}
origin: apache/storm

@Override
public void prepare(Map<String, Object> topoConf, TopologyContext context, OutputCollector collector) {
  List<String> registrations = (List<String>) topoConf.getOrDefault(Config.TOPOLOGY_STATE_KRYO_REGISTER, new ArrayList<>());
  registrations.add(ConcurrentLinkedQueue.class.getName());
  registrations.add(LinkedList.class.getName());
  registrations.add(AtomicInteger.class.getName());
  registrations.add(EventImpl.class.getName());
  registrations.add(WindowPartition.class.getName());
  registrations.add(DefaultEvictionContext.class.getName());
  topoConf.put(Config.TOPOLOGY_STATE_KRYO_REGISTER, registrations);
  prepare(topoConf, context, collector, getWindowState(topoConf, context), getPartitionState(topoConf, context),
      getWindowSystemState(topoConf, context));
}
origin: apache/storm

@SuppressWarnings("unchecked")
private static Map<String, Object> normalizeConf(Map<String, Object> conf, Map<String, Object> topoConf, StormTopology topology) {
  //ensure that serializations are same for all tasks no matter what's on
  // the supervisors. this also allows you to declare the serializations as a sequence
  List<Map<String, Object>> allConfs = new ArrayList<>();
  for (Object comp : StormCommon.allComponents(topology).values()) {
    allConfs.add(StormCommon.componentConf(comp));
  }
  Set<String> decorators = new HashSet<>();
  //Yes we are putting in a config that is not the same type we pulled out.
  Map<String, String> serializers = new HashMap<>();
  for (Map<String, Object> c : allConfs) {
    addToDecorators(decorators, (List<String>) c.get(Config.TOPOLOGY_KRYO_DECORATORS));
    addToSerializers(serializers, (List<Object>) c.get(Config.TOPOLOGY_KRYO_REGISTER));
  }
  addToDecorators(decorators, (List<String>) topoConf.getOrDefault(Config.TOPOLOGY_KRYO_DECORATORS,
                                   conf.get(Config.TOPOLOGY_KRYO_DECORATORS)));
  addToSerializers(serializers, (List<Object>) topoConf.getOrDefault(Config.TOPOLOGY_KRYO_REGISTER,
                                    conf.get(Config.TOPOLOGY_KRYO_REGISTER)));
  Map<String, Object> mergedConf = Utils.merge(conf, topoConf);
  Map<String, Object> ret = new HashMap<>(topoConf);
  ret.put(Config.TOPOLOGY_KRYO_REGISTER, serializers);
  ret.put(Config.TOPOLOGY_KRYO_DECORATORS, new ArrayList<>(decorators));
  ret.put(Config.TOPOLOGY_ACKER_EXECUTORS, mergedConf.get(Config.TOPOLOGY_ACKER_EXECUTORS));
  ret.put(Config.TOPOLOGY_EVENTLOGGER_EXECUTORS, mergedConf.get(Config.TOPOLOGY_EVENTLOGGER_EXECUTORS));
  ret.put(Config.TOPOLOGY_MAX_TASK_PARALLELISM, mergedConf.get(Config.TOPOLOGY_MAX_TASK_PARALLELISM));
  return ret;
}
origin: linkedin/cruise-control

private Set<Map<String, Object>> recentGoalViolations(boolean useDateFormat) {
 Map<Long, Anomaly> goalViolationsByTime = _recentAnomaliesByType.get(AnomalyType.GOAL_VIOLATION);
 Set<Map<String, Object>> recentAnomalies = new HashSet<>(_numCachedRecentAnomalyStates);
 for (Map.Entry<Long, Anomaly> entry: goalViolationsByTime.entrySet()) {
  GoalViolations goalViolations = (GoalViolations) entry.getValue();
  Map<Boolean, List<String>> violatedGoalsByFixability = goalViolations.violatedGoalsByFixability();
  Map<String, Object> anomalyDetails = new HashMap<>(3);
  anomalyDetails.put(useDateFormat ? DETECTION_DATE : DETECTION_MS,
    useDateFormat ? getDateFormat(entry.getKey()) : entry.getKey());
  anomalyDetails.put(FIXABLE_VIOLATED_GOALS, violatedGoalsByFixability.getOrDefault(true, Collections.emptyList()));
  anomalyDetails.put(UNFIXABLE_VIOLATED_GOALS, violatedGoalsByFixability.getOrDefault(false, Collections.emptyList()));
  recentAnomalies.add(anomalyDetails);
 }
 return recentAnomalies;
}
origin: hs-web/hsweb-framework

protected ResponseJudge getResponseJudge(String id, String provider) {
  ResponseJudge judge = judgeMap.get("serverId:" + id);
  if (judge == null) {
    judge = judgeMap.getOrDefault("provider:" + provider, defaultResponseJudge);
  }
  return judge;
}
origin: apache/storm

  /**
   * Chooses one of the incoming tasks and selects the one that has been selected the fewest times so far.
   */
  public Integer chooseTask(int[] assignedTasks) {
    Integer taskIdWithMinLoad = null;
    Long minTaskLoad = Long.MAX_VALUE;
    for (Integer currentTaskId : assignedTasks) {
      final Long currentTaskLoad = targetTaskStats.getOrDefault(currentTaskId, 0L);
      if (currentTaskLoad < minTaskLoad) {
        minTaskLoad = currentTaskLoad;
        taskIdWithMinLoad = currentTaskId;
      }
    }
    targetTaskStats.put(taskIdWithMinLoad, targetTaskStats.getOrDefault(taskIdWithMinLoad, 0L) + 1);
    return taskIdWithMinLoad;
  }
}
origin: apache/ignite

  /** {@inheritDoc} */
  @Override public Double apply(double[] estimations) {
    A.notEmpty(estimations, "estimations vector");

    Map<Double, Integer> cntrsByCls = new HashMap<>();

    for (Double predictedValue : estimations) {
      Integer cntrVal = cntrsByCls.getOrDefault(predictedValue, 0) + 1;
      cntrsByCls.put(predictedValue, cntrVal);
    }

    return cntrsByCls.entrySet().stream()
      .max(Comparator.comparing(Map.Entry::getValue))
      .get().getKey();
  }
}
java.utilMapgetOrDefault

Popular methods of Map

  • put
    Maps the specified key to the specified value.
  • get
  • entrySet
    Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes t
  • containsKey
    Returns whether this Map contains the specified key.
  • keySet
    Returns a set of the keys contained in this Map. The Set is backed by this Map so changes to one are
  • values
    Returns a Collection view of the values contained in this map. The collection is backed by the map,
  • remove
  • size
    Returns the number of mappings in this Map.
  • isEmpty
    Returns true if this map contains no key-value mappings.
  • clear
    Removes all elements from this Map, leaving it empty.
  • putAll
    Copies all of the mappings from the specified map to this map (optional operation). The effect of th
  • forEach
  • putAll,
  • forEach,
  • equals,
  • computeIfAbsent,
  • hashCode,
  • containsValue,
  • putIfAbsent,
  • compute,
  • merge

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • getResourceAsStream (ClassLoader)
  • findViewById (Activity)
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now