X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FStoreUtils.java;h=0f77ac504a3f5a647f9a184e88b7ecc569332c6f;hb=a71bb09b4111391921854c2776edc746108c53c1;hp=4ad941ae9537b243e75456bc6e04d32161f8f246;hpb=822e5c6c51346ef6ca8254b5597b95742a05fc7d;p=controller.git diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/StoreUtils.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/StoreUtils.java index 4ad941ae95..0f77ac504a 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/StoreUtils.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/StoreUtils.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.dom.store.impl; import java.util.Collections; @@ -8,10 +15,14 @@ import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; 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; @@ -20,7 +31,6 @@ import com.google.common.primitives.UnsignedLong; public final class StoreUtils { private final static Function, Object> EXTRACT_IDENTIFIER = new Function, Object>() { - @Override public Object apply(final Identifiable input) { return input.getIdentifier(); @@ -41,6 +51,16 @@ public final class StoreUtils { return new InitialDataChangeEvent(path, data.getData()); } + /* + * Suppressing warnings here allows us to fool the compiler enough + * such that we can reuse a single function for all applicable types + * and present it in a type-safe manner to our users. + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static Function, V> identifierExtractor() { + return (Function) EXTRACT_IDENTIFIER; + } + private static final class InitialDataChangeEvent implements AsyncDataChangeEvent> { @@ -81,16 +101,43 @@ public final class StoreUtils { public NormalizedNode getUpdatedSubtree() { return data; } + } + public static Set toIdentifierSet(final Iterable> children) { + return FluentIterable.from(children).transform(StoreUtils. identifierExtractor()).toSet(); } - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static Function,V> identifierExtractor() { - return (Function) EXTRACT_IDENTIFIER; + public static String toStringTree(final StoreMetadataNode metaNode) { + StringBuilder builder = new StringBuilder(); + toStringTree(builder, metaNode, 0); + return builder.toString(); } - public static Set toIdentifierSet(final Iterable> children) { - return FluentIterable.from(children).transform(StoreUtils.identifierExtractor()).toSet(); + 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(" {\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(); + } }