X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fimpl%2Fschema%2Fbuilder%2Fimpl%2FImmutableLeafSetNodeSchemaAwareBuilder.java;h=4c1d6419674b6e21eca935ce413d22c6eb309919;hb=1e24596294bdc2a57a808b77a2d9862198e4f46e;hp=e1a4eda76ae35bfa5de46780168489357f7a0b0f;hpb=98a61a559927859217fed0ece6385ba5965b874d;p=yangtools.git diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableLeafSetNodeSchemaAwareBuilder.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableLeafSetNodeSchemaAwareBuilder.java index e1a4eda76a..4c1d641967 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableLeafSetNodeSchemaAwareBuilder.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableLeafSetNodeSchemaAwareBuilder.java @@ -7,42 +7,64 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; + +import java.util.Collections; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder; +import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode; +import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException; import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; -import com.google.common.base.Preconditions; - public final class ImmutableLeafSetNodeSchemaAwareBuilder extends ImmutableLeafSetNodeBuilder { - private final LeafListSchemaNode schema; - private ImmutableLeafSetNodeSchemaAwareBuilder(LeafListSchemaNode schema) { - super(); - this.schema = schema; - super.withNodeIdentifier(new InstanceIdentifier.NodeIdentifier(schema.getQName())); + private ImmutableLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema) { + this.schema = requireNonNull(schema); + super.withNodeIdentifier(new NodeIdentifier(schema.getQName())); + } + + public ImmutableLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema, final ImmutableLeafSetNode node) { + super(node); + this.schema = requireNonNull(schema); + // FIXME: Preconditions.checkArgument(schema.getQName().equals(node.getIdentifier())); + super.withNodeIdentifier(new NodeIdentifier(schema.getQName())); } - public static ListNodeBuilder> create(LeafListSchemaNode schema) { + public static @NonNull ListNodeBuilder> create(final LeafListSchemaNode schema) { return new ImmutableLeafSetNodeSchemaAwareBuilder<>(schema); } + public static @NonNull ListNodeBuilder> create(final LeafListSchemaNode schema, + final SystemLeafSetNode node) { + if (!(node instanceof ImmutableLeafSetNode)) { + throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass())); + } + + return new ImmutableLeafSetNodeSchemaAwareBuilder<>(schema, (ImmutableLeafSetNode) node); + } + @Override - public ListNodeBuilder> withChildValue(T value) { + public ImmutableLeafSetNodeBuilder withChildValue(final T childValue) { // TODO check value type - return super.withChildValue(value); + return super.withChildValue(childValue); } @Override - public ListNodeBuilder> withChild(LeafSetEntryNode child) { - Preconditions.checkArgument(schema.getQName().equals(child.getNodeType()), + public ImmutableLeafSetNodeBuilder withChild(final LeafSetEntryNode child) { + checkArgument(schema.getQName().equals(child.getNodeType()), "Incompatible node type, should be: %s, is: %s", schema.getQName(), child.getNodeType()); + // TODO check value type using TypeProvider ? + DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(), + schema, Collections.singleton(schema.getQName())); return super.withChild(child); } @Override - public ListNodeBuilder> withNodeIdentifier(InstanceIdentifier.NodeIdentifier nodeIdentifier) { + public ImmutableLeafSetNodeBuilder withNodeIdentifier(final NodeIdentifier withNodeIdentifier) { throw new UnsupportedOperationException("Node identifier created from schema"); } }