X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fapi%2FDOMRpcIdentifier.java;h=a574564c0a682c28861f06db5e5ad7ad89fb517a;hb=refs%2Fchanges%2F11%2F80211%2F6;hp=671671c90514691c1f1b8f8b1afd6c003678a2a7;hpb=919145b1bf7d68e436efa9b22c174965005a174a;p=controller.git diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMRpcIdentifier.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMRpcIdentifier.java index 671671c905..a574564c0a 100644 --- a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMRpcIdentifier.java +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMRpcIdentifier.java @@ -7,14 +7,13 @@ */ package org.opendaylight.controller.md.sal.dom.api; +import static java.util.Objects.requireNonNull; + import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; -import java.util.Collections; import java.util.Objects; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.model.api.SchemaPath; /** @@ -25,25 +24,23 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; */ public abstract class DOMRpcIdentifier { - private static final YangInstanceIdentifier GLOBAL_CONTEXT = YangInstanceIdentifier.create(Collections.emptySet()); - private static final class Global extends DOMRpcIdentifier { - private Global(final @Nonnull SchemaPath type) { + private Global(final @NonNull SchemaPath type) { super(type); } @Override public YangInstanceIdentifier getContextReference() { - return GLOBAL_CONTEXT; + return YangInstanceIdentifier.EMPTY; } } private static final class Local extends DOMRpcIdentifier { private final YangInstanceIdentifier contextReference; - private Local(final @Nonnull SchemaPath type, final @Nonnull YangInstanceIdentifier contextReference) { + private Local(final @NonNull SchemaPath type, final @NonNull YangInstanceIdentifier contextReference) { super(type); - this.contextReference = Preconditions.checkNotNull(contextReference); + this.contextReference = requireNonNull(contextReference); } @Override @@ -55,7 +52,7 @@ public abstract class DOMRpcIdentifier { private final SchemaPath type; private DOMRpcIdentifier(final SchemaPath type) { - this.type = Preconditions.checkNotNull(type); + this.type = requireNonNull(type); } /** @@ -64,7 +61,7 @@ public abstract class DOMRpcIdentifier { * @param type RPC type, SchemaPath of its definition, may not be null * @return A global RPC identifier, guaranteed to be non-null. */ - public static @Nonnull DOMRpcIdentifier create(final @Nonnull SchemaPath type) { + public static @NonNull DOMRpcIdentifier create(final @NonNull SchemaPath type) { return new Global(type); } @@ -75,12 +72,20 @@ public abstract class DOMRpcIdentifier { * @param contextReference Context reference, null means a global RPC identifier. * @return A global RPC identifier, guaranteed to be non-null. */ - public static @Nonnull DOMRpcIdentifier create(final @Nonnull SchemaPath type, final @Nullable YangInstanceIdentifier contextReference) { - if (contextReference == null || GLOBAL_CONTEXT.equals(contextReference)) { + public static @NonNull DOMRpcIdentifier create(final @NonNull SchemaPath type, + final @Nullable YangInstanceIdentifier contextReference) { + if (contextReference == null || contextReference.isEmpty()) { return new Global(type); - } else { - return new Local(type, contextReference); } + return new Local(type, contextReference); + } + + public static DOMRpcIdentifier fromMdsal(final org.opendaylight.mdsal.dom.api.DOMRpcIdentifier mdsal) { + return create(mdsal.getType(), mdsal.getContextReference()); + } + + public org.opendaylight.mdsal.dom.api.DOMRpcIdentifier toMdsal() { + return org.opendaylight.mdsal.dom.api.DOMRpcIdentifier.create(type, getContextReference()); } /** @@ -88,7 +93,7 @@ public abstract class DOMRpcIdentifier { * * @return RPC type. */ - public final @Nonnull SchemaPath getType() { + public final @NonNull SchemaPath getType() { return type; } @@ -97,14 +102,14 @@ public abstract class DOMRpcIdentifier { * * @return RPC context reference. */ - public abstract @Nonnull YangInstanceIdentifier getContextReference(); + public abstract @NonNull YangInstanceIdentifier getContextReference(); @Override public final int hashCode() { final int prime = 31; int result = 1; result = prime * result + type.hashCode(); - result = prime * result + (getContextReference() == null ? 0 : getContextReference().hashCode()); + result = prime * result + getContextReference().hashCode(); return result; } @@ -125,6 +130,7 @@ public abstract class DOMRpcIdentifier { @Override public final String toString() { - return MoreObjects.toStringHelper(this).omitNullValues().add("type", type).add("contextReference", getContextReference()).toString(); + return MoreObjects.toStringHelper(this).omitNullValues().add("type", type).add("contextReference", + getContextReference()).toString(); } }