Address trivial eclipse warnings
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / AbstractDataTreeCandidateNode.java
index 10f12cf359a74d4502afa13e8794a20046725168..082dfd4c870c05c9aa630651af781f8689c57182 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2015, 2016 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,
@@ -7,13 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Collections2;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -22,25 +20,10 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 
 abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
-    private static final Function<NormalizedNode<?, ?>, DataTreeCandidateNode> TO_DELETED_NODE = new Function<NormalizedNode<?, ?>, DataTreeCandidateNode>() {
-        @Override
-        public DataTreeCandidateNode apply(final NormalizedNode<?, ?> input) {
-            return AbstractRecursiveCandidateNode.deleteNode(input);
-        }
-    };
-    private static final Function<NormalizedNode<?, ?>, DataTreeCandidateNode> TO_WRITTEN_NODE = new Function<NormalizedNode<?, ?>, DataTreeCandidateNode>() {
-        @Override
-        public DataTreeCandidateNode apply(final NormalizedNode<?, ?> input) {
-            return AbstractRecursiveCandidateNode.writeNode(input);
-        }
-    };
-
-    private static Optional<NormalizedNode<?, ?>> getChild(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> container, final PathArgument identifier) {
-        if (container != null) {
-            return container.getChild(identifier);
-        } else {
-            return Optional.absent();
-        }
+    private static Optional<NormalizedNode<?, ?>> getChild(
+            final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> container,
+                    final PathArgument identifier) {
+        return container == null ? Optional.absent() : container.getChild(identifier);
     }
 
     static DataTreeCandidateNode deltaChild(
@@ -53,27 +36,23 @@ abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
             final NormalizedNode<?, ?> oldChild = maybeOldChild.get();
             if (maybeNewChild.isPresent()) {
                 return AbstractRecursiveCandidateNode.replaceNode(oldChild, maybeNewChild.get());
-            } else {
-                return TO_DELETED_NODE.apply(oldChild);
-            }
-        } else {
-            if (maybeNewChild.isPresent()) {
-                return TO_WRITTEN_NODE.apply(maybeNewChild.get());
-            } else {
-                return null;
             }
+            return AbstractRecursiveCandidateNode.deleteNode(oldChild);
         }
+
+        return maybeNewChild.isPresent() ? AbstractRecursiveCandidateNode.writeNode(maybeNewChild.get()) : null;
     }
 
-    static Collection<DataTreeCandidateNode> deltaChildren(@Nullable final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
+    static Collection<DataTreeCandidateNode> deltaChildren(
+            @Nullable final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
             @Nullable final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData) {
         Preconditions.checkArgument(newData != null || oldData != null,
                 "No old or new data, modification type should be NONE and deltaChildren() mustn't be called.");
         if (newData == null) {
-            return Collections2.transform(oldData.getValue(), TO_DELETED_NODE);
+            return Collections2.transform(oldData.getValue(), AbstractRecursiveCandidateNode::deleteNode);
         }
         if (oldData == null) {
-            return Collections2.transform(newData.getValue(), TO_WRITTEN_NODE);
+            return Collections2.transform(newData.getValue(), AbstractRecursiveCandidateNode::writeNode);
         }
 
         /*
@@ -117,7 +96,7 @@ abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
     }
 
     protected final Optional<NormalizedNode<?, ?>> dataOptional() {
-        return Optional.<NormalizedNode<?, ?>>of(data);
+        return Optional.of(data);
     }
 
     @Override
@@ -129,4 +108,9 @@ abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
     protected final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> getData() {
         return data;
     }
+
+    @Override
+    public String toString() {
+        return this.getClass().getSimpleName() + "{data = " + this.data + "}";
+    }
 }