/** 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)); }
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); }
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;
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));
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); }
@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()); }
@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)); }
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); }
public ConsumerGroupInstrumentation getConsumerGroupInstrumentation(String group) { String key = Consumer.GROUP_PREFIX + group; consumerGroupsInstrumentations.putIfAbsent(key, new ConsumerGroupInstrumentation(metricRegistry, key)); return consumerGroupsInstrumentations.get(key); }
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); }
/** * 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); } }
public ProducerInstrumentation getProducerInstrumentation(String destination) { String key = Producer.PREFIX + destination; producerInstrumentations.putIfAbsent(key, new ProducerInstrumentation(metricRegistry, key)); return producerInstrumentations.get(key); }
/** * 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 ); }
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; } }
public ConsumerInstrumentation getConsumerInstrumentation(String destination) { String key = Consumer.PREFIX + destination; consumeInstrumentations.putIfAbsent(key, new ConsumerInstrumentation(metricRegistry, key)); return consumeInstrumentations.get(key); }
@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; } }
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;
/** * @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; }
@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; } }
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);