import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicates;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
+
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+
public class DataNormalizer {
private final DataNormalizationOperation<?> operation;
ImmutableList.Builder<PathArgument> normalizedArgs = ImmutableList.builder();
DataNormalizationOperation<?> currentOp = operation;
- Iterator<PathArgument> arguments = legacy.getPath().iterator();
+ Iterator<PathArgument> arguments = legacy.getPathArguments().iterator();
try {
while (arguments.hasNext()) {
throw new IllegalArgumentException(String.format("Failed to normalize path %s", legacy), e);
}
- return new InstanceIdentifier(normalizedArgs.build());
+ return InstanceIdentifier.create(normalizedArgs.build());
+ }
+
+ public DataNormalizationOperation<?> getOperation(final InstanceIdentifier legacy) throws DataNormalizationException {
+ DataNormalizationOperation<?> currentOp = operation;
+ Iterator<PathArgument> arguments = legacy.getPathArguments().iterator();
+
+ while (arguments.hasNext()) {
+ currentOp = currentOp.getChild(arguments.next());
+ }
+ return currentOp;
}
public Map.Entry<InstanceIdentifier, NormalizedNode<?, ?>> toNormalized(
InstanceIdentifier normalizedPath = toNormalized(legacyPath);
DataNormalizationOperation<?> currentOp = operation;
- for (PathArgument arg : normalizedPath.getPath()) {
+ for (PathArgument arg : normalizedPath.getPathArguments()) {
try {
currentOp = currentOp.getChild(arg);
} catch (DataNormalizationException e) {
if (potentialOp.getIdentifier() instanceof AugmentationIdentifier) {
currentOp = potentialOp;
- ArrayList<PathArgument> reworkedArgs = new ArrayList<>(normalizedPath.getPath());
- reworkedArgs.add(potentialOp.getIdentifier());
- normalizedPath = new InstanceIdentifier(reworkedArgs);
+ normalizedPath = normalizedPath.node(potentialOp.getIdentifier());
}
}
public InstanceIdentifier toLegacy(final InstanceIdentifier normalized) throws DataNormalizationException {
ImmutableList.Builder<PathArgument> legacyArgs = ImmutableList.builder();
- PathArgument previous = null;
DataNormalizationOperation<?> currentOp = operation;
- for (PathArgument normalizedArg : normalized.getPath()) {
+ for (PathArgument normalizedArg : normalized.getPathArguments()) {
currentOp = currentOp.getChild(normalizedArg);
- if(!currentOp.isMixin()) {
+ if (!currentOp.isMixin()) {
legacyArgs.add(normalizedArg);
}
}
- return new InstanceIdentifier(legacyArgs.build());
+ return InstanceIdentifier.create(legacyArgs.build());
}
public CompositeNode toLegacy(final InstanceIdentifier normalizedPath, final NormalizedNode<?, ?> normalizedData) {
return toLegacyFromDataContainer((DataContainerNode<?>) normalizedData);
} else if (normalizedData instanceof AnyXmlNode) {
Node<?> value = ((AnyXmlNode) normalizedData).getValue();
- return value instanceof CompositeNode ? (CompositeNode)value : null;
+ return value instanceof CompositeNode ? (CompositeNode) value : null;
}
return null;
}
for (NormalizedNode<?, ?> child : node.getValue()) {
if (child instanceof MixinNode && child instanceof NormalizedNodeContainer<?, ?, ?>) {
builder.addAll(toLegacyNodesFromMixin((NormalizedNodeContainer) child));
- } else if( child instanceof UnkeyedListNode) {
+ } else if (child instanceof UnkeyedListNode) {
builder.addAll(toLegacyNodesFromUnkeyedList((UnkeyedListNode) child));
} else {
addToBuilder(builder, toLegacy(child));