This base class has no real function, remove it.
JIRA: MDSAL-704
Change-Id: I1c79e861bc55133ed16745d4744b29588326eee5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
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.
.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);
}
@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
+++ /dev/null
-/*
- * 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
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;
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,
}
throw new IllegalArgumentException(String.format("Failed to construct instance of %s for input %s",
- getTypeClass(), input));
+ unionClass, input));
}
@Override