Remove ReflectionBaseCodec 38/100538/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Apr 2022 15:06:18 +0000 (17:06 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Apr 2022 15:06:47 +0000 (17:06 +0200)
This base class has no real function, remove it.

JIRA: MDSAL-704
Change-Id: I1c79e861bc55133ed16745d4744b29588326eee5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/EnumerationCodec.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ReflectionBasedCodec.java [deleted file]
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/UnionTypeCodec.java

index bd7d1614ff8b9cafb4ff987e456051b4eb376310..3b29d23db9210441e8e70dc93039e23a64c7711f 100644 (file)
@@ -26,7 +26,7 @@ import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPai
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-final class EnumerationCodec extends ReflectionBasedCodec implements SchemaUnawareCodec {
+final class EnumerationCodec extends ValueTypeCodec implements SchemaUnawareCodec {
     private static final Logger LOG = LoggerFactory.getLogger(EnumerationCodec.class);
     /*
      * Use identity comparison for keys and allow classes to be GCd themselves.
@@ -42,9 +42,10 @@ final class EnumerationCodec extends ReflectionBasedCodec implements SchemaUnawa
         .softValues().build();
 
     private final ImmutableBiMap<String, Enum<?>> nameToEnum;
+    private final Class<? extends Enum<?>> enumClass;
 
-    private EnumerationCodec(final Class<? extends Enum<?>> enumeration, final Map<String, Enum<?>> nameToEnum) {
-        super(enumeration);
+    private EnumerationCodec(final Class<? extends Enum<?>> enumClass, final Map<String, Enum<?>> nameToEnum) {
+        this.enumClass = requireNonNull(enumClass);
         this.nameToEnum = ImmutableBiMap.copyOf(nameToEnum);
     }
 
@@ -94,7 +95,7 @@ final class EnumerationCodec extends ReflectionBasedCodec implements SchemaUnawa
 
     @Override
     public String serialize(final Object input) {
-        checkArgument(getTypeClass().isInstance(input), "Input %s is not a instance of %s", input, getTypeClass());
+        checkArgument(enumClass.isInstance(input), "Input %s is not a instance of %s", input, enumClass);
         return requireNonNull(nameToEnum.inverse().get(input));
     }
 }
\ No newline at end of file
diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ReflectionBasedCodec.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ReflectionBasedCodec.java
deleted file mode 100644 (file)
index 1f3a7e2..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.codec.impl;
-
-import static java.util.Objects.requireNonNull;
-
-abstract class ReflectionBasedCodec extends ValueTypeCodec {
-
-    private final Class<?> typeClass;
-
-    ReflectionBasedCodec(final Class<?> typeClass) {
-        this.typeClass = requireNonNull(typeClass);
-    }
-
-    protected final Class<?> getTypeClass() {
-        return typeClass;
-    }
-}
\ No newline at end of file
index 6e4bbdb85f22c16693197aae621abd7cc198c37f..1824f60f60d15cc02ad2ae34e7c4327e393c1a18 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.mdsal.binding.dom.codec.impl;
 
 import static com.google.common.base.Verify.verify;
 import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.ImmutableSet;
 import java.lang.reflect.Method;
@@ -24,12 +25,14 @@ import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 
-final class UnionTypeCodec extends ReflectionBasedCodec {
+final class UnionTypeCodec extends ValueTypeCodec {
     private final ImmutableSet<UnionValueOptionContext> typeCodecs;
+    private final Class<?> unionClass;
 
-    private UnionTypeCodec(final Class<?> unionCls,final List<UnionValueOptionContext> codecs) {
-        super(unionCls);
-        typeCodecs = ImmutableSet.copyOf(codecs);
+    private UnionTypeCodec(final Class<?> unionClass, final List<UnionValueOptionContext> typeCodecs) {
+        this.unionClass = requireNonNull(unionClass);
+        // Squashes duplicates
+        this.typeCodecs = ImmutableSet.copyOf(typeCodecs);
     }
 
     static Callable<UnionTypeCodec> loader(final Class<?> unionCls, final UnionTypeDefinition unionType,
@@ -78,7 +81,7 @@ final class UnionTypeCodec extends ReflectionBasedCodec {
         }
 
         throw new IllegalArgumentException(String.format("Failed to construct instance of %s for input %s",
-            getTypeClass(), input));
+            unionClass, input));
     }
 
     @Override