X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;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;hp=df58d62dd47662a7da382f2232b8067a337c7118;hb=494d528befd3908cc1b5f1c7706d34414819ef03;hpb=335a9cfe42385a217ef002e4ab42f9cd958ad202 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 df58d62dd4..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; @@ -24,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(); @@ -45,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> { @@ -85,43 +101,36 @@ public final class StoreUtils { public NormalizedNode getUpdatedSubtree() { return data; } - - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static Function,V> identifierExtractor() { - return (Function) EXTRACT_IDENTIFIER; } public static Set toIdentifierSet(final Iterable> children) { - return FluentIterable.from(children).transform(StoreUtils.identifierExtractor()).toSet(); + return FluentIterable.from(children).transform(StoreUtils. identifierExtractor()).toSet(); } public static String toStringTree(final StoreMetadataNode metaNode) { StringBuilder builder = new StringBuilder(); - toStringTree(builder, metaNode,0); + toStringTree(builder, metaNode, 0); return builder.toString(); - } - private static void toStringTree(final StringBuilder builder, final StoreMetadataNode metaNode,final int offset) { + 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); + if (dataNode instanceof NormalizedNodeContainer) { + builder.append(" {\n"); + for (StoreMetadataNode child : metaNode.getChildren()) { + toStringTree(builder, child, offset + 4); } - builder.append(prefix).append("}"); + builder.append(prefix).append('}'); } else { - builder.append(" ").append(dataNode.getValue()); + builder.append(' ').append(dataNode.getValue()); } - builder.append("\n"); + builder.append('\n'); } private static String toStringTree(final PathArgument identifier) { - if( identifier instanceof NodeIdentifierWithPredicates) { + if (identifier instanceof NodeIdentifierWithPredicates) { StringBuilder builder = new StringBuilder(); builder.append(identifier.getNodeType().getLocalName()); builder.append(((NodeIdentifierWithPredicates) identifier).getKeyValues().values());