import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreMetadataNode;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.AugmentationIdentifier;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import com.google.common.base.Function;
+import com.google.common.base.Strings;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
return new InitialDataChangeEvent(path, data.getData());
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static <V> Function<Identifiable<V>, V> identifierExtractor() {
+ return (Function) EXTRACT_IDENTIFIER;
+ }
+
private static final class InitialDataChangeEvent implements
AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> {
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public static <V> Function<Identifiable<V>,V> identifierExtractor() {
- return (Function) EXTRACT_IDENTIFIER;
+ public static <V> Set<V> toIdentifierSet(final Iterable<? extends Identifiable<V>> children) {
+ return FluentIterable.from(children).transform(StoreUtils.<V> identifierExtractor()).toSet();
}
- public static <V> Set<V> toIdentifierSet(final Iterable<? extends Identifiable<V>> children) {
- return FluentIterable.from(children).transform(StoreUtils.<V>identifierExtractor()).toSet();
+ public static String toStringTree(final StoreMetadataNode metaNode) {
+ StringBuilder builder = new StringBuilder();
+ toStringTree(builder, metaNode, 0);
+ return builder.toString();
+
}
+ private static void toStringTree(final StringBuilder builder, final StoreMetadataNode metaNode, final int offset) {
+ String prefix = Strings.repeat(" ", offset);
+ builder.append(prefix).append(toStringTree(metaNode.getIdentifier()));
+ NormalizedNode<?, ?> dataNode = metaNode.getData();
+ if (dataNode instanceof NormalizedNodeContainer<?, ?, ?>) {
+ builder.append(" {").append("\n");
+ for (StoreMetadataNode child : metaNode.getChildren()) {
+ toStringTree(builder, child, offset + 4);
+ }
+ builder.append(prefix).append("}");
+ } else {
+ builder.append(" ").append(dataNode.getValue());
+ }
+ builder.append("\n");
+ }
+
+ private static String toStringTree(final PathArgument identifier) {
+ if (identifier instanceof NodeIdentifierWithPredicates) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(identifier.getNodeType().getLocalName());
+ builder.append(((NodeIdentifierWithPredicates) identifier).getKeyValues().values());
+ return builder.toString();
+ } else if (identifier instanceof AugmentationIdentifier) {
+ return "augmentation";
+ }
+ return identifier.getNodeType().getLocalName();
+ }
}