diff options
Diffstat (limited to 'vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/NamingContext.java')
-rw-r--r-- | vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/NamingContext.java | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/NamingContext.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/NamingContext.java index ead59a803..056a6df2c 100644 --- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/NamingContext.java +++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/NamingContext.java @@ -39,32 +39,31 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; */ public final class NamingContext implements AutoCloseable { + private static final Collector<Mapping, ?, Mapping> SINGLE_ITEM_COLLECTOR = RWUtils.singleItemCollector(); private final String artificialNamePrefix; private final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext, NamingContextKey> - namingContextIid; - - private static final Collector<Mapping, ?, Mapping> SINGLE_ITEM_COLLECTOR = RWUtils.singleItemCollector(); + namingContextIid; /** * Create new naming context * * @param artificialNamePrefix artificial name to be used for items without a name in VPP (or not provided) - * @param instanceName name of this context instance. Will be used as list item identifier within context data tree + * @param instanceName name of this context instance. Will be used as list item identifier within context + * data tree */ public NamingContext(@Nonnull final String artificialNamePrefix, @Nonnull final String instanceName) { this.artificialNamePrefix = artificialNamePrefix; namingContextIid = InstanceIdentifier.create(Contexts.class).child( - org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext.class, - new NamingContextKey(instanceName)); + org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext.class, + new NamingContextKey(instanceName)); } /** * Retrieve name for mapping stored provided mappingContext instance. If not present, artificial name will be * generated. * - * @param index index of a mapped item + * @param index index of a mapped item * @param mappingContext mapping context providing context data for current transaction - * * @return name mapped to provided index */ @Nonnull @@ -78,16 +77,15 @@ public final class NamingContext implements AutoCloseable { checkState(read.isPresent(), "Mapping for index: %s is not present. But should be", index); return read.get().getMapping().stream() - .filter(mapping -> mapping.getIndex().equals(index)) - .collect(SINGLE_ITEM_COLLECTOR).getName(); + .filter(mapping -> mapping.getIndex().equals(index)) + .collect(SINGLE_ITEM_COLLECTOR).getName(); } /** * Retrieve name for mapping stored provided mappingContext instance. if present * - * @param index index of a mapped item + * @param index index of a mapped item * @param mappingContext mapping context providing context data for current transaction - * * @return name mapped to provided index */ @Nonnull @@ -97,33 +95,32 @@ public final class NamingContext implements AutoCloseable { return read.isPresent() ? Optional.of(read.get().getMapping().stream() - .filter(mapping -> mapping.getIndex().equals(index)) - .collect(SINGLE_ITEM_COLLECTOR) - .getName()) + .filter(mapping -> mapping.getIndex().equals(index)) + .collect(SINGLE_ITEM_COLLECTOR) + .getName()) : Optional.absent(); } /** * Check whether mapping is present for index. * - * @param index index of a mapped item + * @param index index of a mapped item * @param mappingContext mapping context providing context data for current transaction - * * @return true if present, false otherwise */ public synchronized boolean containsName(final int index, @Nonnull final MappingContext mappingContext) { final Optional<Mappings> read = mappingContext.read(namingContextIid.child(Mappings.class)); return read.isPresent() - ? read.get().getMapping().stream().anyMatch(mapping -> mapping.getIndex().equals(index)) - : false; + ? read.get().getMapping().stream().anyMatch(mapping -> mapping.getIndex().equals(index)) + : false; } /** * Add mapping to current context * - * @param index index of a mapped item - * @param name name of a mapped item + * @param index index of a mapped item + * @param name name of a mapped item * @param mappingContext mapping context providing context data for current transaction */ public synchronized void addName(final int index, final String name, final MappingContext mappingContext) { @@ -138,7 +135,7 @@ public final class NamingContext implements AutoCloseable { /** * Remove mapping from current context * - * @param name name of a mapped item + * @param name name of a mapped item * @param mappingContext mapping context providing context data for current transaction */ public synchronized void removeName(final String name, final MappingContext mappingContext) { @@ -148,9 +145,8 @@ public final class NamingContext implements AutoCloseable { /** * Returns index value associated with the given name. * - * @param name the name whose associated index value is to be returned + * @param name the name whose associated index value is to be returned * @param mappingContext mapping context providing context data for current transaction - * * @return integer index value matching supplied name * @throws IllegalArgumentException if name was not found */ @@ -164,9 +160,8 @@ public final class NamingContext implements AutoCloseable { /** * Check whether mapping is present for name. * - * @param name name of a mapped item + * @param name name of a mapped item * @param mappingContext mapping context providing context data for current transaction - * * @return true if present, false otherwise */ public synchronized boolean containsIndex(final String name, final MappingContext mappingContext) { |