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

How to use
putIfAbsent
method
in
java.util.Map

Best Java code snippets using java.util.Map.putIfAbsent (Showing top 20 results out of 9,324)

Refine searchRefine arrow

  • Map.get
  • Map.put
origin: robolectric/robolectric

/** Add a profile to be returned by {@link #getProfiles(int)}.**/
public void addProfile(
  int userHandle, int profileUserHandle, String profileName, int profileFlags) {
 profiles.putIfAbsent(userHandle, new ArrayList<>());
 profiles.get(userHandle).add(new UserInfo(profileUserHandle, profileName, profileFlags));
}
origin: wildfly/wildfly

public static void addProtocol(short id, Class protocol) {
  if(id < MIN_CUSTOM_PROTOCOL_ID)
    throw new IllegalArgumentException("protocol ID (" + id + ") needs to be greater than or equal to " + MIN_CUSTOM_PROTOCOL_ID);
  if(protocol_ids.containsKey(protocol))
    alreadyInProtocolsMap(id, protocol.getName());
  protocol_ids.put(protocol, id);
  protocol_names.putIfAbsent(id, protocol);
}
origin: spring-projects/spring-framework

  throws MissingResourceException {
Map<String, Map<Locale, MessageFormat>> codeMap = this.cachedBundleMessageFormats.get(bundle);
Map<Locale, MessageFormat> localeMap = null;
if (codeMap != null) {
  localeMap = codeMap.get(code);
  if (localeMap != null) {
    MessageFormat result = localeMap.get(locale);
    if (result != null) {
      return result;
    codeMap = new ConcurrentHashMap<>();
    Map<String, Map<Locale, MessageFormat>> existing =
        this.cachedBundleMessageFormats.putIfAbsent(bundle, codeMap);
    if (existing != null) {
      codeMap = existing;
    Map<Locale, MessageFormat> existing = codeMap.putIfAbsent(code, localeMap);
    if (existing != null) {
      localeMap = existing;
  localeMap.put(locale, result);
  return result;
origin: apache/hbase

 RegionInfo currRegion = entry.getKey();
 if (rsGroupInfo.getTables().contains(currTable)) {
  assignments.putIfAbsent(currTable, new HashMap<>());
  assignments.get(currTable).putIfAbsent(currServer, new ArrayList<>());
  assignments.get(currTable).get(currServer).add(currRegion);
for(ServerName serverName: master.getServerManager().getOnlineServers().keySet()) {
 if(rsGroupInfo.getServers().contains(serverName.getAddress())) {
  serverMap.put(serverName, Collections.emptyList());
  result.put(tableName, new HashMap<>());
  result.get(tableName).putAll(serverMap);
  result.get(tableName).putAll(assignments.get(tableName));
origin: apache/incubator-druid

private Pair<Map<Interval, String>, Map<Interval, List<DataSegment>>> getMaxCreateDateAndBaseSegments(
  List<Pair<DataSegment, String>> snapshot
)
{
 Interval maxAllowedToBuildInterval = snapshot.parallelStream()
   .map(pair -> pair.lhs)
   .map(DataSegment::getInterval)
   .max(Comparators.intervalsByStartThenEnd())
   .get();
 Map<Interval, String> maxCreatedDate = new HashMap<>();
 Map<Interval, List<DataSegment>> segments = new HashMap<>();
 for (Pair<DataSegment, String> entry : snapshot) {
  DataSegment segment = entry.lhs;
  String createDate = entry.rhs;
  Interval interval = segment.getInterval();
  if (!hasEnoughLag(interval, maxAllowedToBuildInterval)) {
   continue;
  }
  maxCreatedDate.put(
    interval, 
    DateTimes.max(
      DateTimes.of(createDate), 
      DateTimes.of(maxCreatedDate.getOrDefault(interval, DateTimes.MIN.toString()))
    ).toString()
  );
  segments.putIfAbsent(interval, new ArrayList<>());
  segments.get(interval).add(segment);
 }
 return new Pair<>(maxCreatedDate, segments);
}
origin: jooby-project/jooby

@Override
public void render(final View view, final Renderer.Context ctx) throws Exception {
 String name = view.name() + suffix;
 Template template = template(name, ctx.charset());
 Map<String, Object> hash = new HashMap<>();
 hash.put("_vname", view.name());
 hash.put("_vpath", template.getName());
 hash.put("xss", xss);
 // Locale:
 Locale locale = (Locale) hash.getOrDefault("locale", ctx.locale());
 hash.putIfAbsent("locale", locale);
 // locals
 Map<String, Object> locals = ctx.locals();
 hash.putAll(locals);
 // model
 hash.putAll(view.model());
 TemplateModel model = new SimpleHash(hash, new FtlWrapper(freemarker.getObjectWrapper()));
 // TODO: remove string writer
 StringWriter writer = new StringWriter();
 // Locale:
 template.setLocale(locale);
 // output
 template.process(model, writer);
 ctx.type(MediaType.html)
   .send(writer.toString());
}
origin: jooby-project/jooby

@Override
public void render(final View view, final Renderer.Context ctx) throws Exception {
 String vname = view.name();
 TemplateSource source = handlebars.getLoader().sourceAt(vname);
 Template template = handlebars.compile(source);
 Map<String, Object> locals = ctx.locals();
 locals.putIfAbsent("_vname", vname);
 locals.putIfAbsent("_vpath", source.filename());
 // Locale:
 Locale locale = (Locale) locals.getOrDefault("locale", ctx.locale());
 locals.put("locale", locale);
 com.github.jknack.handlebars.Context context = com.github.jknack.handlebars.Context
   .newBuilder(view.model())
   // merge request locals (req+sessions locals)
   .combine(locals)
   .resolver(resolvers)
   .build();
 // rendering it
 ctx.type(MediaType.html)
   .send(template.apply(context));
}
origin: apache/incubator-druid

private Pair<Map<Interval, String>, Map<Interval, List<DataSegment>>> getVersionAndBaseSegments(
  List<DataSegment> snapshot
)
{
 Map<Interval, String> versions = new HashMap<>();
 Map<Interval, List<DataSegment>> segments = new HashMap<>();
 for (DataSegment segment : snapshot) {
  Interval interval = segment.getInterval();
  versions.put(interval, segment.getVersion());
  segments.putIfAbsent(interval, new ArrayList<>());
  segments.get(interval).add(segment);
 }
 return new Pair<>(versions, segments);
}

origin: spring-cloud-incubator/spring-cloud-alibaba

public ConsumerGroupInstrumentation getConsumerGroupInstrumentation(String group) {
  String key = Consumer.GROUP_PREFIX + group;
  consumerGroupsInstrumentations.putIfAbsent(key,
      new ConsumerGroupInstrumentation(metricRegistry, key));
  return consumerGroupsInstrumentations.get(key);
}
origin: prestodb/presto

private synchronized Map<String, ConnectorId> getCatalogNames()
{
  // todo if repeatable read, this must be recorded
  Map<String, ConnectorId> catalogNames = new HashMap<>();
  catalogByName.values().stream()
      .filter(Optional::isPresent)
      .map(Optional::get)
      .forEach(catalog -> catalogNames.put(catalog.getCatalogName(), catalog.getConnectorId()));
  catalogManager.getCatalogs().stream()
      .forEach(catalog -> catalogNames.putIfAbsent(catalog.getCatalogName(), catalog.getConnectorId()));
  return ImmutableMap.copyOf(catalogNames);
}
origin: languagetool-org/languagetool

/**
 * Associate a notation with a given unit.
 * @param pattern Regex for recognizing the unit. Word boundaries and numbers are added to this pattern by addUnit itself.
 * @param base Unit to associate with the pattern
 * @param symbol Suffix used for suggestion.
 * @param factor Convenience parameter for prefixes for metric units, unit is multiplied with this. Defaults to 1 if not used.
 * @param metric Register this notation for suggestion.
 */
protected void addUnit(String pattern, Unit base, String symbol, double factor, boolean metric) {
 Unit unit = base.multiply(factor);
 unitPatterns.put(Pattern.compile("\\b" + NUMBER_REGEX + "\\s*" + pattern + "\\b"), unit);
 unitSymbols.putIfAbsent(unit, new ArrayList<>());
 unitSymbols.get(unit).add(symbol);
 if (metric && !metricUnits.contains(unit)) {
  metricUnits.add(unit);
 }
}
origin: spring-cloud-incubator/spring-cloud-alibaba

public ProducerInstrumentation getProducerInstrumentation(String destination) {
  String key = Producer.PREFIX + destination;
  producerInstrumentations.putIfAbsent(key,
      new ProducerInstrumentation(metricRegistry, key));
  return producerInstrumentations.get(key);
}
origin: neo4j/neo4j

/**
 * Augment the existing config with new settings, ignoring any conflicting settings.
 *
 * @param setting settings to add and override
 * @throws InvalidSettingException when and invalid setting is found and {@link
 * GraphDatabaseSettings#strict_config_validation} is true.
 */
public void augmentDefaults( Setting<?> setting, String value ) throws InvalidSettingException
{
  overriddenDefaults.put( setting.name(), value );
  params.putIfAbsent( setting.name(), value );
}
origin: pmd/pmd

private Set<String> styleForDepth(int depth, boolean inlineHighlight) {
  if (depth < 0) {
    // that's the style when we're outside any node
    return Collections.emptySet();
  } else {
    // Caching reduces the number of sets used by this step of the overlaying routine to
    // only a few. The number is probably blowing up during the actual spans overlaying
    // in StyleContext#recomputePainting
    DEPTH_STYLE_CACHE.putIfAbsent(style, new HashMap<>());
    Map<Integer, Map<Boolean, Set<String>>> depthToStyle = DEPTH_STYLE_CACHE.get(style);
    depthToStyle.putIfAbsent(depth, new HashMap<>());
    Map<Boolean, Set<String>> isInlineToStyle = depthToStyle.get(depth);
    if (isInlineToStyle.containsKey(inlineHighlight)) {
      return isInlineToStyle.get(inlineHighlight);
    }
    Set<String> s = new HashSet<>(style);
    s.add("depth-" + depth);
    if (inlineHighlight) {
      // inline highlight can be used to add boxing around a node if it wouldn't be ugly
      s.add("inline-highlight");
    }
    isInlineToStyle.put(inlineHighlight, s);
    return s;
  }
}
origin: spring-cloud-incubator/spring-cloud-alibaba

public ConsumerInstrumentation getConsumerInstrumentation(String destination) {
  String key = Consumer.PREFIX + destination;
  consumeInstrumentations.putIfAbsent(key,
      new ConsumerInstrumentation(metricRegistry, key));
  return consumeInstrumentations.get(key);
}
origin: GlowstoneMC/Glowstone

@Override
public boolean addCustomEffect(PotionEffect potionEffect, boolean overwrite) {
  PotionEffectType type = potionEffect.getType();
  if (overwrite) {
    customEffects.put(type, potionEffect);
    return true;
  } else {
    return customEffects.putIfAbsent(type, potionEffect) == null;
  }
}
origin: spring-projects/spring-framework

Map<Locale, ResourceBundle> localeMap = this.cachedResourceBundles.get(basename);
if (localeMap != null) {
  ResourceBundle bundle = localeMap.get(locale);
  if (bundle != null) {
    return bundle;
  if (localeMap == null) {
    localeMap = new ConcurrentHashMap<>();
    Map<Locale, ResourceBundle> existing = this.cachedResourceBundles.putIfAbsent(basename, localeMap);
    if (existing != null) {
      localeMap = existing;
  localeMap.put(locale, bundle);
  return bundle;
origin: apache/ignite

/**
 * @param accMap Map to obtain accumulator from.
 * @param cacheId Cache id.
 * @param part Partition number.
 * @return Accumulator.
 */
private AtomicLong accumulator(Map<Integer, Map<Integer, AtomicLong>> accMap, int cacheId, int part) {
  Map<Integer, AtomicLong> cacheAccs = accMap.get(cacheId);
  if (cacheAccs == null) {
    Map<Integer, AtomicLong> cacheAccs0 =
      accMap.putIfAbsent(cacheId, cacheAccs = new ConcurrentHashMap<>());
    if (cacheAccs0 != null)
      cacheAccs = cacheAccs0;
  }
  AtomicLong acc = cacheAccs.get(part);
  if (acc == null) {
    AtomicLong accDelta0 = cacheAccs.putIfAbsent(part, acc = new AtomicLong());
    if (accDelta0 != null)
      acc = accDelta0;
  }
  return acc;
}
origin: GlowstoneMC/Glowstone

@Override
public boolean addCustomEffect(PotionEffect potionEffect, boolean overwrite) {
  PotionEffectType type = potionEffect.getType();
  if (overwrite) {
    customEffects.put(type, potionEffect);
    return true;
  } else {
    return customEffects.putIfAbsent(type, potionEffect) == null;
  }
}
origin: stanfordnlp/CoreNLP

Mention m = sortedMentions.get(i);
for (String word : getContentWords(m)) {
 wordToMentions.putIfAbsent(word, new ArrayList<>());
 wordToMentions.get(word).add(m);
 List<Mention> withStringMatch = wordToMentions.get(word);
 if (withStringMatch != null) {
  for (Mention match : withStringMatch) {
 mentionToCandidateAntecedents.put(m.mentionID, candidateAntecedents);
java.utilMapputIfAbsent

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,
  • getOrDefault,
  • containsValue,
  • 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 Vim plugins
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