Retain protype in DataContainerCodecContext
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / UnionValueOptionContext.java
index 5b1ae9eeb1b4f4c1fdd0321d7d7858d1705914f1..5cbc9d8b793085a38bb840f53ee41262a628e153 100644 (file)
@@ -7,13 +7,13 @@
  */
 package org.opendaylight.mdsal.binding.dom.codec.impl;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.Throwables;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
 import java.lang.reflect.Method;
-import org.opendaylight.yangtools.concepts.Codec;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -22,14 +22,14 @@ final class UnionValueOptionContext {
     private static final Logger LOG = LoggerFactory.getLogger(UnionValueOptionContext.class);
 
     private final Class<?> bindingType;
-    private final Codec<Object,Object> codec;
+    private final ValueCodec<Object,Object> codec;
     private final MethodHandle getter;
     private final MethodHandle unionCtor;
 
     UnionValueOptionContext(final Class<?> unionType, final Class<?> valueType, final Method getter,
-            final Codec<Object, Object> codec) {
-        this.bindingType = Preconditions.checkNotNull(valueType);
-        this.codec = Preconditions.checkNotNull(codec);
+            final ValueCodec<Object, Object> codec) {
+        bindingType = requireNonNull(valueType);
+        this.codec = requireNonNull(codec);
 
         try {
             this.getter = MethodHandles.publicLookup().unreflect(getter).asType(OBJECT_TYPE);
@@ -38,7 +38,7 @@ final class UnionValueOptionContext {
         }
 
         try {
-            this.unionCtor = MethodHandles.publicLookup().findConstructor(unionType,
+            unionCtor = MethodHandles.publicLookup().findConstructor(unionType,
                 MethodType.methodType(void.class, valueType)).asType(OBJECT_TYPE);
         } catch (IllegalAccessException | NoSuchMethodException e) {
             throw new IllegalStateException(String.format("Failed to access constructor for %s in type %s", valueType,
@@ -83,7 +83,7 @@ final class UnionValueOptionContext {
             return getter.invokeExact(input);
         } catch (Throwable e) {
             Throwables.throwIfUnchecked(e);
-            throw new RuntimeException(e);
+            throw new IllegalStateException(e);
         }
     }
 
@@ -97,11 +97,10 @@ final class UnionValueOptionContext {
         if (this == obj) {
             return true;
         }
-        if (!(obj instanceof UnionValueOptionContext)) {
+        if (!(obj instanceof UnionValueOptionContext other)) {
             return false;
         }
 
-        final UnionValueOptionContext other = (UnionValueOptionContext) obj;
         return bindingType.equals(other.bindingType);
     }
 }