@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);
}
*/
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
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 {
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) {