/** * Update the exposed {@link #cacheNames} set with the given name. * <p>This will always be called within a full {@link #cacheMap} lock * and effectively behaves like a {@code CopyOnWriteArraySet} with * preserved order but exposed as an unmodifiable reference. * @param name the name of the cache to be added */ private void updateCacheNames(String name) { Set<String> cacheNames = new LinkedHashSet<>(this.cacheNames.size() + 1); cacheNames.addAll(this.cacheNames); cacheNames.add(name); this.cacheNames = Collections.unmodifiableSet(cacheNames); }
private void handleDependencyMaterial(Set<String> scmMaterialSet, DependencyMaterialConfig depMaterial, DependencyFanInNode node, Set<DependencyMaterialConfig> visitedNodes) { if (visitedNodes.contains(depMaterial)) { scmMaterialSet.addAll(dependencyMaterialFingerprintMap.get(depMaterial)); return; } visitedNodes.add(depMaterial); final Set<String> scmMaterialFingerprintSet = new HashSet<>(); buildRestOfTheGraph(node, cruiseConfig.pipelineConfigByName(depMaterial.getPipelineName()), scmMaterialFingerprintSet, visitedNodes); dependencyMaterialFingerprintMap.put(depMaterial, scmMaterialFingerprintSet); scmMaterialSet.addAll(scmMaterialFingerprintSet); }
public void addSeedWords(String label, Collection<CandidatePhrase> seeds) throws Exception { if(!seedLabelDictionary.containsKey(label)){ throw new Exception("label not present in the model"); } Set<CandidatePhrase> seedWords = new HashSet<>(seedLabelDictionary.get(label)); seedWords.addAll(seeds); seedLabelDictionary.put(label, Collections.unmodifiableSet(seedWords)); }
Set<Integer> numbers = new TreeSet<Integer>(); numbers.add(2); numbers.add(5); System.out.println(numbers); // "[2, 5]" System.out.println(numbers.contains(7)); // "false" System.out.println(numbers.add(5)); // "false" System.out.println(numbers.size()); // "2" int sum = 0; for (int n : numbers) { sum += n; } System.out.println("Sum = " + sum); // "Sum = 7" numbers.addAll(Arrays.asList(1,2,3,4,5)); System.out.println(numbers); // "[1, 2, 3, 4, 5]" numbers.removeAll(Arrays.asList(4,5,6,7)); System.out.println(numbers); // "[1, 2, 3]" numbers.retainAll(Arrays.asList(2,3,4,5)); System.out.println(numbers); // "[2, 3]"
if (!cl.ner().equals(ne)) continue; neStrings.add(m.lowercaseNormalizedSpanString()); Map<Integer, Set<Mention>> headPositions = Generics.newHashMap(); for (Mention p : predicts) { if (!headPositions.containsKey(p.headIndex)) headPositions.put(p.headIndex, Generics.newHashSet()); headPositions.get(p.headIndex).add(p); for (int hPos : headPositions.keySet()) { Set<Mention> shares = headPositions.get(hPos); if (shares.size() > 1) { Counter<Mention> probs = new ClassicCounter<>(); for (Mention p : shares) { remove.addAll(probs.keySet());
/** * add allowed functions per column * @param columnName * @param udfs */ public void addComparisonOp(String columnName, String... udfs) { Set<String> allowed = columnToUDFs.get(columnName); if (allowed == null || allowed == udfNames) { // override columnToUDFs.put(columnName, new HashSet<String>(Arrays.asList(udfs))); } else { allowed.addAll(Arrays.asList(udfs)); } }
String attrName = (String) attrNames.nextElement(); if (this.cleanupAfterInclude || attrName.startsWith(DEFAULT_STRATEGIES_PREFIX)) { attrsToCheck.add(attrName); attrsToCheck.addAll((Set<String>) attributesSnapshot.keySet()); Object attrValue = attributesSnapshot.get(attrName); if (attrValue == null){ request.removeAttribute(attrName);
public static <K,R,S,T> Map<K, R> zipWith(Function2<R,S,T> fn, Map<K, S> m1, Map<K, T> m2, Map<K, R> results){ Set<K> keySet = new HashSet<K>(); keySet.addAll(m1.keySet()); keySet.addAll(m2.keySet()); results.clear(); for (K key : keySet) { results.put(key, fn.eval(m1.get(key), m2.get(key))); } return results; }
private Set<AsyncLoadBalanceClient> registerClients(final NodeIdentifier nodeId) { final Set<AsyncLoadBalanceClient> clients = new HashSet<>(); for (int i=0; i < clientsPerNode; i++) { final AsyncLoadBalanceClient client = clientFactory.createClient(nodeId); clients.add(client); logger.debug("Added client {} for communicating with Node {}", client, nodeId); } clientMap.put(nodeId, clients); allClients.addAll(clients); if (running) { clients.forEach(AsyncLoadBalanceClient::start); } return clients; }
private synchronized NameValueMap getCachedAttributes(ObjectName objName, Set<String> attrNames) throws InstanceNotFoundException, ReflectionException, IOException { NameValueMap values = cachedValues.get(objName); if (values != null && values.keySet().containsAll(attrNames)) { return values; } attrNames = new TreeSet<String>(attrNames); Set<String> oldNames = cachedNames.get(objName); if (oldNames != null) { attrNames.addAll(oldNames); } values = new NameValueMap(); final AttributeList attrs = conn.getAttributes(objName, attrNames.toArray(new String[attrNames.size()])); for (Attribute attr : attrs.asList()) { values.put(attr.getName(), attr.getValue()); } cachedValues.put(objName, values); cachedNames.put(objName, attrNames); return values; }
private Set<String> getPackagesToScan(AnnotationMetadata metadata) { AnnotationAttributes attributes = AnnotationAttributes.fromMap( metadata.getAnnotationAttributes(CompatibleDubboComponentScan.class.getName())); String[] basePackages = attributes.getStringArray("basePackages"); Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses"); String[] value = attributes.getStringArray("value"); // Appends value array attributes Set<String> packagesToScan = new LinkedHashSet<String>(Arrays.asList(value)); packagesToScan.addAll(Arrays.asList(basePackages)); for (Class<?> basePackageClass : basePackageClasses) { packagesToScan.add(ClassUtils.getPackageName(basePackageClass)); } if (packagesToScan.isEmpty()) { return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName())); } return packagesToScan; }
/** * Validate that the specified bean name and aliases have not been used already * within the current level of beans element nesting. */ protected void checkNameUniqueness(String beanName, List<String> aliases, Element beanElement) { String foundName = null; if (StringUtils.hasText(beanName) && this.usedNames.contains(beanName)) { foundName = beanName; } if (foundName == null) { foundName = CollectionUtils.findFirstMatch(this.usedNames, aliases); } if (foundName != null) { error("Bean name '" + foundName + "' is already used in this <beans> element", beanElement); } this.usedNames.add(beanName); this.usedNames.addAll(aliases); }
public static Map<GlobalStreamId, Grouping> eventLoggerInputs(StormTopology topology) { Map<GlobalStreamId, Grouping> inputs = new HashMap<GlobalStreamId, Grouping>(); Set<String> allIds = new HashSet<String>(); allIds.addAll(topology.get_bolts().keySet()); allIds.addAll(topology.get_spouts().keySet()); for (String id : allIds) { inputs.put(Utils.getGlobalStreamId(id, EVENTLOGGER_STREAM_ID), Thrift.prepareFieldsGrouping(Arrays.asList("component-id"))); } return inputs; }
private Set<EventHandlerInfo> selectEventHandlers(Class<? extends Event> eventType, EntityRef entity) { Set<EventHandlerInfo> result = Sets.newHashSet(); result.addAll(generalHandlers.get(eventType)); SetMultimap<Class<? extends Component>, EventHandlerInfo> handlers = componentSpecificHandlers.get(eventType); if (handlers == null) { return result; } for (Class<? extends Component> compClass : handlers.keySet()) { if (entity.hasComponent(compClass)) { for (EventHandlerInfo eventHandler : handlers.get(compClass)) { if (eventHandler.isValidFor(entity)) { result.add(eventHandler); } } } } return result; }
/** The format of the demonyms file is * countryCityOrState ( TAB demonym )* * Lines starting with # are ignored * The file is cased but stored in in-memory data structures uncased. * The results are: * demonyms is a has from each country (etc.) to a set of demonymic Strings; * adjectiveNation is a set of demonymic Strings; * demonymSet has all country (etc.) names and all demonymic Strings. */ private void loadDemonymLists(String demonymFile) { try (BufferedReader reader = IOUtils.readerFromString(demonymFile)) { for (String line; (line = reader.readLine()) != null; ) { line = line.toLowerCase(Locale.ENGLISH); String[] tokens = line.split("\t"); if (tokens[0].startsWith("#")) continue; Set<String> set = Generics.newHashSet(); for (String s : tokens) { set.add(s); demonymSet.add(s); } demonyms.put(tokens[0], set); } adjectiveNation.addAll(demonymSet); adjectiveNation.removeAll(demonyms.keySet()); } catch (IOException e) { throw new RuntimeIOException(e); } }
public DestinationPatternsMessageCondition combine(DestinationPatternsMessageCondition other) { Set<String> result = new LinkedHashSet<>(); if (!this.patterns.isEmpty() && !other.patterns.isEmpty()) { for (String pattern1 : this.patterns) { for (String pattern2 : other.patterns) { result.add(this.pathMatcher.combine(pattern1, pattern2)); else if (!this.patterns.isEmpty()) { result.addAll(this.patterns); else if (!other.patterns.isEmpty()) { result.addAll(other.patterns); result.add("");
@Override TypeVariable<?> captureAsTypeVariable(Type[] upperBounds) { Set<Type> combined = new LinkedHashSet<>(asList(upperBounds)); // Since this is an artifically generated type variable, we don't bother checking // subtyping between declared type bound and actual type bound. So it's possible that we // may generate something like <capture#1-of ? extends Foo&SubFoo>. // Checking subtype between declared and actual type bounds // adds recursive isSubtypeOf() call and feels complicated. // There is no contract one way or another as long as isSubtypeOf() works as expected. combined.addAll(asList(typeParam.getBounds())); if (combined.size() > 1) { // Object is implicit and only useful if it's the only bound. combined.remove(Object.class); } return super.captureAsTypeVariable(combined.toArray(new Type[0])); } };