Rework NormalizedNode type hierarchy
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / AbstractImmutableNormalizedNodeBuilder.java
index d33db494217b05a0b5c23d44c8db44292357d546..bd8618049cda438934e655901e7b305325e080e2 100644 (file)
@@ -7,47 +7,38 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
 
-import java.util.Collections;
-import java.util.Map;
-import org.opendaylight.yangtools.yang.common.QName;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
-
-abstract class AbstractImmutableNormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode<I, ?>>
-        implements NormalizedNodeAttrBuilder<I,V,R> {
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
 
-    private Map<QName, String> attributes = Collections.emptyMap();
-    private I nodeIdentifier;
-    private V value;
+abstract class AbstractImmutableNormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode>
+        implements NormalizedNodeBuilder<I, V, R> {
+    private @Nullable I nodeIdentifier = null;
+    private @Nullable V value = null;
 
     protected final I getNodeIdentifier() {
+        checkState(nodeIdentifier != null, "Identifier has not been set");
         return nodeIdentifier;
     }
 
     protected final V getValue() {
+        checkState(value != null, "Value has not been set");
         return value;
     }
 
-    protected final Map<QName, String> getAttributes() {
-        return attributes;
-    }
-
-    @Override
-    public NormalizedNodeAttrBuilder<I,V,R> withValue(final V value) {
-        this.value = value;
-        return this;
-    }
-
     @Override
-    public NormalizedNodeAttrBuilder<I,V,R> withNodeIdentifier(final I nodeIdentifier) {
-        this.nodeIdentifier = nodeIdentifier;
+    public NormalizedNodeBuilder<I, V, R> withValue(final V withValue) {
+        this.value = requireNonNull(withValue);
         return this;
     }
 
     @Override
-    public NormalizedNodeAttrBuilder<I,V,R> withAttributes(final Map<QName, String> attributes) {
-        this.attributes = attributes;
+    public NormalizedNodeBuilder<I, V, R> withNodeIdentifier(final I withNodeIdentifier) {
+        this.nodeIdentifier = requireNonNull(withNodeIdentifier);
         return this;
     }
 }