Use lambdas instead of anonymous classes
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / AbstractModifiedNodeBasedCandidateNode.java
index 876b2855a334456065121cda9d3fcab55363aa98..aa1ae48ceed8183951807beb85c1459f0eb757a1 100644 (file)
@@ -1,18 +1,18 @@
 /*
- * 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,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 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.base.Verify;
 import com.google.common.collect.Collections2;
 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;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -22,20 +22,12 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 
 abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandidateNode {
-
-    private static final Function<NormalizedNode<?, ?>, DataTreeCandidateNode> TO_UNMODIFIED_NODE = new Function<NormalizedNode<?, ?>, DataTreeCandidateNode>() {
-        @Override
-        public DataTreeCandidateNode apply(final NormalizedNode<?, ?> input) {
-            return AbstractRecursiveCandidateNode.unmodifiedNode(input);
-        }
-    };
-
     private final ModifiedNode mod;
     private final TreeNode newMeta;
     private final TreeNode oldMeta;
 
-    protected AbstractModifiedNodeBasedCandidateNode(final ModifiedNode mod,
-            final TreeNode oldMeta, final TreeNode newMeta) {
+    protected AbstractModifiedNodeBasedCandidateNode(final ModifiedNode mod, final TreeNode oldMeta,
+            final TreeNode newMeta) {
         this.newMeta = newMeta;
         this.oldMeta = oldMeta;
         this.mod = Preconditions.checkNotNull(mod);
@@ -82,22 +74,19 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
     }
 
     @Override
+    @Nonnull
     public Collection<DataTreeCandidateNode> getChildNodes() {
         switch (mod.getModificationType()) {
         case APPEARED:
         case DISAPPEARED:
         case SUBTREE_MODIFIED:
-            return Collections2.transform(mod.getChildren(), new Function<ModifiedNode, DataTreeCandidateNode>() {
-                @Override
-                public DataTreeCandidateNode apply(final ModifiedNode input) {
-                    return childNode(input);
-                }
-            });
+            return Collections2.transform(mod.getChildren(), this::childNode);
         case UNMODIFIED:
             // Unmodified node, but we still need to resolve potential children. canHaveChildren returns
             // false if both arguments are null.
             if (canHaveChildren(oldMeta, newMeta)) {
-                return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(), TO_UNMODIFIED_NODE);
+                return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(),
+                    AbstractRecursiveCandidateNode::unmodifiedNode);
             } else {
                 return Collections.emptyList();
             }
@@ -116,24 +105,27 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
     }
 
     @Override
+    @Nonnull
     public ModificationType getModificationType() {
         return Verify.verifyNotNull(mod.getModificationType(), "Node %s does not have resolved modification type", mod);
     }
 
     private static Optional<NormalizedNode<?, ?>> optionalData(final TreeNode meta) {
         if (meta != null) {
-            return Optional.<NormalizedNode<?,?>>of(meta.getData());
+            return Optional.of(meta.getData());
         } else {
             return Optional.absent();
         }
     }
 
     @Override
+    @Nonnull
     public final Optional<NormalizedNode<?, ?>> getDataAfter() {
         return optionalData(newMeta);
     }
 
     @Override
+    @Nonnull
     public final Optional<NormalizedNode<?, ?>> getDataBefore() {
         return optionalData(oldMeta);
     }
@@ -153,7 +145,7 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
             if (canHaveChildren(oldMeta, newMeta)) {
                 final Optional<NormalizedNode<?, ?>> maybeChild = getContainer(newMeta != null ? newMeta : oldMeta).getChild(identifier);
                 if (maybeChild.isPresent()) {
-                    return TO_UNMODIFIED_NODE.apply(maybeChild.get());
+                    return AbstractRecursiveCandidateNode.unmodifiedNode(maybeChild.get());
                 } else {
                     return null;
                 }
@@ -178,8 +170,15 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
         }
 
         @Override
+        @Nonnull
         public PathArgument getIdentifier() {
             return getMod().getIdentifier();
         }
     }
+
+    @Override
+    public String toString() {
+        return this.getClass().getSimpleName() + "{mod = " + this.mod + ", oldMeta = " + this.oldMeta + ", newMeta = " +
+                this.newMeta + "}";
+    }
 }