Migrate yang-model-util annotations
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / SchemaNodeUtils.java
index eaa6b9d92019e14644e34830fb368e7c96bfd0ec..2b21b23c115e066492234379857fedb71bfa8c87 100644 (file)
@@ -7,58 +7,59 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import static java.util.Objects.requireNonNull;
+
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 
-public class SchemaNodeUtils {
-
+public final class SchemaNodeUtils {
     private SchemaNodeUtils() {
         throw new UnsupportedOperationException("Utility class");
     }
 
-    public static final Optional<SchemaNode> getOriginalIfPossible(final SchemaNode node) {
-        if(node instanceof DerivableSchemaNode) {
+    public static Optional<SchemaNode> getOriginalIfPossible(final SchemaNode node) {
+        if (node instanceof DerivableSchemaNode) {
             @SuppressWarnings("unchecked")
-            final Optional<SchemaNode> ret  = (Optional<SchemaNode>) (((DerivableSchemaNode) node).getOriginal());
+            final Optional<SchemaNode> ret  = (Optional<SchemaNode>) ((DerivableSchemaNode) node).getOriginal();
             return ret;
         }
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    public static final  SchemaNode getRootOriginalIfPossible(final SchemaNode data) {
-        Optional<SchemaNode> previous = Optional.absent();
+    public static SchemaNode getRootOriginalIfPossible(final SchemaNode data) {
+        Optional<SchemaNode> previous = Optional.empty();
         Optional<SchemaNode> next = getOriginalIfPossible(data);
-        while(next.isPresent()) {
+        while (next.isPresent()) {
             previous = next;
             next = getOriginalIfPossible(next.get());
         }
-        return previous.orNull();
+        return previous.orElse(null);
     }
 
     /**
-     * Returns RPC input or output schema based on supplied QName
+     * Returns RPC input or output schema based on supplied QName.
      *
      * @param rpc RPC Definition
      * @param qname input or output QName with namespace same as RPC
      * @return input or output schema. Returns null if RPC does not have input/output specified.
      */
-    @Nullable public static ContainerSchemaNode getRpcDataSchema(@Nonnull final RpcDefinition rpc, @Nonnull final QName qname) {
-        Preconditions.checkNotNull(rpc, "Rpc Schema must not be null");
-        Preconditions.checkNotNull(qname,"QName must not be null");
-        switch (qname.getLocalName()) {
-           case "input":
-               return rpc.getInput();
-           case "output":
-               return rpc.getOutput();
-           default:
-               throw new IllegalArgumentException("Supplied qname " + qname + " does not represent rpc input or output.");
-           }
-       }
+    public static @Nullable ContainerSchemaNode getRpcDataSchema(final @NonNull RpcDefinition rpc,
+            final @NonNull QName qname) {
+        requireNonNull(rpc, "Rpc Schema must not be null");
+        switch (requireNonNull(qname, "QName must not be null").getLocalName()) {
+            case "input":
+                return rpc.getInput();
+            case "output":
+                return rpc.getOutput();
+            default:
+                throw new IllegalArgumentException("Supplied qname " + qname
+                        + " does not represent rpc input or output.");
+        }
+    }
 }