Improve ImmutableAugmentationNodeBuilder defensiveness
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableLeafSetEntryNodeBuilder.java
index 219f58c522165d174f7dc662f3fcc5371939cdf6..f0068ece7896f4dada06183990b33b13d4446657 100644 (file)
@@ -7,31 +7,32 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
 
-import java.util.Map;
+import static com.google.common.base.Preconditions.checkArgument;
 
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import java.util.Objects;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedSimpleValueNode;
 
-import com.google.common.base.Preconditions;
+public class ImmutableLeafSetEntryNodeBuilder<T>
+        extends AbstractImmutableNormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> {
 
-public class ImmutableLeafSetEntryNodeBuilder<T> extends AbstractImmutableNormalizedNodeBuilder<YangInstanceIdentifier.NodeWithValue, T, LeafSetEntryNode<T>> {
-
-    public static <T> ImmutableLeafSetEntryNodeBuilder<T> create() {
+    public static <T> @NonNull ImmutableLeafSetEntryNodeBuilder<T> create() {
         return new ImmutableLeafSetEntryNodeBuilder<>();
     }
 
     @Override
     public LeafSetEntryNode<T> build() {
-        return new ImmutableLeafSetEntryNode<>(getNodeIdentifier(), getValue(), getAttributes());
+        return new ImmutableLeafSetEntryNode<>(getNodeIdentifier(), getValue());
     }
 
-    private static final class ImmutableLeafSetEntryNode<T> extends AbstractImmutableNormalizedValueAttrNode<YangInstanceIdentifier.NodeWithValue, T> implements LeafSetEntryNode<T> {
+    private static final class ImmutableLeafSetEntryNode<T>
+            extends AbstractImmutableNormalizedSimpleValueNode<NodeWithValue, T> implements LeafSetEntryNode<T> {
 
-        ImmutableLeafSetEntryNode(final YangInstanceIdentifier.NodeWithValue nodeIdentifier, final T value, final Map<QName, String> attributes) {
-            super(nodeIdentifier, value, attributes);
-            Preconditions.checkArgument(nodeIdentifier.getValue().equals(value),
+        ImmutableLeafSetEntryNode(final NodeWithValue nodeIdentifier, final T value) {
+            super(nodeIdentifier, value);
+            checkArgument(Objects.deepEquals(nodeIdentifier.getValue(), value),
                     "Node identifier contains different value: %s than value itself: %s", nodeIdentifier, value);
         }
     }