String instanceName = innerEntry.getKey();
ExceptionMessageWithStackTrace ex = innerEntry.getValue();
Map<String, ExceptionMessageWithStackTrace> instanceToExMap = failedValidations
- .get(moduleName);
- if (instanceToExMap == null) {
- instanceToExMap = new HashMap<>();
- failedValidations.put(moduleName, instanceToExMap);
- }
+ .computeIfAbsent(moduleName, k -> new HashMap<>());
if (instanceToExMap.containsKey(instanceName)) {
throw new IllegalArgumentException(
"Cannot merge with same module name "
package org.opendaylight.controller.config.facade.xml;
import com.google.common.base.Optional;
-import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import java.io.Closeable;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
}
private static Map<String, Map<Date, IdentityMapping>> transformIdentities(final Set<Module> modules) {
- Map<String, Map<Date, IdentityMapping>> mappedIds = Maps.newHashMap();
+ Map<String, Map<Date, IdentityMapping>> mappedIds = new HashMap<>();
for (Module module : modules) {
String namespace = module.getNamespace().toString();
- Map<Date, IdentityMapping> revisionsByNamespace = mappedIds.get(namespace);
- if (revisionsByNamespace == null) {
- revisionsByNamespace = Maps.newHashMap();
- mappedIds.put(namespace, revisionsByNamespace);
- }
+ Map<Date, IdentityMapping> revisionsByNamespace =
+ mappedIds.computeIfAbsent(namespace, k -> new HashMap<>());
Date revision = module.getRevision();
- IdentityMapping identityMapping = revisionsByNamespace.get(revision);
- if (identityMapping == null) {
- identityMapping = new IdentityMapping();
- revisionsByNamespace.put(revision, identityMapping);
- }
+ IdentityMapping identityMapping =
+ revisionsByNamespace.computeIfAbsent(revision, k -> new IdentityMapping());
for (IdentitySchemaNode identitySchemaNode : module.getIdentities()) {
identityMapping.addIdSchemaNode(identitySchemaNode);
final Map<String/* Namespace from yang file */,
Map<String /* Name of module entry from yang file */, ModuleMXBeanEntry>> mBeanEntries) {
- Map<String, Map<String, ModuleConfig>> namespaceToModuleNameToModuleConfig = Maps.newHashMap();
+ Map<String, Map<String, ModuleConfig>> namespaceToModuleNameToModuleConfig = new HashMap<>();
for (Map.Entry<String, Map<String, ModuleMXBeanEntry>> namespaceToModuleToMbe : mBeanEntries.entrySet()) {
for (Map.Entry<String, ModuleMXBeanEntry> moduleNameToMbe : namespaceToModuleToMbe.getValue().entrySet()) {
ModuleConfig moduleConfig = new ModuleConfig(moduleName,
new InstanceConfig(reader, moduleMXBeanEntry.getAttributes(), moduleMXBeanEntry.getNullableDummyContainerName()));
- Map<String, ModuleConfig> moduleNameToModuleConfig = namespaceToModuleNameToModuleConfig.get(namespaceToModuleToMbe.getKey());
- if (moduleNameToModuleConfig == null) {
- moduleNameToModuleConfig = Maps.newHashMap();
- namespaceToModuleNameToModuleConfig.put(namespaceToModuleToMbe.getKey(), moduleNameToModuleConfig);
- }
+ Map<String, ModuleConfig> moduleNameToModuleConfig =
+ namespaceToModuleNameToModuleConfig.computeIfAbsent(namespaceToModuleToMbe.getKey(),
+ k -> new HashMap<>());
moduleNameToModuleConfig.put(moduleName, moduleConfig);
}
private Map<String, Map<String, ModuleRuntime>> createModuleRuntimes(final ConfigRegistryClient configRegistryClient,
final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries) {
- Map<String, Map<String, ModuleRuntime>> retVal = Maps.newHashMap();
+ Map<String, Map<String, ModuleRuntime>> retVal = new HashMap<>();
for (Map.Entry<String, Map<String, ModuleMXBeanEntry>> namespaceToModuleEntry : mBeanEntries.entrySet()) {
- Map<String, ModuleRuntime> innerMap = Maps.newHashMap();
+ Map<String, ModuleRuntime> innerMap = new HashMap<>();
Map<String, ModuleMXBeanEntry> entriesFromNamespace = namespaceToModuleEntry.getValue();
for (Map.Entry<String, ModuleMXBeanEntry> moduleToMXEntry : entriesFromNamespace.entrySet()) {
ModuleMXBeanEntry mbe = moduleToMXEntry.getValue();
- Map<RuntimeBeanEntry, InstanceConfig> cache = Maps.newHashMap();
+ Map<RuntimeBeanEntry, InstanceConfig> cache = new HashMap<>();
RuntimeBeanEntry root = null;
for (RuntimeBeanEntry rbe : mbe.getRuntimeBeans()) {
cache.put(rbe, new InstanceConfig(configRegistryClient, rbe.getYangPropertiesToTypesMap(), mbe.getNullableDummyContainerName()));
}
private InstanceRuntime createInstanceRuntime(final RuntimeBeanEntry root, final Map<RuntimeBeanEntry, InstanceConfig> cache) {
- Map<String, InstanceRuntime> children = Maps.newHashMap();
+ Map<String, InstanceRuntime> children = new HashMap<>();
for (RuntimeBeanEntry child : root.getChildren()) {
children.put(child.getJavaNamePrefix(), createInstanceRuntime(child, cache));
}
}
private Map<String, String> createJmxToYangMap(final List<RuntimeBeanEntry> children) {
- Map<String, String> jmxToYangNamesForChildRbe = Maps.newHashMap();
+ Map<String, String> jmxToYangNamesForChildRbe = new HashMap<>();
for (RuntimeBeanEntry rbe : children) {
jmxToYangNamesForChildRbe.put(rbe.getJavaNamePrefix(), rbe.getYangName());
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import javax.management.ObjectName;
import javax.management.openmbean.OpenType;
public Rpcs mapRpcs() {
- final Map<String, Map<String, ModuleRpcs>> map = Maps.newHashMap();
+ final Map<String, Map<String, ModuleRpcs>> map = new HashMap<>();
for (final Map.Entry<String, Map<String, ModuleMXBeanEntry>> namespaceToModuleEntry : yangStoreService.getModuleMXBeanEntryMap().entrySet()) {
- Map<String, ModuleRpcs> namespaceToModules = map.get(namespaceToModuleEntry.getKey());
- if (namespaceToModules == null) {
- namespaceToModules = Maps.newHashMap();
- map.put(namespaceToModuleEntry.getKey(), namespaceToModules);
- }
+ Map<String, ModuleRpcs> namespaceToModules =
+ map.computeIfAbsent(namespaceToModuleEntry.getKey(), k -> new HashMap<>());
for (final Map.Entry<String, ModuleMXBeanEntry> moduleEntry : namespaceToModuleEntry.getValue().entrySet()) {
- ModuleRpcs rpcMapping = namespaceToModules.get(moduleEntry.getKey());
- if (rpcMapping == null) {
- rpcMapping = new ModuleRpcs(yangStoreService.getEnumResolver());
- namespaceToModules.put(moduleEntry.getKey(), rpcMapping);
- }
+ ModuleRpcs rpcMapping = namespaceToModules.computeIfAbsent(moduleEntry.getKey(),
+ k -> new ModuleRpcs(yangStoreService.getEnumResolver()));
final ModuleMXBeanEntry entry = moduleEntry.getValue();
private Map<String, AttributeConfigElement> sortAttributes(
final Map<String, AttributeConfigElement> attributes, final XmlElement xml) {
- final Map<String, AttributeConfigElement> sorted = Maps.newLinkedHashMap();
+ final Map<String, AttributeConfigElement> sorted = new LinkedHashMap<>();
for (XmlElement xmlElement : xml.getChildElements()) {
final String name = xmlElement.getName();
ModuleConfig moduleMapping = getModuleMapping(moduleNamespace, instanceName, factoryName);
- Multimap<String, T> innerMap = retVal.get(moduleNamespace);
- if (innerMap == null) {
- innerMap = HashMultimap.create();
- retVal.put(moduleNamespace, innerMap);
- }
+ Multimap<String, T> innerMap = retVal.computeIfAbsent(moduleNamespace, k -> HashMultimap.create());
T resolvedElement = resolvingStrategy.resolveElement(moduleMapping, moduleElement, serviceTracker,
instanceName, moduleNamespace, defaultStrategy);
package org.opendaylight.controller.config.facade.xml.mapping.config;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import java.util.HashMap;
import java.util.Map;
import javax.management.InstanceNotFoundException;
import javax.management.ObjectName;
}
public Map<String, Map<String, Map<String, String>>> getMappedServices() {
- Map<String, Map<String, Map<String, String>>> retVal = Maps.newHashMap();
+ Map<String, Map<String, Map<String, String>>> retVal = new HashMap<>();
Map<String, Map<String, ObjectName>> serviceMapping = configServiceRefRegistry.getServiceMapping();
for (Map.Entry<String, Map<String, ObjectName>> qNameToRefNameEntry : serviceMapping.entrySet()){
QName qname = QName.create(qNameToRefNameEntry.getKey());
String namespace = qname.getNamespace().toString();
- Map<String, Map<String, String>> serviceToRefs = retVal.get(namespace);
- if(serviceToRefs==null) {
- serviceToRefs = Maps.newHashMap();
- retVal.put(namespace, serviceToRefs);
- }
+ Map<String, Map<String, String>> serviceToRefs =
+ retVal.computeIfAbsent(namespace, k -> new HashMap<>());
String localName = qname.getLocalName();
- Map<String, String> refsToSis = serviceToRefs.get(localName);
- if(refsToSis==null) {
- refsToSis = Maps.newHashMap();
- serviceToRefs.put(localName, refsToSis);
- }
+ Map<String, String> refsToSis = serviceToRefs.computeIfAbsent(localName, k -> new HashMap<>());
Preconditions.checkState(!refsToSis.containsKey(refName),
"Duplicate reference name %s for service %s:%s, now for instance %s", refName, namespace,
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public static final String TYPE_KEY = "type";
public static final String SERVICE_KEY = "service";
- private final Map<String /*Namespace*/, Map<String/* ServiceName */, Map<String/* refName */, ServiceInstance>>> namespaceToServiceNameToRefNameToInstance = Maps
- .newHashMap();
+ private final Map<String /*Namespace*/, Map<String/* ServiceName */, Map<String/* refName */, ServiceInstance>>>
+ namespaceToServiceNameToRefNameToInstance = new HashMap<>();
/**
*
String serviceName = serviceEntry.getKey();
for (Entry<String, String> refEntry : serviceEntry.getValue().entrySet()) {
- Map<String, Map<String, ServiceInstance>> namespaceToServices = tracker.namespaceToServiceNameToRefNameToInstance.get(namespace);
- if (namespaceToServices == null) {
- namespaceToServices = Maps.newHashMap();
- tracker.namespaceToServiceNameToRefNameToInstance.put(namespace, namespaceToServices);
- }
+ Map<String, Map<String, ServiceInstance>> namespaceToServices =
+ tracker.namespaceToServiceNameToRefNameToInstance.computeIfAbsent(namespace,
+ k -> new HashMap<>());
Map<String, ServiceInstance> refNameToInstance = namespaceToServices
- .get(serviceName);
- if (refNameToInstance == null) {
- refNameToInstance = Maps.newHashMap();
- namespaceToServices.put(serviceName, refNameToInstance);
- }
+ .computeIfAbsent(serviceName, k -> new HashMap<>());
String refName = refEntry.getKey();
//we want to compare reference not value of the provider
// TODO support edit strategies on services
public static Services fromXml(final XmlElement xml) throws DocumentedException {
- Map<String, Map<String, Map<String, String>>> retVal = Maps.newHashMap();
+ Map<String, Map<String, Map<String, String>>> retVal = new HashMap<>();
List<XmlElement> services = xml.getChildElements(SERVICE_KEY);
xml.checkUnrecognisedElements(services);
Preconditions.checkState(prefixNamespace.getKey()!=null && !prefixNamespace.getKey().equals(""), "Type attribute was not prefixed");
- Map<String, Map<String, String>> namespaceToServices = retVal.get(prefixNamespace.getValue());
- if(namespaceToServices == null) {
- namespaceToServices = Maps.newHashMap();
- retVal.put(prefixNamespace.getValue(), namespaceToServices);
- }
+ Map<String, Map<String, String>> namespaceToServices =
+ retVal.computeIfAbsent(prefixNamespace.getValue(), k -> new HashMap<>());
String serviceName = ObjectNameAttributeReadingStrategy
.checkPrefixAndExtractServiceName(typeElement, prefixNamespace);
- Map<String, String> innerMap = namespaceToServices.get(serviceName);
- if (innerMap == null) {
- innerMap = Maps.newHashMap();
- namespaceToServices.put(serviceName, innerMap);
- }
+ Map<String, String> innerMap = namespaceToServices.computeIfAbsent(serviceName, k -> new HashMap<>());
List<XmlElement> instances = service.getChildElements(XmlMappingConstants.INSTANCE_KEY);
service.checkUnrecognisedElements(instances, typeElement);
package org.opendaylight.controller.config.facade.xml.rpc;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import java.util.HashMap;
import java.util.Map;
import org.opendaylight.controller.config.facade.xml.osgi.EnumResolver;
import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
public final class ModuleRpcs {
- private final Map<String, String> yangToJavaNames = Maps.newHashMap();
- private final Map<String, Map<String, InstanceRuntimeRpc>> rpcMapping = Maps.newHashMap();
+ private final Map<String, String> yangToJavaNames = new HashMap<>();
+ private final Map<String, Map<String, InstanceRuntimeRpc>> rpcMapping = new HashMap<>();
private final EnumResolver enumResolver;
public ModuleRpcs(final EnumResolver enumResolver) {
public void addRpc(RuntimeBeanEntry runtimeEntry, Rpc rpc) {
String yangName = runtimeEntry.getYangName();
- Map<String, InstanceRuntimeRpc> map = rpcMapping.get(yangName);
- if (map == null) {
- map = Maps.newHashMap();
- rpcMapping.put(yangName, map);
- }
+ Map<String, InstanceRuntimeRpc> map = rpcMapping.computeIfAbsent(yangName, k -> new HashMap<>());
Preconditions.checkState(!map.containsKey(rpc.getYangName()), "Rpc %s for runtime bean %s added twice",
rpc.getYangName(), yangName);
for (ObjectName objectName : instancesToMap) {
String moduleName = ObjectNameUtil.getFactoryName(objectName);
- Multimap<String, ObjectName> multimap = retVal.get(moduleName);
- if (multimap == null) {
- multimap = HashMultimap.create();
- retVal.put(moduleName, multimap);
- }
+ Multimap<String, ObjectName> multimap = retVal.computeIfAbsent(moduleName, k -> HashMultimap.create());
String instanceName = ObjectNameUtil.getInstanceName(objectName);
Map<String /* namespace */, Map<String /* localName */, ServiceInterfaceAnnotation>> modifiableNamespacesToAnnotations = new HashMap<>();
Map<String /* service qName*/, ServiceInterfaceAnnotation> modifiableServiceQNamesToAnnotations = new HashMap<>();
for (ServiceInterfaceAnnotation sia : allAnnotations) {
- Map<String, ServiceInterfaceAnnotation> ofNamespace = modifiableNamespacesToAnnotations.get(sia.namespace());
- if (ofNamespace == null) {
- ofNamespace = new HashMap<>();
- modifiableNamespacesToAnnotations.put(sia.namespace(), ofNamespace);
- }
+ Map<String, ServiceInterfaceAnnotation> ofNamespace =
+ modifiableNamespacesToAnnotations.computeIfAbsent(sia.namespace(), k -> new HashMap<>());
if (ofNamespace.containsKey(sia.localName())) {
LOG.error(
"Cannot construct namespacesToAnnotations map, conflict between local names in {}, offending local name: {}, map so far {}",
Map<String /* serviceInterfaceName */, Map<String/* refName */, ObjectName>> result = new HashMap<>();
for (Entry<ServiceReference, ModuleIdentifier> entry: refNames.entrySet()) {
String qName = entry.getKey().getServiceInterfaceQName();
- Map<String /* refName */, ObjectName> innerMap = result.get(qName);
- if (innerMap == null) {
- innerMap = new HashMap<>();
- result.put(qName, innerMap);
- }
+ Map<String /* refName */, ObjectName> innerMap = result.computeIfAbsent(qName, k -> new HashMap<>());
innerMap.put(entry.getKey().getRefName(), getObjectName(entry.getValue()));
}
return result;
}
// save to refNames
refNames.put(serviceReference, moduleIdentifier);
- Map<ServiceInterfaceAnnotation, String /* service ref name */> refNamesToAnnotations = modulesToServiceRef.get(moduleIdentifier);
- if (refNamesToAnnotations == null){
- refNamesToAnnotations = new HashMap<>();
- modulesToServiceRef.put(moduleIdentifier, refNamesToAnnotations);
- }
+ Map<ServiceInterfaceAnnotation, String /* service ref name */> refNamesToAnnotations =
+ modulesToServiceRef.computeIfAbsent(moduleIdentifier, k -> new HashMap<>());
ServiceInterfaceAnnotation annotation = serviceQNamesToAnnotations.get(serviceReference.getServiceInterfaceQName());
Preconditions.checkNotNull(annotation, "Possible error in code, cannot find annotation for " + serviceReference);
import akka.persistence.PersistentImpl;
import akka.persistence.PersistentRepr;
import akka.persistence.journal.japi.AsyncWriteJournal;
-import com.google.common.collect.Maps;
import com.google.common.util.concurrent.Uninterruptibles;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
}
public static void addEntry(String persistenceId, long sequenceNr, Object data) {
- Map<Long, Object> journal = JOURNALS.get(persistenceId);
- if (journal == null) {
- journal = Maps.newLinkedHashMap();
- JOURNALS.put(persistenceId, journal);
- }
+ Map<Long, Object> journal = JOURNALS.computeIfAbsent(persistenceId, k -> new LinkedHashMap<>());
synchronized (journal) {
journal.put(sequenceNr, data instanceof Serializable
private static Map<String, List<StoredSnapshot>> snapshots = new ConcurrentHashMap<>();
public static void addSnapshot(String persistentId, Object snapshot) {
- List<StoredSnapshot> snapshotList = snapshots.get(persistentId);
-
- if (snapshotList == null) {
- snapshotList = new ArrayList<>();
- snapshots.put(persistentId, snapshotList);
- }
+ List<StoredSnapshot> snapshotList = snapshots.computeIfAbsent(persistentId, k -> new ArrayList<>());
synchronized (snapshotList) {
snapshotList.add(new StoredSnapshot(new SnapshotMetadata(persistentId, snapshotList.size(),
ConfigObjectWrapper wrapper = new ConfigObjectWrapper(o);
String moduleName = wrapper.stringValue("name");
- ModuleConfig.Builder builder = moduleConfigMap.get(moduleName);
- if (builder == null) {
- builder = ModuleConfig.builder(moduleName);
- moduleConfigMap.put(moduleName, builder);
- }
+ ModuleConfig.Builder builder = moduleConfigMap.computeIfAbsent(moduleName, ModuleConfig::builder);
builder.nameSpace(wrapper.stringValue("namespace"));
builder.shardStrategy(ShardStrategyFactory.newShardStrategyInstance(moduleName,
package org.opendaylight.controller.cluster.datastore.utils;
-import java.util.Map;
import org.opendaylight.controller.cluster.access.concepts.MemberName;
import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
builder.append(p.getNodeType().getLocalName());
if (p instanceof NodeIdentifierWithPredicates) {
builder.append("-key_");
- final Map<QName, Object> key = ((NodeIdentifierWithPredicates) p).getKeyValues();
- key.entrySet().forEach(e -> {
- builder.append(e.getKey().getLocalName());
- builder.append(e.getValue());
+ ((NodeIdentifierWithPredicates) p).getKeyValues().forEach((key, value) -> {
+ builder.append(key.getLocalName());
+ builder.append(value);
builder.append("-");
});
builder.append("_");
continue;
}
- SubshardProducerSpecification spec = affectedSubshards.get(maybeAffected.getPrefix());
- if (spec == null) {
- spec = new SubshardProducerSpecification(maybeAffected);
- affectedSubshards.put(maybeAffected.getPrefix(), spec);
- }
+ SubshardProducerSpecification spec = affectedSubshards.computeIfAbsent(maybeAffected.getPrefix(),
+ k -> new SubshardProducerSpecification(maybeAffected));
spec.addPrefix(bindPath);
}
}
@GuardedBy("this")
private void storeShard(final DOMDataTreeIdentifier prefix, final ShardRegistration<?> reg) {
- ShardingTableEntry t = shardingTables.get(prefix.getDatastoreType());
- if (t == null) {
- t = new ShardingTableEntry();
- shardingTables.put(prefix.getDatastoreType(), t);
- }
+ ShardingTableEntry t = shardingTables.computeIfAbsent(prefix.getDatastoreType(), k -> new ShardingTableEntry());
t.store(prefix.getRootIdentifier(), reg);
}
while (it.hasNext()) {
final PathArgument a = it.next();
- ShardingTableEntry child = entry.children.get(a);
- if (child == null) {
- child = new ShardingTableEntry(a);
- entry.children.put(a, child);
- }
+ ShardingTableEntry child = entry.children.computeIfAbsent(a, ShardingTableEntry::new);
}
Preconditions.checkState(entry.registration == null);