diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-02-24 10:39:55 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-02-27 11:42:19 +0000 |
commit | ec78f178f542369fdfd696fdc6e4bb872780ac87 (patch) | |
tree | 129206bdf7bb3ad62257d5cfca776e264f70fad6 /infra/translate-utils/src/main | |
parent | 309d5e1561ba42ee491fa33c3b8c24849dc003fa (diff) |
HONEYCOMB-344 - structural reader for list
Change-Id: Ia02ed73daaeea547d49c9ec2d4d7d10f4db85b5e
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'infra/translate-utils/src/main')
-rw-r--r-- | infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizer.java | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizer.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizer.java index 62dbcd6c9..b6430a355 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizer.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/ReflexiveListReaderCustomizer.java @@ -16,31 +16,39 @@ package io.fd.honeycomb.translate.util.read; -import static com.google.common.base.Preconditions.checkArgument; - import com.google.common.base.Optional; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; import io.fd.honeycomb.translate.util.ReflectionUtils; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.List; -import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Identifiable; import org.opendaylight.yangtools.yang.binding.Identifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import javax.annotation.Nonnull; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.List; + +import static com.google.common.base.Preconditions.*; /** * Might be slow. */ -public abstract class ReflexiveListReaderCustomizer<C extends DataObject & Identifiable<K>, K extends Identifier<C>, B extends Builder<C>> +public class ReflexiveListReaderCustomizer<C extends DataObject & Identifiable<K>, K extends Identifier<C>, B extends Builder<C>> extends ReflexiveReaderCustomizer<C, B> implements ListReaderCustomizer<C, K, B> { + private final List<K> staticKeys; - public ReflexiveListReaderCustomizer(final Class<C> typeClass, final Class<B> builderClass) { + public ReflexiveListReaderCustomizer(@Nonnull final Class<C> typeClass, @Nonnull final Class<B> builderClass, + @Nonnull final List<K> staticKeys) { super(typeClass, builderClass); + this.staticKeys = checkNotNull(staticKeys, "Static keys cannot be null"); + checkState(!this.staticKeys.isEmpty(), "No static keys provided"); } @Override @@ -62,4 +70,10 @@ public abstract class ReflexiveListReaderCustomizer<C extends DataObject & Ident throw new IllegalArgumentException("Unable to set " + readData + " to " + parentBuilder, e); } } + + @Nonnull + @Override + public List<K> getAllIds(@Nonnull InstanceIdentifier<C> id, @Nonnull ReadContext context) throws ReadFailedException { + return staticKeys; + } } |