diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-09-05 12:10:26 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2016-09-07 06:50:30 +0000 |
commit | 1326e9fa5cffe326b82aeee9d82d008526aff947 (patch) | |
tree | f8ca808f3aa3a9338573d8892b83305210a664a1 /infra/translate-utils/src/main/java/io/fd | |
parent | 6e77db8e850be8ad8a3d91bf43fb8986125ae60f (diff) |
Cleanup TODOs and FIXMEs
- Fix minor ones
- Report bigger and include issue number in comment
- Pull common dependencies into dependency management of common/parents
Change-Id: I06a6ac37c52b603fd73ed42023d6b2e7fa18010f
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/translate-utils/src/main/java/io/fd')
7 files changed, 22 insertions, 33 deletions
diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/AbstractSubtreeManagerRegistryBuilderBuilder.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/AbstractSubtreeManagerRegistryBuilderBuilder.java index bf1e89c12..07f2bf1ee 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/AbstractSubtreeManagerRegistryBuilderBuilder.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/AbstractSubtreeManagerRegistryBuilderBuilder.java @@ -192,10 +192,10 @@ public abstract class AbstractSubtreeManagerRegistryBuilderBuilder<S extends Sub } }); - // TODO we could optimize subtree handlers, if there is a dedicated handler for a node managed by a subtree + // TODO HONEYCOMB-171 we could optimize subtree handlers, if there is a dedicated handler for a node managed by a subtree // handler, recreate the subtree handler with a subset of handled child nodes // This way it is not necessary to change the configuration of subtree writer, just to add a dedicated child - // writer. This will be needed if we ever switch to annotations for reader/writer hierarchy initialization + // writer return builder.build(); } diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RWUtils.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RWUtils.java index 695ce6806..4616f8347 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RWUtils.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/RWUtils.java @@ -38,10 +38,12 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public final class RWUtils { + // TODO HONEYCOMB-172 update the utils methods considering Java8. Make sure they still work by wiring a detailed unit test first + private RWUtils() {} /** - * Collector expecting only a single resulting item from a stream + * Collector expecting only a single resulting item from a stream. */ public static<T> Collector<T,?,T> singleItemCollector() { return Collectors.collectingAndThen( @@ -56,12 +58,11 @@ public final class RWUtils { } /** - * Find next item in ID after provided type + * Find next item in ID after provided type. */ @Nonnull public static InstanceIdentifier.PathArgument getNextId(@Nonnull final InstanceIdentifier<? extends DataObject> id, @Nonnull final InstanceIdentifier<? extends DataObject> type) { - // TODO this is inefficient(maybe, depending on actual Iterable type) final Iterable<InstanceIdentifier.PathArgument> pathArguments = id.getPathArguments(); final int i = Iterables.indexOf(pathArguments, new Predicate<InstanceIdentifier.PathArgument>() { @Override @@ -74,7 +75,7 @@ public final class RWUtils { } /** - * Replace last item in ID with a provided IdentifiableItem of the same type + * Replace last item in ID with a provided IdentifiableItem of the same type. */ @SuppressWarnings("unchecked") @Nonnull @@ -90,7 +91,7 @@ public final class RWUtils { } /** - * Create IdentifiableItem from target type of provided ID with provided key + * Create IdentifiableItem from target type of provided ID with provided key. */ @Nonnull public static <D extends DataObject & Identifiable<K>, K extends Identifier<D>> InstanceIdentifier.IdentifiableItem<D, K> getCurrentIdItem( @@ -99,7 +100,7 @@ public final class RWUtils { } /** - * Trim InstanceIdentifier at indexOf(type) + * Trim InstanceIdentifier at indexOf(type). */ @SuppressWarnings("unchecked") @Nonnull diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/TransactionMappingContext.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/TransactionMappingContext.java index 1b6504c78..4d4e9fddd 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/TransactionMappingContext.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/TransactionMappingContext.java @@ -34,7 +34,7 @@ public class TransactionMappingContext implements MappingContext { private final ReadWriteTransaction readWriteTransaction; - // TODO make async + // TODO HONEYCOMB-169 make async public TransactionMappingContext(final ReadWriteTransaction readWriteTransaction) { this.readWriteTransaction = readWriteTransaction; diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/AbstractGenericReader.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/AbstractGenericReader.java index 75a2a673c..40c78b3c9 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/AbstractGenericReader.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/AbstractGenericReader.java @@ -56,7 +56,8 @@ public abstract class AbstractGenericReader<D extends DataObject, B extends Buil @Nonnull final ReadContext ctx) throws ReadFailedException { LOG.debug("{}: Reading current: {}", this, id); final B builder = getBuilder(id); - // Cache empty value to determine if anything has changed later TODO cache in a field + // The empty value could be cached, but no caching is safer since we call overridden getBuilder each time + // and the build could produce something different (even if it shouldn't) final D emptyValue = builder.build(); LOG.trace("{}: Reading current attributes", this); diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReader.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReader.java index 720bd0b11..260fb241b 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReader.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReader.java @@ -19,7 +19,6 @@ package io.fd.honeycomb.translate.util.read.registry; import static com.google.common.base.Preconditions.checkArgument; import com.google.common.base.Optional; -import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import io.fd.honeycomb.translate.read.ListReader; import io.fd.honeycomb.translate.read.ReadContext; @@ -34,7 +33,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Identifiable; @@ -143,7 +141,6 @@ class SubtreeReader<D extends DataObject, B extends Builder<D>> implements Reade private static Optional<? extends DataObject> findNextParent(@Nonnull final DataObject parent, @Nonnull final InstanceIdentifier.PathArgument nextId, @Nonnull final Class<?> managedType) { - // TODO is there a better way than reflection ? e.g. convert into NN and filter out with a utility Optional<Method> method = ReflectionUtils.findMethodReflex(managedType, "get", Collections.emptyList(), nextId.getType()); @@ -172,19 +169,13 @@ class SubtreeReader<D extends DataObject, B extends Builder<D>> implements Reade checkArgument(nextId instanceof InstanceIdentifier.IdentifiableItem<?, ?>, "Unable to perform wildcarded read for %s", nextId); final Identifier key = ((InstanceIdentifier.IdentifiableItem) nextId).getKey(); - // TODO replace with stream().filter().findFirst() when we switch to using java's Optional instead of Guava's - // because now we would have to do awkward Optional transformation since findFirstReturns guava's optional - return Iterables.tryFind(invoke, new Predicate<DataObject>() { - - @Override - public boolean apply(@Nullable final DataObject input) { - final Optional<Method> keyGetter = ReflectionUtils.findMethodReflex(nextId.getType(), "get", - Collections.emptyList(), key.getClass()); - final Object actualKey; - actualKey = invoke(keyGetter.get(), nextId, input); - return key.equals(actualKey); - } - }); + + final Method keyGetter = ReflectionUtils.findMethodReflex(nextId.getType(), "get", + Collections.emptyList(), key.getClass()).get(); + + return Optional.fromNullable(invoke.stream() + .filter(item -> key.equals(invoke(keyGetter, nextId, item))) + .findFirst().orElse(null)); } private static DataObject filterSingle(final DataObject parent, diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java index 5d801edab..0128ee4a8 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java @@ -50,14 +50,13 @@ public final class TransactionWriteContext implements WriteContext { final DOMDataReadOnlyTransaction afterTx, final MappingContext mappingContext) { this.serializer = serializer; - // TODO do we have a BA transaction adapter ? If so, use it here and don't pass serializer this.beforeTx = beforeTx; this.afterTx = afterTx; this.mappingContext = mappingContext; this.ctx = new ModificationCache(); } - // TODO make this asynchronous + // TODO HONEYCOMB-169 make this asynchronous @Override public <T extends DataObject> Optional<T> readBefore(@Nonnull final InstanceIdentifier<T> currentId) { @@ -78,7 +77,7 @@ public final class TransactionWriteContext implements WriteContext { tx.read(LogicalDatastoreType.CONFIGURATION, path); try { - // TODO once the APIs are asynchronous use just Futures.transform + // TODO HONEYCOMB-169 once the APIs are asynchronous use just Futures.transform final Optional<NormalizedNode<?, ?>> optional = read.checkedGet(); if (!optional.isPresent()) { diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/registry/FlatWriterRegistry.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/registry/FlatWriterRegistry.java index df8ec107b..ab80eb4ac 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/registry/FlatWriterRegistry.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/registry/FlatWriterRegistry.java @@ -139,13 +139,11 @@ final class FlatWriterRegistry implements WriterRegistry { } private Writer<?> getSubtreeWriterResponsible(final InstanceIdentifier<?> singleType) { - final Writer<?> writer;// This is slow ( minor TODO-perf ) - writer = writers.values().stream() + return writers.values().stream() .filter(w -> w instanceof SubtreeWriter) .filter(w -> ((SubtreeWriter<?>) w).getHandledChildTypes().contains(singleType)) .findFirst() .get(); - return writer; } private Collection<DataObjectUpdate> getParentDataObjectUpdate(final WriteContext ctx, @@ -255,7 +253,6 @@ final class FlatWriterRegistry implements WriterRegistry { return writers.get(singleType); } - // FIXME unit test private final class ReverterImpl implements Reverter { private final Collection<InstanceIdentifier<?>> processedNodes; |