summaryrefslogtreecommitdiffstats
path: root/v3po/vpp-translate-utils
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-05-23 09:26:27 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-05-24 12:53:23 +0200
commit0bc7eaba914121d64c2a095818fda9edcc4e3004 (patch)
tree9181cfbb29c0f36152e65f2501534852c863f938 /v3po/vpp-translate-utils
parent1959d37c3611ac1e821b72d9a51c40086c5db5cb (diff)
HONEYCOMB-61: Fix outstanding issues
Change-Id: I2dec6bbd8db656663029ad0f59da1b583c890565 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/vpp-translate-utils')
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java58
1 files changed, 53 insertions, 5 deletions
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java
index d32f27203..34c810462 100644
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java
+++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java
@@ -36,14 +36,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Utility adapter on top of {@link MappingContext}
+ * Utility adapter on top of {@link MappingContext} storing integer to string mappings according to naming-context yang
+ * model
*/
public final class NamingContext implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(NamingContext.class);
private final String artificialNamePrefix;
- private KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext, NamingContextKey>
+ private final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext, NamingContextKey>
namingContextIid;
/**
@@ -58,15 +59,30 @@ public final class NamingContext implements AutoCloseable {
return list.get(0);
});
- public NamingContext(final String artificialNamePrefix, final String instanceName) {
+ /**
+ * 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
+ */
+ 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));
}
+ /**
+ * Retrieve name for mapping stored provided mappingContext instance. If not present, artificial name will be
+ * generated.
+ *
+ * @param index index of a mapped item
+ * @param mappingContext mapping context providing context data for current transaction
+ *
+ * @return name mapped to provided index
+ */
@Nonnull
- public synchronized String getName(final int index, final MappingContext mappingContext) {
+ public synchronized String getName(final int index, @Nonnull final MappingContext mappingContext) {
if (!containsName(index, mappingContext)) {
final String artificialName = getArtificialName(index);
LOG.info("Assigning artificial name: {} for index: {}", artificialName, index);
@@ -81,13 +97,29 @@ public final class NamingContext implements AutoCloseable {
.collect(SINGLE_ITEM_COLLECTOR).getName();
}
- public synchronized boolean containsName(final int index, final MappingContext mappingContext) {
+ /**
+ * Check whether mapping is present for index.
+ *
+ * @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;
}
+
+ /**
+ * Add mapping to current context
+ *
+ * @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) {
final KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid = getMappingIid(name);
mappingContext.put(mappingIid, new MappingBuilder().setIndex(index).setName(name).build());
@@ -97,6 +129,12 @@ public final class NamingContext implements AutoCloseable {
return namingContextIid.child(Mappings.class).child(Mapping.class, new MappingKey(name));
}
+ /**
+ * Remove mapping from current context
+ *
+ * @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) {
mappingContext.delete(getMappingIid(name));
}
@@ -105,6 +143,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 mappingContext mapping context providing context data for current transaction
+ *
* @return integer index value matching supplied name
* @throws IllegalArgumentException if name was not found
*/
@@ -115,6 +155,14 @@ public final class NamingContext implements AutoCloseable {
}
+ /**
+ * Check whether mapping is present for name.
+ *
+ * @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) {
return mappingContext.read(getMappingIid(name)).isPresent();
}