Modernize yang-repo-{api,spi} 33/101333/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 29 May 2022 19:37:25 +0000 (21:37 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 29 May 2022 20:10:55 +0000 (22:10 +0200)
Use pattern matching on instanceof to simplify our code.

Change-Id: I1399f78a5b25558b6437434e1c316790cfc50e23
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaContextFactoryConfiguration.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinDomSchemaSource.java
yang/yang-repo-spi/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/PotentialSchemaSource.java

index 6b2fdae2d338ea6ca2e95952003407d9af99a52d..879da762f9bbd2aa6a2564d70139e515a5ecbf99 100644 (file)
@@ -83,16 +83,10 @@ public final class SchemaContextFactoryConfiguration implements Immutable {
 
     @Override
     public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof SchemaContextFactoryConfiguration)) {
-            return false;
-        }
-        final SchemaContextFactoryConfiguration other = (SchemaContextFactoryConfiguration) obj;
-        return filter.equals(other.filter) && statementParserMode.equals(other.statementParserMode)
-                && Objects.equals(supportedFeatures, other.supportedFeatures)
-                && Objects.equals(modulesDeviatedByModules, other.modulesDeviatedByModules);
+        return this == obj || obj instanceof SchemaContextFactoryConfiguration other && filter.equals(other.filter)
+            && statementParserMode.equals(other.statementParserMode)
+            && Objects.equals(supportedFeatures, other.supportedFeatures)
+            && Objects.equals(modulesDeviatedByModules, other.modulesDeviatedByModules);
     }
 
     @Override
index bac0786482f3424be89ad591ac487e1b7d7f37b9..67a69c2bef9170a71fb6d55daa01c4688e2117bf 100644 (file)
@@ -161,16 +161,14 @@ public abstract class YinDomSchemaSource implements YinXmlSchemaSource {
     }
 
     private static @Nullable YinDomSchemaSource castSchemaSource(final YinXmlSchemaSource xmlSchemaSource) {
-        if (xmlSchemaSource instanceof YinDomSchemaSource) {
-            return (YinDomSchemaSource) xmlSchemaSource;
+        if (xmlSchemaSource instanceof YinDomSchemaSource yinDom) {
+            return yinDom;
         }
 
         final Source source = xmlSchemaSource.getSource();
-        if (source instanceof DOMSource) {
-            return create(xmlSchemaSource.getIdentifier(), (DOMSource) source,
-                xmlSchemaSource.getSymbolicName().orElse(null));
+        if (source instanceof DOMSource dom) {
+            return create(xmlSchemaSource.getIdentifier(), dom, xmlSchemaSource.getSymbolicName().orElse(null));
         }
-
         return null;
     }
 
index c02c7673b9bcea5fb2a69330ff66ead0b66a5de4..c9663386583bb259d96ddba2ac4d39b0c84bae6b 100644 (file)
@@ -118,14 +118,7 @@ public final class PotentialSchemaSource<T extends SchemaSourceRepresentation> {
 
     @Override
     public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof PotentialSchemaSource)) {
-            return false;
-        }
-        final PotentialSchemaSource<?> other = (PotentialSchemaSource<?>) obj;
-        return cost == other.cost && representation.equals(other.representation)
-                && sourceIdentifier.equals(other.sourceIdentifier);
+        return this == obj || obj instanceof PotentialSchemaSource<?> other && cost == other.cost
+            && representation.equals(other.representation) && sourceIdentifier.equals(other.sourceIdentifier);
     }
 }