Enforce non-null class 04/40704/2
authorRobert Varga <rovarga@cisco.com>
Wed, 8 Jun 2016 17:05:56 +0000 (19:05 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 22 Jun 2016 13:33:38 +0000 (13:33 +0000)
Also hide the field and expose a getter.

Change-Id: Ic998b2726be93bf173525bdb6a394e438e3e330c
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit 183d2e748a46108562797fb04b18e28609322fd3)

binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/EnumerationCodec.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/ReflectionBasedCodec.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/UnionTypeCodec.java

index a35a5621a2d904b49fa2e861c9b4a5bfba164769..dc13319246023d24a8e91efd9775c1dd76fd341d 100644 (file)
@@ -60,7 +60,7 @@ final class EnumerationCodec extends ReflectionBasedCodec implements SchemaUnawa
 
     @Override
     public Object serialize(final Object input) {
-        Preconditions.checkArgument(typeClass.isInstance(input), "Input must be instance of %s", typeClass);
+        Preconditions.checkArgument(getTypeClass().isInstance(input), "Input must be instance of %s", getTypeClass());
         return yangValueToBinding.inverse().get(input);
     }
 
index fa3aa5001d188bd0c30564a057d78b4c58a74631..373db00049df70af00315a1f799980c8a79236cd 100644 (file)
@@ -7,12 +7,17 @@
  */
 package org.opendaylight.yangtools.binding.data.codec.impl;
 
+import com.google.common.base.Preconditions;
+
 abstract class ReflectionBasedCodec extends ValueTypeCodec {
 
-    protected final Class<?> typeClass;
+    private final Class<?> typeClass;
+
+    ReflectionBasedCodec(final Class<?> typeClass) {
+        this.typeClass = Preconditions.checkNotNull(typeClass);
+    }
 
-    public ReflectionBasedCodec(final Class<?> typeClass) {
-        super();
-        this.typeClass = typeClass;
+    protected final Class<?> getTypeClass() {
+        return typeClass;
     }
 }
\ No newline at end of file
index 17b040f006b4757051531cb2a5417a558114d026..3ee4a2e23278b17866405a0eda18d77bf66bb78b 100644 (file)
@@ -30,7 +30,7 @@ final class UnionTypeCodec extends ReflectionBasedCodec {
     private final Constructor<?> charConstructor;
 
     private UnionTypeCodec(final Class<?> unionCls,final Set<UnionValueOptionContext> codecs,
-                           @Nullable Codec<Object, Object> identityrefCodec) {
+                           @Nullable final Codec<Object, Object> identityrefCodec) {
         super(unionCls);
         this.identityrefCodec = identityrefCodec;
         try {
@@ -68,7 +68,7 @@ final class UnionTypeCodec extends ReflectionBasedCodec {
         if (identityrefCodec != null) {
             try {
                 Object identityref = identityrefCodec.deserialize(input);
-                return typeClass.getConstructor(Class.class).newInstance(identityref);
+                return getTypeClass().getConstructor(Class.class).newInstance(identityref);
             } catch (UncheckedExecutionException | ExecutionError e) {
                 // ignore this exception caused by deserialize()
             } catch (NoSuchMethodException e) {