From: Robert Varga Date: Sat, 23 Oct 2021 18:37:47 +0000 (+0200) Subject: Make a few methods static X-Git-Tag: v2.0.6~34 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=8bcd8d38fe72849c2a34c9e7580ad1b3441c9cda;p=netconf.git Make a few methods static There is no point to use instance invocation, this makes things a tad easier on the eyes. Change-Id: I519b946607c1f998ee39bee13024b400ccc715a5 Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java index a7d9fa2429..313b71d704 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java @@ -105,7 +105,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C public ControllerContext(final DOMSchemaService schemaService, final DOMMountPointService mountService, final DOMSchemaService domSchemaService) { this.mountService = mountService; - this.yangTextSourceProvider = domSchemaService.getExtensions().getInstance(DOMYangTextSourceProvider.class); + yangTextSourceProvider = domSchemaService.getExtensions().getInstance(DOMYangTextSourceProvider.class); onModelContextUpdated(schemaService.getGlobalContext()); listenerRegistration = schemaService.registerSchemaContextListener(this); @@ -126,7 +126,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C private void setGlobalSchema(final EffectiveModelContext globalSchema) { this.globalSchema = globalSchema; - this.dataNormalizer = new DataNormalizer(globalSchema); + dataNormalizer = new DataNormalizer(globalSchema); } public DOMYangTextSourceProvider getYangTextSourceProvider() { @@ -134,7 +134,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C } private void checkPreconditions() { - if (this.globalSchema == null) { + if (globalSchema == null) { throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE); } } @@ -154,7 +154,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C } public EffectiveModelContext getGlobalSchema() { - return this.globalSchema; + return globalSchema; } public InstanceIdentifierContext toMountPointIdentifier(final String restconfInstance) { @@ -166,8 +166,8 @@ public final class ControllerContext implements EffectiveModelContextListener, C checkPreconditions(); if (restconfInstance == null) { - return new InstanceIdentifierContext<>(YangInstanceIdentifier.empty(), this.globalSchema, null, - this.globalSchema); + return new InstanceIdentifierContext<>(YangInstanceIdentifier.empty(), globalSchema, null, + globalSchema); } final List pathArgs = urlPathArgsDecode(SLASH_SPLITTER.split(restconfInstance)); @@ -184,7 +184,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C } final InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder(); - final Collection latestModule = this.globalSchema.findModules(startModule); + final Collection latestModule = globalSchema.findModules(startModule); if (latestModule.isEmpty()) { throw new RestconfDocumentedException("The module named '" + startModule + "' does not exist.", @@ -226,7 +226,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C public Module findModuleByName(final String moduleName) { checkPreconditions(); checkArgument(moduleName != null && !moduleName.isEmpty()); - return this.globalSchema.findModules(moduleName).stream().findFirst().orElse(null); + return globalSchema.findModules(moduleName).stream().findFirst().orElse(null); } public static Module findModuleByName(final DOMMountPoint mountPoint, final String moduleName) { @@ -240,7 +240,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C public Module findModuleByNamespace(final XMLNamespace namespace) { checkPreconditions(); checkArgument(namespace != null); - return this.globalSchema.findModules(namespace).stream().findFirst().orElse(null); + return globalSchema.findModules(namespace).stream().findFirst().orElse(null); } public static Module findModuleByNamespace(final DOMMountPoint mountPoint, final XMLNamespace namespace) { @@ -255,7 +255,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C checkPreconditions(); checkArgument(name != null && revision != null); - return this.globalSchema.findModule(name, revision).orElse(null); + return globalSchema.findModule(name, revision).orElse(null); } public Module findModuleByNameAndRevision(final DOMMountPoint mountPoint, final String name, @@ -273,7 +273,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C final Iterable elements = path.getPathArguments(); final PathArgument head = elements.iterator().next(); final QName startQName = head.getNodeType(); - final Module initialModule = this.globalSchema.findModule(startQName.getModule()).orElse(null); + final Module initialModule = globalSchema.findModule(startQName.getModule()).orElse(null); DataNodeContainer node = initialModule; for (final PathArgument element : elements) { final QName _nodeType = element.getNodeType(); @@ -298,7 +298,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C if (mount != null) { schemaContext = getModelContext(mount); } else { - schemaContext = this.globalSchema; + schemaContext = globalSchema; } final Module initialModule = schemaContext.findModule(startQName.getModule()).orElse(null); DataNodeContainer node = initialModule; @@ -326,8 +326,8 @@ public final class ControllerContext implements EffectiveModelContextListener, C return module == null ? null : module.getName(); } - public String findModuleNameByNamespace(final DOMMountPoint mountPoint, final XMLNamespace namespace) { - final Module module = this.findModuleByNamespace(mountPoint, namespace); + public static String findModuleNameByNamespace(final DOMMountPoint mountPoint, final XMLNamespace namespace) { + final Module module = findModuleByNamespace(mountPoint, namespace); return module == null ? null : module.getName(); } @@ -336,8 +336,8 @@ public final class ControllerContext implements EffectiveModelContextListener, C return module == null ? null : module.getNamespace(); } - public XMLNamespace findNamespaceByModuleName(final DOMMountPoint mountPoint, final String moduleName) { - final Module module = this.findModuleByName(mountPoint, moduleName); + public static XMLNamespace findNamespaceByModuleName(final DOMMountPoint mountPoint, final String moduleName) { + final Module module = findModuleByName(mountPoint, moduleName); return module == null ? null : module.getNamespace(); } @@ -350,7 +350,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C public Collection getAllModules() { checkPreconditions(); - return this.globalSchema.getModules(); + return globalSchema.getModules(); } private static String toRestconfIdentifier(final EffectiveModelContext context, final QName qname) { @@ -366,7 +366,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C public String toRestconfIdentifier(final QName qname) { checkPreconditions(); - return toRestconfIdentifier(this.globalSchema, qname); + return toRestconfIdentifier(globalSchema, qname); } public static String toRestconfIdentifier(final DOMMountPoint mountPoint, final QName qname) { @@ -535,7 +535,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C if (strings.isEmpty()) { return createContext(builder.build(), (DataSchemaNode) parentNode, mountPoint, - mountPoint != null ? getModelContext(mountPoint) : this.globalSchema); + mountPoint != null ? getModelContext(mountPoint) : globalSchema); } final String head = strings.iterator().next(); @@ -556,14 +556,14 @@ public final class ControllerContext implements EffectiveModelContextListener, C ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED); } - if (this.mountService == null) { + if (mountService == null) { throw new RestconfDocumentedException( "MountService was not found. Finding behind mount points does not work.", ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED); } - final YangInstanceIdentifier partialPath = this.dataNormalizer.toNormalized(builder.build()); - final Optional mountOpt = this.mountService.getMountPoint(partialPath); + final YangInstanceIdentifier partialPath = dataNormalizer.toNormalized(builder.build()); + final Optional mountOpt = mountService.getMountPoint(partialPath); if (mountOpt.isEmpty()) { LOG.debug("Instance identifier to missing mount point: {}", partialPath); throw new RestconfDocumentedException("Mount point does not exist.", ErrorType.PROTOCOL, @@ -604,7 +604,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C Module module = null; if (mountPoint == null) { checkPreconditions(); - module = this.globalSchema.findModules(moduleName).stream().findFirst().orElse(null); + module = globalSchema.findModules(moduleName).stream().findFirst().orElse(null); if (module == null) { throw new RestconfDocumentedException("\"" + moduleName + "\" module does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); @@ -634,7 +634,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C } if (rpc != null) { return new InstanceIdentifierContext<>(builder.build(), rpc, mountPoint, - mountPoint != null ? getModelContext(mountPoint) : this.globalSchema); + mountPoint != null ? getModelContext(mountPoint) : globalSchema); } } @@ -713,7 +713,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C } return createContext(builder.build(), targetNode, mountPoint, - mountPoint != null ? getModelContext(mountPoint) : this.globalSchema); + mountPoint != null ? getModelContext(mountPoint) : globalSchema); } private static InstanceIdentifierContext createContext(final YangInstanceIdentifier instance, @@ -850,13 +850,13 @@ public final class ControllerContext implements EffectiveModelContextListener, C } public RpcDefinition getRpcDefinition(final String name, final Optional revisionDate) { - final QName validName = toQName(this.globalSchema, name, revisionDate); - return validName == null ? null : this.qnameToRpc.get().get(validName); + final QName validName = toQName(globalSchema, name, revisionDate); + return validName == null ? null : qnameToRpc.get().get(validName); } public RpcDefinition getRpcDefinition(final String name) { - final QName validName = toQName(this.globalSchema, name); - return validName == null ? null : this.qnameToRpc.get().get(validName); + final QName validName = toQName(globalSchema, name); + return validName == null ? null : qnameToRpc.get().get(validName); } private static RpcDefinition getRpcDefinition(final Module module, final String rpcName) { @@ -880,7 +880,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C } // FIXME: still not completely atomic - this.qnameToRpc.set(ImmutableMap.copyOf(newMap)); + qnameToRpc.set(ImmutableMap.copyOf(newMap)); setGlobalSchema(context); } } @@ -957,7 +957,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) { try { - return this.dataNormalizer.toNormalized(legacy); + return dataNormalizer.toNormalized(legacy); } catch (final NullPointerException e) { throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e); } @@ -965,7 +965,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C public YangInstanceIdentifier toXpathRepresentation(final YangInstanceIdentifier instanceIdentifier) { try { - return this.dataNormalizer.toLegacy(instanceIdentifier); + return dataNormalizer.toLegacy(instanceIdentifier); } catch (final NullPointerException e) { throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e); } catch (final DataNormalizationException e) { @@ -976,7 +976,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C public boolean isNodeMixin(final YangInstanceIdentifier path) { final DataNormalizationOperation operation; try { - operation = this.dataNormalizer.getOperation(path); + operation = dataNormalizer.getOperation(path); } catch (final DataNormalizationException e) { throw new RestconfDocumentedException("Data normalizer failed. Normalization isn't possible", e); } diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestCodec.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestCodec.java index 0f9dfec67d..1947d03729 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestCodec.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestCodec.java @@ -73,16 +73,16 @@ public final class RestCodec { private ObjectCodec(final TypeDefinition typeDefinition, final DOMMountPoint mountPoint, final ControllerContext controllerContext) { this.controllerContext = controllerContext; - this.type = RestUtil.resolveBaseTypeFrom(typeDefinition); - if (this.type instanceof IdentityrefTypeDefinition) { - this.identityrefCodec = new IdentityrefCodecImpl(mountPoint, controllerContext); + type = RestUtil.resolveBaseTypeFrom(typeDefinition); + if (type instanceof IdentityrefTypeDefinition) { + identityrefCodec = new IdentityrefCodecImpl(mountPoint, controllerContext); } else { - this.identityrefCodec = null; + identityrefCodec = null; } - if (this.type instanceof InstanceIdentifierTypeDefinition) { - this.instanceIdentifier = new InstanceIdentifierCodecImpl(mountPoint, controllerContext); + if (type instanceof InstanceIdentifierTypeDefinition) { + instanceIdentifier = new InstanceIdentifierCodecImpl(mountPoint, controllerContext); } else { - this.instanceIdentifier = null; + instanceIdentifier = null; } } @@ -90,9 +90,9 @@ public final class RestCodec { @Override public Object deserialize(final Object input) { try { - if (this.type instanceof IdentityrefTypeDefinition) { + if (type instanceof IdentityrefTypeDefinition) { if (input instanceof IdentityValuesDTO) { - return this.identityrefCodec.deserialize(input); + return identityrefCodec.deserialize(input); } if (LOG.isDebugEnabled()) { LOG.debug( @@ -101,9 +101,9 @@ public final class RestCodec { input == null ? "null" : input.getClass(), String.valueOf(input)); } return null; - } else if (this.type instanceof InstanceIdentifierTypeDefinition) { + } else if (type instanceof InstanceIdentifierTypeDefinition) { if (input instanceof IdentityValuesDTO) { - return this.instanceIdentifier.deserialize(input); + return instanceIdentifier.deserialize(input); } else { final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec( controllerContext.getGlobalSchema()); @@ -111,7 +111,7 @@ public final class RestCodec { } } else { final TypeDefinitionAwareCodec> typeAwarecodec = - TypeDefinitionAwareCodec.from(this.type); + TypeDefinitionAwareCodec.from(type); if (typeAwarecodec != null) { if (input instanceof IdentityValuesDTO) { return typeAwarecodec.deserialize(((IdentityValuesDTO) input).getOriginValue()); @@ -132,15 +132,15 @@ public final class RestCodec { @Override public Object serialize(final Object input) { try { - if (this.type instanceof IdentityrefTypeDefinition) { - return this.identityrefCodec.serialize(input); - } else if (this.type instanceof LeafrefTypeDefinition) { + if (type instanceof IdentityrefTypeDefinition) { + return identityrefCodec.serialize(input); + } else if (type instanceof LeafrefTypeDefinition) { return LEAFREF_DEFAULT_CODEC.serialize(input); - } else if (this.type instanceof InstanceIdentifierTypeDefinition) { - return this.instanceIdentifier.serialize(input); + } else if (type instanceof InstanceIdentifierTypeDefinition) { + return instanceIdentifier.serialize(input); } else { final TypeDefinitionAwareCodec> typeAwarecodec = - TypeDefinitionAwareCodec.from(this.type); + TypeDefinitionAwareCodec.from(type); if (typeAwarecodec != null) { return typeAwarecodec.serialize(input); } else { @@ -176,7 +176,7 @@ public final class RestCodec { @Override public QName deserialize(final IdentityValuesDTO data) { final IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0); - final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), this.mountPoint, + final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint, controllerContext); if (module == null) { LOG.info("Module was not found for namespace {}", valueWithNamespace.getNamespace()); @@ -241,7 +241,7 @@ public final class RestCodec { public YangInstanceIdentifier deserialize(final IdentityValuesDTO data) { final List result = new ArrayList<>(); final IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0); - final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), this.mountPoint, + final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint, controllerContext); if (module == null) { LOG.info("Module by namespace '{}' of first node in instance-identifier was not found.", @@ -255,7 +255,7 @@ public final class RestCodec { final List identities = data.getValuesWithNamespaces(); for (int i = 0; i < identities.size(); i++) { final IdentityValue identityValue = identities.get(i); - XMLNamespace validNamespace = resolveValidNamespace(identityValue.getNamespace(), this.mountPoint, + XMLNamespace validNamespace = resolveValidNamespace(identityValue.getNamespace(), mountPoint, controllerContext); final DataSchemaNode node = ControllerContext.findInstanceDataChildByNameAndNamespace( parentContainer, identityValue.getValue(), validNamespace); @@ -283,7 +283,7 @@ public final class RestCodec { final DataNodeContainer listNode = (DataNodeContainer) node; final Map predicatesMap = new HashMap<>(); for (final Predicate predicate : identityValue.getPredicates()) { - validNamespace = resolveValidNamespace(predicate.getName().getNamespace(), this.mountPoint, + validNamespace = resolveValidNamespace(predicate.getName().getNamespace(), mountPoint, controllerContext); final DataSchemaNode listKey = ControllerContext .findInstanceDataChildByNameAndNamespace(listNode, predicate.getName().getValue(), @@ -341,7 +341,7 @@ public final class RestCodec { Module module = null; if (mountPoint != null) { - module = controllerContext.findModuleByNamespace(mountPoint, validNamespace); + module = ControllerContext.findModuleByNamespace(mountPoint, validNamespace); } else { module = controllerContext.findModuleByNamespace(validNamespace); } @@ -356,7 +356,7 @@ public final class RestCodec { final ControllerContext controllerContext) { XMLNamespace validNamespace; if (mountPoint != null) { - validNamespace = controllerContext.findNamespaceByModuleName(mountPoint, namespace); + validNamespace = ControllerContext.findNamespaceByModuleName(mountPoint, namespace); } else { validNamespace = controllerContext.findNamespaceByModuleName(namespace); }