Enforce non-null class 59/40059/4
authorRobert Varga <rovarga@cisco.com>
Wed, 8 Jun 2016 17:05:56 +0000 (19:05 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 14 Jun 2016 15:05:02 +0000 (15:05 +0000)
Also hide the field and expose a getter.

Change-Id: Ic998b2726be93bf173525bdb6a394e438e3e330c
Signed-off-by: Robert Varga <rovarga@cisco.com>
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 19f79fa2d120237df3e5abea2b119d11b30bf6ac..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 {
@@ -42,7 +42,7 @@ final class UnionTypeCodec extends ReflectionBasedCodec {
     }
 
     static Callable<UnionTypeCodec> loader(final Class<?> unionCls, final UnionTypeDefinition unionType,
-                                           BindingCodecContext bindingCodecContext) {
+                                           final BindingCodecContext bindingCodecContext) {
         return new Callable<UnionTypeCodec>() {
             @Override
             public UnionTypeCodec call() throws NoSuchMethodException, SecurityException {
@@ -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) {