Introduce model.util.type package 61/28261/7
authorRobert Varga <robert.varga@pantheon.sk>
Sat, 10 Oct 2015 21:18:07 +0000 (23:18 +0200)
committerRobert Varga <robert.varga@pantheon.sk>
Thu, 15 Oct 2015 04:54:48 +0000 (06:54 +0200)
This package introduces new utility classes for implementing a
TypeDefinition hierarchy. The two entrypoints are RestrictedTypes and
DerivedTypes.

Change-Id: Icf0a91f09151c975a77461ee4488af1f5b300d27
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
69 files changed:
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractBaseType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractDerivedType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractIntegerBaseType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractLengthRestrictedType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRangeRestrictedType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRangedBaseType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRestrictedType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRestrictedTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractUnsignedBaseType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseBinaryType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseBitsType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseBooleanType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseDecimalType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseEmptyType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseEnumerationType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseIdentityrefType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInstanceIdentifierType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt16Type.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt32Type.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt64Type.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt8Type.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseLeafrefType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseStringType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseTypes.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint16Type.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint32Type.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint64Type.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint8Type.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUnionType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DecimalTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedBinaryType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedBitsType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedBooleanType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedDecimalType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedEmptyType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedEnumerationType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIdentityrefType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedInstanceIdentifierType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIntegerType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedLeafrefType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedStringType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypes.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedUnionType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedUnsignedType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/IdentityrefTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/InstanceIdentifierTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LeafrefTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LengthRestrictedTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RangeRestrictedTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBinaryType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBitsType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBooleanType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedDecimalType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedEmptyType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedEnumerationType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIdentityrefType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedInstanceIdentifierType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIntegerType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedLeafrefType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedStringType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedTypes.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedUnionType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedUnsignedType.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/StringTypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/TypeBuilder.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/UnionTypeBuilder.java [new file with mode: 0644]

diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractBaseType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractBaseType.java
new file mode 100644 (file)
index 0000000..5b5c287
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+
+abstract class AbstractBaseType<T extends TypeDefinition<T>> implements Immutable, TypeDefinition<T> {
+    private final List<UnknownSchemaNode> unknownSchemaNodes;
+    private final SchemaPath path;
+
+    AbstractBaseType(final QName qname) {
+        this(SchemaPath.create(true, qname), ImmutableList.<UnknownSchemaNode>of());
+    }
+
+    AbstractBaseType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes) {
+        this.path = Preconditions.checkNotNull(path);
+        this.unknownSchemaNodes = Preconditions.checkNotNull(unknownSchemaNodes);
+    }
+
+    @Override
+    public final T getBaseType() {
+        return null;
+    }
+
+    @Override
+    public final String getUnits() {
+        return null;
+    }
+
+    @Override
+    public final Object getDefaultValue() {
+        return null;
+    }
+
+    @Override
+    public final QName getQName() {
+        return path.getLastComponent();
+    }
+
+    @Override
+    public final SchemaPath getPath() {
+        return path;
+    }
+
+    @Override
+    public final String getDescription() {
+        return null;
+    }
+
+    @Override
+    public final String getReference() {
+        return null;
+    }
+
+    @Override
+    public final Status getStatus() {
+        return Status.CURRENT;
+    }
+
+    @Override
+    public final List<UnknownSchemaNode> getUnknownSchemaNodes() {
+        return unknownSchemaNodes;
+    }
+
+    @Override
+    public final String toString() {
+        return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
+    }
+
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return toStringHelper.add("path", path);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractDerivedType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractDerivedType.java
new file mode 100644 (file)
index 0000000..601afb5
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+
+abstract class AbstractDerivedType<T extends TypeDefinition<T>> implements Immutable, TypeDefinition<T> {
+    private final SchemaPath path;
+    private final T baseType;
+    private final Object defaultValue;
+    private final String description;
+    private final String reference;
+    private final Status status;
+    private final String units;
+    private final List<UnknownSchemaNode> unknownSchemNodes;
+
+    AbstractDerivedType(final T baseType, final SchemaPath path, final Object defaultValue, final String description,
+            final String reference, final Status status, final String units, final Collection<UnknownSchemaNode> unknownSchemNodes) {
+        this.baseType = Preconditions.checkNotNull(baseType);
+        this.path = Preconditions.checkNotNull(path);
+        this.status = Preconditions.checkNotNull(status);
+        this.defaultValue = defaultValue;
+        this.description = description;
+        this.reference = reference;
+        this.units = units;
+        this.unknownSchemNodes = ImmutableList.copyOf(unknownSchemNodes);
+    }
+
+    @Override
+    public final T getBaseType() {
+        return baseType;
+    }
+
+    @Override
+    public final Object getDefaultValue() {
+        return defaultValue != null ? defaultValue : baseType.getDefaultValue();
+    }
+
+    @Override
+    public final QName getQName() {
+        return path.getLastComponent();
+    }
+
+    @Override
+    public final SchemaPath getPath() {
+        return path;
+    }
+
+    @Override
+    public final List<UnknownSchemaNode> getUnknownSchemaNodes() {
+        return unknownSchemNodes;
+    }
+
+    @Override
+    public final String getDescription() {
+        return description;
+    }
+
+    @Override
+    public final String getReference() {
+        return reference;
+    }
+
+    @Override
+    public final Status getStatus() {
+        return status;
+    }
+
+    @Override
+    public final String getUnits() {
+        return units != null ? units : baseType.getUnits();
+    }
+
+    @Override
+    public final String toString() {
+        return MoreObjects.toStringHelper(this).omitNullValues().add("baseType", baseType).add("default", defaultValue)
+                .add("description", description).add("path", path).add("reference", reference).add("status", status)
+                .add("units", units).toString();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractIntegerBaseType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractIntegerBaseType.java
new file mode 100644 (file)
index 0000000..37c3821
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+
+abstract class AbstractIntegerBaseType extends AbstractRangedBaseType<IntegerTypeDefinition> implements IntegerTypeDefinition {
+    AbstractIntegerBaseType(final QName qname, final Number minValue, final Number maxValue) {
+        super(qname, minValue, maxValue);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractLengthRestrictedType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractLengthRestrictedType.java
new file mode 100644 (file)
index 0000000..bdc730f
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+
+abstract class AbstractLengthRestrictedType<T extends TypeDefinition<T>> extends AbstractRestrictedType<T> {
+    private final List<LengthConstraint> lengthConstraints;
+
+    AbstractLengthRestrictedType(final T baseType, final SchemaPath path,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes, final Collection<LengthConstraint> lengthConstraints) {
+        super(baseType, path, unknownSchemaNodes);
+        this.lengthConstraints = ImmutableList.copyOf(lengthConstraints);
+    }
+
+    public final List<LengthConstraint> getLengthConstraints() {
+        return lengthConstraints;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRangeRestrictedType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRangeRestrictedType.java
new file mode 100644 (file)
index 0000000..cf1f4d0
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+
+abstract class AbstractRangeRestrictedType<T extends TypeDefinition<T>> extends AbstractRestrictedType<T> {
+    private final List<RangeConstraint> rangeConstraints;
+
+    AbstractRangeRestrictedType(final T baseType, final SchemaPath path,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes, final Collection<RangeConstraint> rangeConstraints) {
+        super(baseType, path, unknownSchemaNodes);
+        this.rangeConstraints = ImmutableList.copyOf(rangeConstraints);
+    }
+
+    public final List<RangeConstraint> getRangeConstraints() {
+        return rangeConstraints;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRangedBaseType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRangedBaseType.java
new file mode 100644 (file)
index 0000000..37c708a
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+import org.opendaylight.yangtools.yang.model.util.BaseConstraints;
+
+abstract class AbstractRangedBaseType<T extends TypeDefinition<T>> extends AbstractBaseType<T> {
+    private final List<RangeConstraint> rangeConstraints;
+
+    AbstractRangedBaseType(final QName qname, final Number minValue, final Number maxValue) {
+        super(qname);
+        this.rangeConstraints = ImmutableList.<RangeConstraint>of(BaseConstraints.newRangeConstraint(
+                minValue, maxValue, Optional.<String>absent(), Optional.<String>absent()));
+    }
+
+    AbstractRangedBaseType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes,
+        final List<RangeConstraint> rangeConstraints) {
+        super(path, unknownSchemaNodes);
+        this.rangeConstraints = ImmutableList.copyOf(rangeConstraints);
+    }
+
+    public final List<RangeConstraint> getRangeConstraints() {
+        return rangeConstraints;
+    }
+
+    @Override
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return super.addToStringAttributes(toStringHelper).add("range", rangeConstraints);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRestrictedType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRestrictedType.java
new file mode 100644 (file)
index 0000000..03ae423
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+
+abstract class AbstractRestrictedType<T extends TypeDefinition<T>> implements Immutable, TypeDefinition<T> {
+    private final List<UnknownSchemaNode> unknownSchemaNodes;
+    private final T baseType;
+    private final SchemaPath path;
+
+    AbstractRestrictedType(final T baseType, final SchemaPath path, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        this.baseType = Preconditions.checkNotNull(baseType);
+        this.path = Preconditions.checkNotNull(path);
+        this.unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodes);
+    }
+
+    @Override
+    public final T getBaseType() {
+        return baseType;
+    }
+
+    @Override
+    public final String getUnits() {
+        return baseType.getUnits();
+    }
+
+    @Override
+    public final Object getDefaultValue() {
+        return baseType.getDefaultValue();
+    }
+
+    @Override
+    public final QName getQName() {
+        return path.getLastComponent();
+    }
+
+    @Override
+    public final SchemaPath getPath() {
+        return path;
+    }
+
+    @Override
+    public final List<UnknownSchemaNode> getUnknownSchemaNodes() {
+        return unknownSchemaNodes;
+    }
+
+    @Override
+    public final String getDescription() {
+        return baseType.getDescription();
+    }
+
+    @Override
+    public final String getReference() {
+        return baseType.getReference();
+    }
+
+    @Override
+    public final Status getStatus() {
+        return baseType.getStatus();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRestrictedTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRestrictedTypeBuilder.java
new file mode 100644 (file)
index 0000000..24822f5
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+
+abstract class AbstractRestrictedTypeBuilder<T extends TypeDefinition<T>> extends TypeBuilder<T> {
+    private boolean touched = false;
+
+    AbstractRestrictedTypeBuilder(final T baseType, final SchemaPath path) {
+        super(Preconditions.checkNotNull(baseType), path);
+    }
+
+    final void touch() {
+        touched = true;
+    }
+
+    abstract T buildType();
+
+    @Override
+    public final T build() {
+        if (!touched) {
+            return getBaseType();
+        }
+
+        return buildType();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractUnsignedBaseType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractUnsignedBaseType.java
new file mode 100644 (file)
index 0000000..27287fd
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+
+abstract class AbstractUnsignedBaseType extends AbstractRangedBaseType<UnsignedIntegerTypeDefinition>
+        implements UnsignedIntegerTypeDefinition {
+    AbstractUnsignedBaseType(final QName qname, final Number minValue, final Number maxValue) {
+        super(qname, minValue, maxValue);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseBinaryType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseBinaryType.java
new file mode 100644 (file)
index 0000000..f3f554f
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseBinaryType extends AbstractBaseType<BinaryTypeDefinition> implements BinaryTypeDefinition {
+    static final BaseBinaryType INSTANCE = new BaseBinaryType();
+
+    private BaseBinaryType() {
+        super(BaseTypes.BINARY_QNAME);
+    }
+
+    @Override
+    public List<LengthConstraint> getLengthConstraints() {
+        return ImmutableList.of();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseBitsType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseBitsType.java
new file mode 100644 (file)
index 0000000..055b37d
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
+
+final class BaseBitsType extends AbstractBaseType<BitsTypeDefinition> implements BitsTypeDefinition {
+    private final List<Bit> bits;
+
+    BaseBitsType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes, final Collection<Bit> bits) {
+        super(path, unknownSchemaNodes);
+        this.bits = ImmutableList.copyOf(bits);
+    }
+
+    @Override
+    public List<Bit> getBits() {
+        return bits;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseBooleanType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseBooleanType.java
new file mode 100644 (file)
index 0000000..a3d029e
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseBooleanType extends AbstractBaseType<BooleanTypeDefinition> implements BooleanTypeDefinition {
+    static final BaseBooleanType INSTANCE = new BaseBooleanType();
+
+    private BaseBooleanType() {
+        super(BaseTypes.BINARY_QNAME);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseDecimalType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseDecimalType.java
new file mode 100644 (file)
index 0000000..a34ec24
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import java.math.BigDecimal;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+import org.opendaylight.yangtools.yang.model.util.BaseConstraints;
+
+final class BaseDecimalType extends AbstractRangedBaseType<DecimalTypeDefinition> implements DecimalTypeDefinition {
+    private static final List<List<RangeConstraint>> IMPLICIT_RANGE_STATEMENTS;
+    static {
+        final Builder<List<RangeConstraint>> b = ImmutableList.builder();
+        b.add(createRangeConstraint("-922337203685477580.8", "922337203685477580.7"));
+        b.add(createRangeConstraint("-92233720368547758.08", "92233720368547758.07"));
+        b.add(createRangeConstraint("-9223372036854775.808", "9223372036854775.807"));
+        b.add(createRangeConstraint("-922337203685477.5808", "922337203685477.5807"));
+        b.add(createRangeConstraint("-92233720368547.75808", "92233720368547.75807"));
+        b.add(createRangeConstraint("-9223372036854.775808", "9223372036854.775807"));
+        b.add(createRangeConstraint("-922337203685.4775808", "922337203685.4775807"));
+        b.add(createRangeConstraint("-92233720368.54775808", "92233720368.54775807"));
+        b.add(createRangeConstraint("-9223372036.854775808", "9223372036.854775807"));
+        b.add(createRangeConstraint("-922337203.6854775808", "922337203.6854775807"));
+        b.add(createRangeConstraint("-92233720.36854775808", "92233720.36854775807"));
+        b.add(createRangeConstraint("-9223372.036854775808", "9223372.036854775807"));
+        b.add(createRangeConstraint("-922337.2036854775808", "922337.2036854775807"));
+        b.add(createRangeConstraint("-92233.72036854775808", "92233.72036854775807"));
+        b.add(createRangeConstraint("-9223.372036854775808", "9223.372036854775807"));
+        b.add(createRangeConstraint("-922.3372036854775808", "922.3372036854775807"));
+        b.add(createRangeConstraint("-92.23372036854775808", "92.23372036854775807"));
+        b.add(createRangeConstraint("-9.223372036854775808", "9.223372036854775807"));
+        IMPLICIT_RANGE_STATEMENTS = b.build();
+    }
+
+    private static List<RangeConstraint> createRangeConstraint(final String min, final String max) {
+        return ImmutableList.of(BaseConstraints.newRangeConstraint(new BigDecimal(min), new BigDecimal(max),
+            Optional.<String>absent(), Optional.of("https://tools.ietf.org/html/rfc6020#section-9.3.4")));
+    }
+
+    private final Integer fractionDigits;
+
+    BaseDecimalType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes, final Integer fractionDigits) {
+        super(path, unknownSchemaNodes, IMPLICIT_RANGE_STATEMENTS.get(fractionDigits - 1));
+        this.fractionDigits = fractionDigits;
+    }
+
+    @Override
+    public Integer getFractionDigits() {
+        return fractionDigits;
+    }
+
+    @Override
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return super.addToStringAttributes(toStringHelper).add("fractionDigits", fractionDigits);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseEmptyType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseEmptyType.java
new file mode 100644 (file)
index 0000000..b3e1982
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseEmptyType extends AbstractBaseType<EmptyTypeDefinition> implements EmptyTypeDefinition {
+    static final BaseEmptyType INSTANCE = new BaseEmptyType();
+
+    private BaseEmptyType() {
+        super(BaseTypes.EMPTY_QNAME);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseEnumerationType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseEnumerationType.java
new file mode 100644 (file)
index 0000000..acba86a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+
+final class BaseEnumerationType extends AbstractBaseType<EnumTypeDefinition> implements EnumTypeDefinition {
+    private final List<EnumPair> values;
+
+    BaseEnumerationType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes, final Collection<EnumPair> values) {
+        super(path, unknownSchemaNodes);
+        this.values = ImmutableList.copyOf(values);
+    }
+
+    @Override
+    public List<EnumPair> getValues() {
+        return values;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseIdentityrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseIdentityrefType.java
new file mode 100644 (file)
index 0000000..373c460
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+
+final class BaseIdentityrefType extends AbstractBaseType<IdentityrefTypeDefinition> implements IdentityrefTypeDefinition {
+    private final IdentitySchemaNode identity;
+
+    BaseIdentityrefType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes, final IdentitySchemaNode identity) {
+        super(path, unknownSchemaNodes);
+        this.identity = Preconditions.checkNotNull(identity);
+    }
+
+    @Override
+    public IdentitySchemaNode getIdentity() {
+        return identity;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInstanceIdentifierType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInstanceIdentifierType.java
new file mode 100644 (file)
index 0000000..466d008
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseInstanceIdentifierType extends AbstractBaseType<InstanceIdentifierTypeDefinition>
+        implements InstanceIdentifierTypeDefinition {
+    static final BaseInstanceIdentifierType INSTANCE = new BaseInstanceIdentifierType();
+
+    private BaseInstanceIdentifierType() {
+        super(BaseTypes.INSTANCE_IDENTIFIER_QNAME);
+    }
+
+    @Deprecated
+    @Override
+    public RevisionAwareXPath getPathStatement() {
+        throw new UnsupportedOperationException("API design error");
+    }
+
+    @Override
+    public boolean requireInstance() {
+        return false;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt16Type.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt16Type.java
new file mode 100644 (file)
index 0000000..dfc749a
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseInt16Type extends AbstractIntegerBaseType {
+    static final BaseInt16Type INSTANCE = new BaseInt16Type();
+
+    private BaseInt16Type() {
+        super(BaseTypes.INT16_QNAME, Short.MIN_VALUE, Short.MAX_VALUE);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt32Type.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt32Type.java
new file mode 100644 (file)
index 0000000..defb85d
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseInt32Type extends AbstractIntegerBaseType {
+    static final BaseInt32Type INSTANCE = new BaseInt32Type();
+
+    private BaseInt32Type() {
+        super(BaseTypes.INT32_QNAME, Integer.MIN_VALUE, Integer.MAX_VALUE);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt64Type.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt64Type.java
new file mode 100644 (file)
index 0000000..1b92d90
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseInt64Type extends AbstractIntegerBaseType {
+    static final BaseInt64Type INSTANCE = new BaseInt64Type();
+
+    private BaseInt64Type() {
+        super(BaseTypes.INT64_QNAME, Long.MIN_VALUE, Long.MAX_VALUE);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt8Type.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseInt8Type.java
new file mode 100644 (file)
index 0000000..748fb4e
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseInt8Type extends AbstractIntegerBaseType {
+    static final BaseInt8Type INSTANCE = new BaseInt8Type();
+
+    private BaseInt8Type() {
+        super(BaseTypes.INT8_QNAME, Byte.MIN_VALUE, Byte.MAX_VALUE);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseLeafrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseLeafrefType.java
new file mode 100644 (file)
index 0000000..db504be
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+
+final class BaseLeafrefType extends AbstractBaseType<LeafrefTypeDefinition> implements LeafrefTypeDefinition {
+    private final RevisionAwareXPath pathStatement;
+
+    BaseLeafrefType(final SchemaPath path, final RevisionAwareXPath pathStatement, final List<UnknownSchemaNode> unknownSchemaNodes) {
+        super(path, unknownSchemaNodes);
+        this.pathStatement = Preconditions.checkNotNull(pathStatement);
+    }
+
+    @Override
+    public RevisionAwareXPath getPathStatement() {
+        return pathStatement;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseStringType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseStringType.java
new file mode 100644 (file)
index 0000000..2db0125
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseStringType extends AbstractBaseType<StringTypeDefinition> implements StringTypeDefinition {
+    static final BaseStringType INSTANCE = new BaseStringType();
+
+    private BaseStringType() {
+        super(BaseTypes.STRING_QNAME);
+    }
+
+    @Override
+    public List<LengthConstraint> getLengthConstraints() {
+        return ImmutableList.of();
+    }
+
+    @Override
+    public List<PatternConstraint> getPatternConstraints() {
+        return ImmutableList.of();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseTypes.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseTypes.java
new file mode 100644 (file)
index 0000000..1da6f3a
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+
+/**
+ * Utility access methods for creating and accessing YANG base type definitions. YANG types come in two basic variants,
+ * depending on whether they fully define their base instance or model input is required to fully-form the type.
+ *
+ * The following types have their base type fully specified and are exposed as appropriate TypeDefinition sub-interfaces:
+ * <ul>
+ *     <li>boolean</li>
+ *     <li>empty</li>
+ *     <li>binary</li>
+ *     <li>int{8,16,32,64}</li>
+ *     <li>string</li>
+ *     <li>uint{8,16,32,64}</li>
+ * </ul>
+ *
+ * The following types require additional specification in the model and are exposed by means of a specialized
+ * {@link TypeBuilder}s for each type:
+ * <ul>
+ *    <li>decimal64</li>
+ *    <li>instance-identifier</li>
+ *    <li>enumeration</li>
+ *    <li>identityref</li>
+ *    <li>leafref</li>
+ *    <li>union</li>
+ * </ul>
+ */
+@Beta
+public final class BaseTypes {
+    private BaseTypes() {
+        throw new UnsupportedOperationException();
+    }
+
+    public static BinaryTypeDefinition binaryType() {
+        return BaseBinaryType.INSTANCE;
+    }
+
+    public static BitsTypeBuilder bitsTypeBuilder(final SchemaPath path) {
+        return new BitsTypeBuilder(path);
+    }
+
+    public static BooleanTypeDefinition booleanType() {
+        return BaseBooleanType.INSTANCE;
+    }
+
+    public static DecimalTypeBuilder decimalTypeBuilder(final SchemaPath path) {
+        return new DecimalTypeBuilder(path);
+    }
+
+    public static EmptyTypeDefinition emptyType() {
+        return BaseEmptyType.INSTANCE;
+    }
+
+    public static EnumerationTypeBuilder enumerationTypeBuilder(final SchemaPath path) {
+        return new EnumerationTypeBuilder(path);
+    }
+
+    public static IdentityrefTypeBuilder identityrefTypeBuilder(final SchemaPath path) {
+        return new IdentityrefTypeBuilder(path);
+    }
+
+    public static InstanceIdentifierTypeDefinition instanceIdentifierType() {
+        return BaseInstanceIdentifierType.INSTANCE;
+    }
+
+    public static IntegerTypeDefinition int8Type() {
+        return BaseInt8Type.INSTANCE;
+    }
+
+    public static IntegerTypeDefinition int16Type() {
+        return BaseInt16Type.INSTANCE;
+    }
+
+    public static IntegerTypeDefinition int32Type() {
+        return BaseInt32Type.INSTANCE;
+    }
+
+    public static IntegerTypeDefinition int64Type() {
+        return BaseInt64Type.INSTANCE;
+    }
+
+    public static LeafrefTypeBuilder leafrefTypeBuilder(final SchemaPath path) {
+        return new LeafrefTypeBuilder(path);
+    }
+
+    public static StringTypeDefinition stringType() {
+        return BaseStringType.INSTANCE;
+    }
+
+    public static UnionTypeBuilder unionTypeBuilder(final SchemaPath path) {
+        return new UnionTypeBuilder(path);
+    }
+
+    public static UnsignedIntegerTypeDefinition uint8Type() {
+        return BaseUint8Type.INSTANCE;
+    }
+
+    public static UnsignedIntegerTypeDefinition uint16Type() {
+        return BaseUint16Type.INSTANCE;
+    }
+
+    public static UnsignedIntegerTypeDefinition uint32Type() {
+        return BaseUint32Type.INSTANCE;
+    }
+
+    public static UnsignedIntegerTypeDefinition uint64Type() {
+        return BaseUint64Type.INSTANCE;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint16Type.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint16Type.java
new file mode 100644 (file)
index 0000000..79e2350
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseUint16Type extends AbstractUnsignedBaseType {
+    static final BaseUint16Type INSTANCE = new BaseUint16Type();
+
+    private BaseUint16Type() {
+        super(BaseTypes.UINT16_QNAME, 0, 65535);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint32Type.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint32Type.java
new file mode 100644 (file)
index 0000000..898ebd5
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseUint32Type extends AbstractUnsignedBaseType {
+    static final BaseUint32Type INSTANCE = new BaseUint32Type();
+
+    private BaseUint32Type() {
+        super(BaseTypes.UINT32_QNAME, 0L, 4294967295L);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint64Type.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint64Type.java
new file mode 100644 (file)
index 0000000..12db4b1
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.math.BigInteger;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseUint64Type extends AbstractUnsignedBaseType {
+    static final BaseUint64Type INSTANCE = new BaseUint64Type();
+
+    private BaseUint64Type() {
+        super(BaseTypes.UINT64_QNAME, BigInteger.ZERO, new BigInteger("18446744073709551615"));
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint8Type.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUint8Type.java
new file mode 100644 (file)
index 0000000..02532ba
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+
+final class BaseUint8Type extends AbstractUnsignedBaseType {
+    static final BaseUint8Type INSTANCE = new BaseUint8Type();
+
+    private BaseUint8Type() {
+        super(BaseTypes.UINT8_QNAME, (short)0, (short)255);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUnionType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUnionType.java
new file mode 100644 (file)
index 0000000..23f4476
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+
+final class BaseUnionType extends AbstractBaseType<UnionTypeDefinition> implements UnionTypeDefinition {
+    private final List<TypeDefinition<?>> types;
+
+    BaseUnionType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes, final Collection<TypeDefinition<?>> types) {
+        super(path, unknownSchemaNodes);
+        this.types = ImmutableList.copyOf(types);
+    }
+
+    @Override
+    public List<TypeDefinition<?>> getTypes() {
+        return types;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java
new file mode 100644 (file)
index 0000000..afa744a
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
+
+public final class BitsTypeBuilder extends TypeBuilder<BitsTypeDefinition> {
+    private final Builder<String, Bit> builder = ImmutableMap.builder();
+
+    BitsTypeBuilder(final SchemaPath path) {
+        super(null, path);
+    }
+
+    public void addBit(@Nonnull final Bit item) {
+        builder.put(item.getName(), item);
+    }
+
+    @Override
+    public BitsTypeDefinition build() {
+        final Map<String, Bit> map = builder.build();
+
+        // FIXME: run null position checks and re-generate Bit items as appropriate
+
+        return new BaseBitsType(getPath(), getUnknownSchemaNodes(), map.values());
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DecimalTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DecimalTypeBuilder.java
new file mode 100644 (file)
index 0000000..8d8125e
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+
+public final class DecimalTypeBuilder extends TypeBuilder<DecimalTypeDefinition> {
+    private Integer fractionDigits;
+
+    DecimalTypeBuilder(final SchemaPath path) {
+        super(null, path);
+    }
+
+    public DecimalTypeBuilder setFractionDigits(final int fractionDigits) {
+        Preconditions.checkState(this.fractionDigits == null, "Fraction digits already defined to %s",
+                this.fractionDigits);
+        this.fractionDigits = fractionDigits;
+        return this;
+    }
+
+    @Override
+    public BaseDecimalType build() {
+        Preconditions.checkState(fractionDigits != null, "Fraction digits not defined");
+        return new BaseDecimalType(getPath(), getUnknownSchemaNodes(), fractionDigits);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedBinaryType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedBinaryType.java
new file mode 100644 (file)
index 0000000..6eb196c
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+
+final class DerivedBinaryType extends AbstractDerivedType<BinaryTypeDefinition> implements BinaryTypeDefinition {
+    DerivedBinaryType(final BinaryTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
+            final String description, final String reference, final Status status, final String units,
+            final Collection<UnknownSchemaNode> unknownSchemNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemNodes);
+    }
+
+    @Override
+    public List<LengthConstraint> getLengthConstraints() {
+        return getBaseType().getLengthConstraints();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedBitsType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedBitsType.java
new file mode 100644 (file)
index 0000000..fab4135
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
+
+final class DerivedBitsType extends AbstractDerivedType<BitsTypeDefinition> implements BitsTypeDefinition {
+    DerivedBitsType(final BitsTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
+        final String description, final String reference, final Status status, final String units,
+        final Collection<UnknownSchemaNode> unknownSchemNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemNodes);
+    }
+
+    @Override
+    public List<Bit> getBits() {
+        return getBaseType().getBits();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedBooleanType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedBooleanType.java
new file mode 100644 (file)
index 0000000..6f100fd
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
+
+final class DerivedBooleanType extends AbstractDerivedType<BooleanTypeDefinition> implements BooleanTypeDefinition {
+    DerivedBooleanType(final BooleanTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
+        final String description, final String reference, final Status status, final String units,
+        final Collection<UnknownSchemaNode> unknownSchemNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemNodes);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedDecimalType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedDecimalType.java
new file mode 100644 (file)
index 0000000..01ae973
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+
+final class DerivedDecimalType extends AbstractDerivedType<DecimalTypeDefinition> implements DecimalTypeDefinition {
+    DerivedDecimalType(final DecimalTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
+        final String description, final String reference, final Status status, final String units,
+        final Collection<UnknownSchemaNode> unknownSchemNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemNodes);
+    }
+
+    @Override
+    public Integer getFractionDigits() {
+        return getBaseType().getFractionDigits();
+    }
+
+    @Override
+    public List<RangeConstraint> getRangeConstraints() {
+        return getBaseType().getRangeConstraints();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedEmptyType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedEmptyType.java
new file mode 100644 (file)
index 0000000..ed88513
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+
+final class DerivedEmptyType extends AbstractDerivedType<EmptyTypeDefinition> implements EmptyTypeDefinition {
+    DerivedEmptyType(final EmptyTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
+        final String description, final String reference, final Status status, final String units,
+        final Collection<UnknownSchemaNode> unknownSchemNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemNodes);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedEnumerationType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedEnumerationType.java
new file mode 100644 (file)
index 0000000..a8924d4
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+
+final class DerivedEnumerationType extends AbstractDerivedType<EnumTypeDefinition> implements EnumTypeDefinition {
+    DerivedEnumerationType(final EnumTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
+        final String description, final String reference, final Status status, final String units,
+        final Collection<UnknownSchemaNode> unknownSchemNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemNodes);
+    }
+
+    @Override
+    public List<EnumPair> getValues() {
+        return getBaseType().getValues();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIdentityrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIdentityrefType.java
new file mode 100644 (file)
index 0000000..6e32671
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+
+final class DerivedIdentityrefType extends AbstractDerivedType<IdentityrefTypeDefinition> implements IdentityrefTypeDefinition {
+    DerivedIdentityrefType(final IdentityrefTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
+        final String description, final String reference, final Status status, final String units,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
+    }
+
+    @Override
+    public IdentitySchemaNode getIdentity() {
+        return getBaseType().getIdentity();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedInstanceIdentifierType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedInstanceIdentifierType.java
new file mode 100644 (file)
index 0000000..8b13813
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
+
+final class DerivedInstanceIdentifierType extends AbstractDerivedType<InstanceIdentifierTypeDefinition> implements InstanceIdentifierTypeDefinition {
+    private final boolean requireInstance;
+
+    DerivedInstanceIdentifierType(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
+        final String description, final String reference, final Status status, final String units,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes,  final boolean requireInstance) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
+        this.requireInstance = requireInstance;
+    }
+
+    @Deprecated
+    @Override
+    public RevisionAwareXPath getPathStatement() {
+        throw new UnsupportedOperationException("API design mistake");
+    }
+
+    @Override
+    public boolean requireInstance() {
+        return requireInstance;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIntegerType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIntegerType.java
new file mode 100644 (file)
index 0000000..9efc5fb
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+
+final class DerivedIntegerType extends AbstractDerivedType<IntegerTypeDefinition> implements IntegerTypeDefinition {
+    DerivedIntegerType(final IntegerTypeDefinition baseType, final SchemaPath path, final Object defaultValue, final String description,
+            final String reference, final Status status, final String units, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
+    }
+
+    @Override
+    public List<RangeConstraint> getRangeConstraints() {
+        return getBaseType().getRangeConstraints();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedLeafrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedLeafrefType.java
new file mode 100644 (file)
index 0000000..fce65e7
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+
+final class DerivedLeafrefType extends AbstractDerivedType<LeafrefTypeDefinition> implements LeafrefTypeDefinition {
+    DerivedLeafrefType(final LeafrefTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
+        final String description, final String reference, final Status status, final String units,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
+    }
+
+    @Override
+    public RevisionAwareXPath getPathStatement() {
+        return getBaseType().getPathStatement();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedStringType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedStringType.java
new file mode 100644 (file)
index 0000000..b527929
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
+
+final class DerivedStringType extends AbstractDerivedType<StringTypeDefinition> implements StringTypeDefinition {
+    DerivedStringType(final StringTypeDefinition baseType, final SchemaPath path, final Object defaultValue, final String description,
+            final String reference, final Status status, final String units, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
+    }
+
+    @Override
+    public List<PatternConstraint> getPatternConstraints() {
+        return getBaseType().getPatternConstraints();
+    }
+
+    @Override
+    public List<LengthConstraint> getLengthConstraints() {
+        return getBaseType().getLengthConstraints();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypeBuilder.java
new file mode 100644 (file)
index 0000000..d90d1d8
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+
+public abstract class DerivedTypeBuilder<T extends TypeDefinition<T>> extends TypeBuilder<T> {
+    private Object defaultValue;
+    private String description;
+    private String reference;
+    private Status status = Status.CURRENT;
+    private String units;
+
+    DerivedTypeBuilder(final T baseType, final SchemaPath path) {
+        super(Preconditions.checkNotNull(baseType), path);
+    }
+
+    public void setDefaultValue(@Nonnull final Object defaultValue) {
+        this.defaultValue = Preconditions.checkNotNull(defaultValue);
+    }
+
+    public final void setDescription(@Nonnull final String description) {
+        this.description = Preconditions.checkNotNull(description);
+    }
+
+    public final void setReference(@Nonnull final String reference) {
+        this.reference = Preconditions.checkNotNull(reference);
+    }
+
+    public final void setStatus(@Nonnull final Status status) {
+        this.status = Preconditions.checkNotNull(status);
+    }
+
+    public final void setUnits(final String units) {
+        this.units = Preconditions.checkNotNull(units);
+    }
+
+    final Object getDefaultValue() {
+        return defaultValue;
+    }
+
+    final String getDescription() {
+        return description;
+    }
+
+    final String getReference() {
+        return reference;
+    }
+
+    final Status getStatus() {
+        return status;
+    }
+
+    final String getUnits() {
+        return units;
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypes.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypes.java
new file mode 100644 (file)
index 0000000..27ae372
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+
+/**
+ * YANG defines 'derived type' as a type created through a 'typedef' statement. These types are exposed in the
+ * hierarchical namespace and can be looked up.
+ *
+ * A derived type can redefine the default value, description, status and reference of a particular type definition.
+ * It can only refine the units attribute, as that attribute is tied to the semantics of the value. The default value,
+ * and units attributes are inherited from the super (base or restricted) type, others are left undefined if not
+ * explicitly set. Status defaults to current.
+ */
+/*
+ * FIXME: Create ConcreteTypes
+ *        Leaf and leaf-list statements provide for a similar mechanism by which a particular type is changed, most
+ *        notably with the ability to redefine the default type. The resulting types could conceivably be called
+ *        'concrete types', as they cannot be referenced by another leaf or type definition. This aspect needs to be
+ *        split out into a 'ConcreteTypes' class.
+ *
+ *        Builders should use the fly-weight pattern to minimize footprint for cases when leaves do not override any
+ *        aspect of the base type.
+ */
+@Beta
+public final class DerivedTypes {
+    private DerivedTypes() {
+        throw new UnsupportedOperationException();
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T extends TypeDefinition<T>> DerivedTypeBuilder<T> derivedTypeBuilder(@Nonnull final T baseType,
+            @Nonnull final SchemaPath path) {
+        if (baseType instanceof BinaryTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedBinaryBuilder((BinaryTypeDefinition) baseType, path);
+        } else if (baseType instanceof BitsTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedBitsBuilder((BitsTypeDefinition) baseType, path);
+        } else if (baseType instanceof BooleanTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedBooleanBuilder((BooleanTypeDefinition) baseType, path);
+        } else if (baseType instanceof DecimalTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedDecimalBuilder((DecimalTypeDefinition) baseType, path);
+        } else if (baseType instanceof EmptyTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedEmptyBuilder((EmptyTypeDefinition) baseType, path);
+        } else if (baseType instanceof EnumTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedEnumerationBuilder((EnumTypeDefinition) baseType, path);
+        } else if (baseType instanceof IdentityrefTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedIdentityrefBuilder((IdentityrefTypeDefinition) baseType, path);
+        } else if (baseType instanceof InstanceIdentifierTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedInstanceIdentifierBuilder((InstanceIdentifierTypeDefinition) baseType, path);
+        } else if (baseType instanceof IntegerTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedIntegerBuilder((IntegerTypeDefinition) baseType, path);
+        } else if (baseType instanceof LeafrefTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedLeafrefBuilder((LeafrefTypeDefinition) baseType, path);
+        } else if (baseType instanceof StringTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedStringBuilder((StringTypeDefinition) baseType, path);
+        } else if (baseType instanceof UnionTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedUnionBuilder((UnionTypeDefinition) baseType, path);
+        } else if (baseType instanceof UnsignedIntegerTypeDefinition) {
+            return (DerivedTypeBuilder<T>) derivedUnsignedBuilder((UnsignedIntegerTypeDefinition) baseType, path);
+        } else {
+            throw new IllegalArgumentException("Unhandled type definition class " + baseType.getClass());
+        }
+    }
+
+    public static DerivedTypeBuilder<BinaryTypeDefinition> derivedBinaryBuilder(@Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) {
+        return new DerivedTypeBuilder<BinaryTypeDefinition>(baseType, path) {
+            @Override
+            public BinaryTypeDefinition build() {
+                return new DerivedBinaryType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<BitsTypeDefinition> derivedBitsBuilder(final BitsTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<BitsTypeDefinition>(baseType, path) {
+            @Override
+            public BitsTypeDefinition build() {
+                return new DerivedBitsType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<BooleanTypeDefinition> derivedBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) {
+        return new DerivedTypeBuilder<BooleanTypeDefinition>(baseType, path) {
+            @Override
+            public BooleanTypeDefinition build() {
+                return new DerivedBooleanType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<DecimalTypeDefinition> derivedDecimalBuilder(final DecimalTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<DecimalTypeDefinition>(baseType, path) {
+            @Override
+            public DecimalTypeDefinition build() {
+                return new DerivedDecimalType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<EmptyTypeDefinition> derivedEmptyBuilder(final EmptyTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<EmptyTypeDefinition>(baseType, path) {
+            @Override
+            public EmptyTypeDefinition build() {
+                return new DerivedEmptyType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<EnumTypeDefinition> derivedEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<EnumTypeDefinition>(baseType, path) {
+            @Override
+            public EnumTypeDefinition build() {
+                return new DerivedEnumerationType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<IdentityrefTypeDefinition> derivedIdentityrefBuilder(final IdentityrefTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<IdentityrefTypeDefinition>(baseType, path) {
+            @Override
+            public IdentityrefTypeDefinition build() {
+                return new DerivedIdentityrefType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<InstanceIdentifierTypeDefinition> derivedInstanceIdentifierBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<InstanceIdentifierTypeDefinition>(baseType, path) {
+            @Override
+            public InstanceIdentifierTypeDefinition build() {
+                return new DerivedInstanceIdentifierType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes(), baseType.requireInstance());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<IntegerTypeDefinition> derivedIntegerBuilder(final IntegerTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<IntegerTypeDefinition>(baseType, path) {
+            @Override
+            public IntegerTypeDefinition build() {
+                return new DerivedIntegerType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<LeafrefTypeDefinition> derivedLeafrefBuilder(final LeafrefTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<LeafrefTypeDefinition>(baseType, path) {
+            @Override
+            public LeafrefTypeDefinition build() {
+                return new DerivedLeafrefType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<StringTypeDefinition> derivedStringBuilder(final StringTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<StringTypeDefinition>(baseType, path) {
+            @Override
+            public StringTypeDefinition build() {
+                return new DerivedStringType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<UnionTypeDefinition> derivedUnionBuilder(final UnionTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<UnionTypeDefinition>(baseType, path) {
+            @Override
+            public DerivedUnionType build() {
+                return new DerivedUnionType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static DerivedTypeBuilder<UnsignedIntegerTypeDefinition> derivedUnsignedBuilder(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) {
+        return new DerivedTypeBuilder<UnsignedIntegerTypeDefinition>(baseType, path) {
+            @Override
+            public UnsignedIntegerTypeDefinition build() {
+                return new DerivedUnsignedType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(),
+                    getStatus(), getUnits(), getUnknownSchemaNodes());
+            }
+        };
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedUnionType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedUnionType.java
new file mode 100644 (file)
index 0000000..5546769
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+
+final class DerivedUnionType extends AbstractDerivedType<UnionTypeDefinition> implements UnionTypeDefinition {
+    DerivedUnionType(final UnionTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
+        final String description, final String reference, final Status status, final String units,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
+    }
+
+    @Override
+    public List<TypeDefinition<?>> getTypes() {
+        return getBaseType().getTypes();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedUnsignedType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedUnsignedType.java
new file mode 100644 (file)
index 0000000..9240c03
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+
+final class DerivedUnsignedType extends AbstractDerivedType<UnsignedIntegerTypeDefinition>
+        implements UnsignedIntegerTypeDefinition {
+
+    DerivedUnsignedType(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path,
+            final Object defaultValue, final String description, final String reference, final Status status,
+            final String units, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
+    }
+
+    @Override
+    public List<RangeConstraint> getRangeConstraints() {
+        return getBaseType().getRangeConstraints();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java
new file mode 100644 (file)
index 0000000..46f1aa0
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
+
+public final class EnumerationTypeBuilder extends TypeBuilder<EnumTypeDefinition> {
+    private final Builder<String, EnumPair> builder = ImmutableMap.builder();
+
+    EnumerationTypeBuilder(final SchemaPath path) {
+        super(null, path);
+    }
+
+    public void addEnum(@Nonnull final EnumPair item) {
+        builder.put(item.getName(), item);
+    }
+
+    @Override
+    public EnumTypeDefinition build() {
+        final Map<String, EnumPair> map = builder.build();
+
+        // FIXME: run null value checks and re-generate EnumPairs as appropriate
+
+        return new BaseEnumerationType(getPath(), getUnknownSchemaNodes(), map.values());
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/IdentityrefTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/IdentityrefTypeBuilder.java
new file mode 100644 (file)
index 0000000..78c5693
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+
+public final class IdentityrefTypeBuilder extends TypeBuilder<IdentityrefTypeDefinition> {
+    private IdentitySchemaNode identity;
+
+    IdentityrefTypeBuilder(final SchemaPath path) {
+        super(null, path);
+    }
+
+    public void setIdentity(@Nonnull final IdentitySchemaNode identity) {
+        Preconditions.checkState(identity == null, "Identity already set to %s", identity);
+        this.identity = Preconditions.checkNotNull(identity);
+    }
+
+    @Override
+    public BaseIdentityrefType build() {
+        return new BaseIdentityrefType(getPath(), getUnknownSchemaNodes(), identity);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/InstanceIdentifierTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/InstanceIdentifierTypeBuilder.java
new file mode 100644 (file)
index 0000000..20a3c7e
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
+
+public final class InstanceIdentifierTypeBuilder extends AbstractRestrictedTypeBuilder<InstanceIdentifierTypeDefinition> {
+    private boolean requireInstance;
+
+    InstanceIdentifierTypeBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
+        super(Preconditions.checkNotNull(baseType), path);
+        this.requireInstance = baseType.requireInstance();
+    }
+
+    public void setRequireInstance(final boolean requireInstance) {
+        if (this.requireInstance) {
+            Preconditions.checkArgument(!requireInstance, "Cannot switch require-instance off in type %s", getPath());
+        }
+
+        this.requireInstance = requireInstance;
+        touch();
+    }
+
+    @Override
+    InstanceIdentifierTypeDefinition buildType() {
+        if (requireInstance == getBaseType().requireInstance()) {
+            return getBaseType();
+        }
+
+        return new RestrictedInstanceIdentifierType(getBaseType(), getPath(), getUnknownSchemaNodes(), requireInstance);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LeafrefTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LeafrefTypeBuilder.java
new file mode 100644 (file)
index 0000000..be63da0
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+
+public final class LeafrefTypeBuilder extends TypeBuilder<LeafrefTypeDefinition> {
+    private RevisionAwareXPath pathStatement;
+
+    LeafrefTypeBuilder(final SchemaPath path) {
+        super(null, path);
+    }
+
+    public void setPathStatement(@Nonnull final RevisionAwareXPath pathStatement) {
+        Preconditions.checkState(pathStatement == null, "Path statement already set to %s", pathStatement);
+        this.pathStatement = Preconditions.checkNotNull(pathStatement);
+    }
+
+    @Override
+    public BaseLeafrefType build() {
+        return new BaseLeafrefType(getPath(), pathStatement, getUnknownSchemaNodes());
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LengthRestrictedTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LengthRestrictedTypeBuilder.java
new file mode 100644 (file)
index 0000000..57cccbf
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import java.util.Collection;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+
+public abstract class LengthRestrictedTypeBuilder<T extends TypeDefinition<T>> extends AbstractRestrictedTypeBuilder<T> {
+    private Collection<LengthConstraint> lengthAlternatives;
+
+    LengthRestrictedTypeBuilder(final T baseType, final SchemaPath path) {
+        super(Preconditions.checkNotNull(baseType), path);
+    }
+
+    public final void setLengthAlternatives(@Nonnull final Collection<LengthConstraint> lengthAlternatives) {
+        Preconditions.checkState(this.lengthAlternatives == null, "Range alternatives already defined as %s",
+                lengthAlternatives);
+        this.lengthAlternatives = Preconditions.checkNotNull(lengthAlternatives);
+        touch();
+    }
+
+    final List<LengthConstraint> calculateLenghtConstraints(final List<LengthConstraint> baseLengthConstraints) {
+        if (lengthAlternatives == null || lengthAlternatives.isEmpty()) {
+            return baseLengthConstraints;
+        }
+
+        // FIXME: calculate lengths
+        throw new UnsupportedOperationException();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RangeRestrictedTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RangeRestrictedTypeBuilder.java
new file mode 100644 (file)
index 0000000..e9bdd2c
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import java.util.Collection;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+
+public abstract class RangeRestrictedTypeBuilder<T extends TypeDefinition<T>> extends AbstractRestrictedTypeBuilder<T> {
+    private Collection<RangeConstraint> rangeAlternatives;
+
+    RangeRestrictedTypeBuilder(final T baseType, final SchemaPath path) {
+        super(Preconditions.checkNotNull(baseType), path);
+    }
+
+    public void setRangeAlternatives(@Nonnull final Collection<RangeConstraint> rangeAlternatives) {
+        Preconditions.checkState(this.rangeAlternatives == null, "Range alternatives already defined as %s",
+                this.rangeAlternatives);
+        this.rangeAlternatives = Preconditions.checkNotNull(rangeAlternatives);
+        touch();
+    }
+
+    final List<RangeConstraint> calculateRangeConstraints(final List<RangeConstraint> baseRangeConstraints) {
+        if (rangeAlternatives == null || rangeAlternatives.isEmpty()) {
+            return baseRangeConstraints;
+        }
+
+        // FIXME: calculate ranges
+        throw new UnsupportedOperationException();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBinaryType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBinaryType.java
new file mode 100644 (file)
index 0000000..4cbed79
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+
+final class RestrictedBinaryType extends AbstractLengthRestrictedType<BinaryTypeDefinition> implements BinaryTypeDefinition {
+    RestrictedBinaryType(final BinaryTypeDefinition baseType, final SchemaPath path,
+            final Collection<UnknownSchemaNode> unknownSchemaNodes,
+            final Collection<LengthConstraint> lengthConstraints) {
+        super(baseType, path, unknownSchemaNodes, lengthConstraints);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBitsType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBitsType.java
new file mode 100644 (file)
index 0000000..ea29712
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
+
+final class RestrictedBitsType extends AbstractRestrictedType<BitsTypeDefinition> implements BitsTypeDefinition {
+    RestrictedBitsType(final BitsTypeDefinition baseType, final SchemaPath path,
+            final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, unknownSchemaNodes);
+    }
+
+    @Override
+    public List<Bit> getBits() {
+        return getBaseType().getBits();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBooleanType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBooleanType.java
new file mode 100644 (file)
index 0000000..782b17e
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
+
+final class RestrictedBooleanType extends AbstractRestrictedType<BooleanTypeDefinition> implements BooleanTypeDefinition {
+    RestrictedBooleanType(final BooleanTypeDefinition baseType, final SchemaPath path,
+            final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, unknownSchemaNodes);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedDecimalType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedDecimalType.java
new file mode 100644 (file)
index 0000000..86c6d87
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+
+final class RestrictedDecimalType extends AbstractRangeRestrictedType<DecimalTypeDefinition>
+        implements DecimalTypeDefinition {
+    RestrictedDecimalType(final DecimalTypeDefinition baseType, final SchemaPath path,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes, final Collection<RangeConstraint> rangeConstraints) {
+        super(baseType, path, unknownSchemaNodes, rangeConstraints);
+    }
+
+    @Override
+    public Integer getFractionDigits() {
+        return getBaseType().getFractionDigits();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedEmptyType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedEmptyType.java
new file mode 100644 (file)
index 0000000..08446d8
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+
+final class RestrictedEmptyType extends AbstractRestrictedType<EmptyTypeDefinition> implements EmptyTypeDefinition {
+    RestrictedEmptyType(final EmptyTypeDefinition baseType, final SchemaPath path,
+            final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, unknownSchemaNodes);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedEnumerationType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedEnumerationType.java
new file mode 100644 (file)
index 0000000..bc6f34d
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+
+final class RestrictedEnumerationType extends AbstractRestrictedType<EnumTypeDefinition> implements EnumTypeDefinition {
+    RestrictedEnumerationType(final EnumTypeDefinition baseType, final SchemaPath path,
+            final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, unknownSchemaNodes);
+    }
+
+    @Override
+    public List<EnumPair> getValues() {
+        return getBaseType().getValues();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIdentityrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIdentityrefType.java
new file mode 100644 (file)
index 0000000..edc09ff
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+
+final class RestrictedIdentityrefType extends AbstractRestrictedType<IdentityrefTypeDefinition> implements IdentityrefTypeDefinition {
+    RestrictedIdentityrefType(final IdentityrefTypeDefinition baseType, final SchemaPath path,
+            final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, unknownSchemaNodes);
+    }
+
+    @Override
+    public IdentitySchemaNode getIdentity() {
+        return getBaseType().getIdentity();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedInstanceIdentifierType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedInstanceIdentifierType.java
new file mode 100644 (file)
index 0000000..51ae0c3
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
+
+final class RestrictedInstanceIdentifierType extends AbstractRestrictedType<InstanceIdentifierTypeDefinition>
+        implements InstanceIdentifierTypeDefinition {
+    private final boolean requireInstance;
+
+    RestrictedInstanceIdentifierType(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes, final boolean requireInstance) {
+        super(baseType, path, unknownSchemaNodes);
+        this.requireInstance = requireInstance;
+    }
+
+    @Deprecated
+    @Override
+    public RevisionAwareXPath getPathStatement() {
+        throw new UnsupportedOperationException("API design mistake");
+    }
+
+    @Override
+    public boolean requireInstance() {
+        return requireInstance;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIntegerType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIntegerType.java
new file mode 100644 (file)
index 0000000..a27f009
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+
+final class RestrictedIntegerType extends AbstractRangeRestrictedType<IntegerTypeDefinition> implements IntegerTypeDefinition {
+    RestrictedIntegerType(final IntegerTypeDefinition baseType, final SchemaPath path,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes, final Collection<RangeConstraint> rangeConstraints) {
+        super(baseType, path, unknownSchemaNodes, rangeConstraints);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedLeafrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedLeafrefType.java
new file mode 100644 (file)
index 0000000..692a7e1
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+
+final class RestrictedLeafrefType extends AbstractRestrictedType<LeafrefTypeDefinition> implements LeafrefTypeDefinition {
+    RestrictedLeafrefType(final LeafrefTypeDefinition baseType, final SchemaPath path,
+            final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, unknownSchemaNodes);
+    }
+
+    @Override
+    public RevisionAwareXPath getPathStatement() {
+        return getBaseType().getPathStatement();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedStringType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedStringType.java
new file mode 100644 (file)
index 0000000..cbd7e1c
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
+
+final class RestrictedStringType extends AbstractLengthRestrictedType<StringTypeDefinition> implements StringTypeDefinition {
+    private final List<PatternConstraint> patternConstraints;
+
+    RestrictedStringType(final StringTypeDefinition baseType, final SchemaPath path,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes, final Collection<LengthConstraint> lengthConstraints,
+        final List<PatternConstraint> patternConstraints) {
+        super(baseType, path, unknownSchemaNodes, lengthConstraints);
+        this.patternConstraints = ImmutableList.copyOf(patternConstraints);
+    }
+
+    @Override
+    public List<PatternConstraint> getPatternConstraints() {
+        return patternConstraints;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedTypes.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedTypes.java
new file mode 100644 (file)
index 0000000..1c238fe
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+
+/**
+ * Restricted types are a refinement of the restrictions applied to a particular type. YANG defines restrictions only
+ * on a subset of the base types, but conceptually any such definition can hold unknown nodes.
+ *
+ * 1) Restrictable
+ *    binary (length)
+ *    int{8,16,32,64} (range)
+ *    string (length, patterns)
+ *    uint{8,16,32,64} (range)
+ *    decimal64 (range)
+ *    instance-identifier (require-instance)
+ *
+ * 2) Non-restrictable
+ *    boolean
+ *    bits
+ *    empty (ignores default on derivation)
+ *    enumeration
+ *    identityref
+ *    leafref
+ *    union
+ *
+ * This class holds methods which allow creation of restricted types using {@link TypeBuilder} and its subclasses. Each
+ * restricted type is logically anchored at a {@link SchemaPath}, but can be substituted by its base type if it does
+ * not contribute any additional restrictions. TypeBuilder instances take this into account, and result in the base type
+ * being returned from the builder when the base type and restricted type are semantically equal.
+ *
+ * Restricted types inherit the default value, description, reference, status and units from the base type, if that type
+ * defines them.
+ */
+@Beta
+public final class RestrictedTypes {
+    private RestrictedTypes() {
+        throw new UnsupportedOperationException();
+    }
+
+    public static LengthRestrictedTypeBuilder<BinaryTypeDefinition> newBinaryBuilder(@Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) {
+        return new LengthRestrictedTypeBuilder<BinaryTypeDefinition>(baseType, path) {
+            @Override
+            BinaryTypeDefinition buildType() {
+                return new RestrictedBinaryType(getBaseType(), getPath(), getUnknownSchemaNodes(),
+                    calculateLenghtConstraints(getBaseType().getLengthConstraints()));
+            }
+        };
+    }
+
+    public static TypeBuilder<BitsTypeDefinition> newBitsBuilder(final BitsTypeDefinition baseType, final SchemaPath path) {
+        return new AbstractRestrictedTypeBuilder<BitsTypeDefinition>(baseType, path) {
+            @Override
+            BitsTypeDefinition buildType() {
+                return new RestrictedBitsType(getBaseType(), getPath(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static TypeBuilder<BooleanTypeDefinition> newBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) {
+        return new AbstractRestrictedTypeBuilder<BooleanTypeDefinition>(baseType, path) {
+            @Override
+            BooleanTypeDefinition buildType() {
+                return new RestrictedBooleanType(getBaseType(), getPath(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static RangeRestrictedTypeBuilder<DecimalTypeDefinition> newDecima64Builder(final DecimalTypeDefinition baseType, final SchemaPath path) {
+        return new RangeRestrictedTypeBuilder<DecimalTypeDefinition>(baseType, path) {
+            @Override
+            DecimalTypeDefinition buildType() {
+                return new RestrictedDecimalType(getBaseType(), getPath(), getUnknownSchemaNodes(),
+                    calculateRangeConstraints(getBaseType().getRangeConstraints()));
+            }
+        };
+    }
+
+    public static TypeBuilder<EmptyTypeDefinition> newEmptyBuilder(final EmptyTypeDefinition baseType, final SchemaPath path) {
+        return new AbstractRestrictedTypeBuilder<EmptyTypeDefinition>(baseType, path) {
+            @Override
+            EmptyTypeDefinition buildType() {
+                return new RestrictedEmptyType(getBaseType(), getPath(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static TypeBuilder<EnumTypeDefinition> newEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) {
+        return new AbstractRestrictedTypeBuilder<EnumTypeDefinition>(baseType, path) {
+            @Override
+            EnumTypeDefinition buildType() {
+                return new RestrictedEnumerationType(getBaseType(), getPath(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static TypeBuilder<IdentityrefTypeDefinition> newIdentityrefBuilder(final IdentityrefTypeDefinition baseType, final SchemaPath path) {
+        return new AbstractRestrictedTypeBuilder<IdentityrefTypeDefinition>(baseType, path) {
+            @Override
+            IdentityrefTypeDefinition buildType() {
+                return new RestrictedIdentityrefType(getBaseType(), getPath(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static InstanceIdentifierTypeBuilder newInstanceIdentifierBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
+        return new InstanceIdentifierTypeBuilder(baseType, path);
+    }
+
+    public static TypeBuilder<LeafrefTypeDefinition> newLeafrefBuilder(final LeafrefTypeDefinition baseType, final SchemaPath path) {
+        return new AbstractRestrictedTypeBuilder<LeafrefTypeDefinition>(baseType, path) {
+            @Override
+            LeafrefTypeDefinition buildType() {
+                return new RestrictedLeafrefType(getBaseType(), getPath(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static RangeRestrictedTypeBuilder<IntegerTypeDefinition> newIntegerBuilder(final IntegerTypeDefinition baseType, final SchemaPath path) {
+        return new RangeRestrictedTypeBuilder<IntegerTypeDefinition>(baseType, path) {
+            @Override
+            IntegerTypeDefinition buildType() {
+                return new RestrictedIntegerType(getBaseType(), getPath(), getUnknownSchemaNodes(),
+                    calculateRangeConstraints(getBaseType().getRangeConstraints()));
+            }
+        };
+    }
+
+    public static StringTypeBuilder newStringBuilder(final StringTypeDefinition baseType, final SchemaPath path) {
+        return new StringTypeBuilder(baseType, path);
+    }
+
+    public static TypeBuilder<UnionTypeDefinition> newUnionBuilder(final UnionTypeDefinition baseType, final SchemaPath path) {
+        return new AbstractRestrictedTypeBuilder<UnionTypeDefinition>(baseType, path) {
+            @Override
+            UnionTypeDefinition buildType() {
+                return new RestrictedUnionType(getBaseType(), getPath(), getUnknownSchemaNodes());
+            }
+        };
+    }
+
+    public static RangeRestrictedTypeBuilder<UnsignedIntegerTypeDefinition> newUnsignedBuilder(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) {
+        return new RangeRestrictedTypeBuilder<UnsignedIntegerTypeDefinition>(baseType, path) {
+            @Override
+            UnsignedIntegerTypeDefinition buildType() {
+                return new RestrictedUnsignedType(getBaseType(), getPath(), getUnknownSchemaNodes(),
+                    calculateRangeConstraints(getBaseType().getRangeConstraints()));
+            }
+        };
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedUnionType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedUnionType.java
new file mode 100644 (file)
index 0000000..ca7ec91
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+
+final class RestrictedUnionType extends AbstractRestrictedType<UnionTypeDefinition> implements UnionTypeDefinition {
+    RestrictedUnionType(final UnionTypeDefinition baseType, final SchemaPath path,
+            final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+        super(baseType, path, unknownSchemaNodes);
+    }
+
+    @Override
+    public List<TypeDefinition<?>> getTypes() {
+        return getBaseType().getTypes();
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedUnsignedType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedUnsignedType.java
new file mode 100644 (file)
index 0000000..a1c214c
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+
+final class RestrictedUnsignedType extends AbstractRestrictedType<UnsignedIntegerTypeDefinition>
+        implements UnsignedIntegerTypeDefinition {
+    private final List<RangeConstraint> rangeConstraints;
+
+    RestrictedUnsignedType(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path,
+        final Collection<UnknownSchemaNode> unknownSchemaNodes, final Collection<RangeConstraint> rangeConstraints) {
+        super(baseType, path, unknownSchemaNodes);
+        this.rangeConstraints = ImmutableList.copyOf(rangeConstraints);
+    }
+
+    @Override
+    public List<RangeConstraint> getRangeConstraints() {
+        return rangeConstraints;
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/StringTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/StringTypeBuilder.java
new file mode 100644 (file)
index 0000000..81a080f
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
+
+public final class StringTypeBuilder extends LengthRestrictedTypeBuilder<StringTypeDefinition> {
+    private final List<PatternConstraint> patternConstraints = new ArrayList<>(0);
+
+    StringTypeBuilder(final StringTypeDefinition baseType, final SchemaPath path) {
+        super(baseType, path);
+    }
+
+    public void addPatternConstraint(final PatternConstraint constraint) {
+        patternConstraints.add(Preconditions.checkNotNull(constraint));
+        touch();
+    }
+
+    @Override
+    public RestrictedStringType buildType() {
+        final List<PatternConstraint> basePatterns = getBaseType().getPatternConstraints();
+        final List<PatternConstraint> patterns;
+        if (!patternConstraints.isEmpty()) {
+            patterns = new ArrayList<>(patternConstraints.size() + basePatterns.size());
+            patterns.addAll(patternConstraints);
+            patterns.addAll(basePatterns);
+        } else {
+            patterns = getBaseType().getPatternConstraints();
+        }
+
+        return new RestrictedStringType(getBaseType(), getPath(), getUnknownSchemaNodes(),
+            calculateLenghtConstraints(getBaseType().getLengthConstraints()), patterns);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/TypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/TypeBuilder.java
new file mode 100644 (file)
index 0000000..5920a36
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+
+public abstract class TypeBuilder<T extends TypeDefinition<T>> implements Builder<T> {
+    private final ImmutableList.Builder<UnknownSchemaNode> unknownSchemaNodes = ImmutableList.builder();
+    private final SchemaPath path;
+    private final T baseType;
+
+    TypeBuilder(final T baseType, final SchemaPath path) {
+        this.path = Preconditions.checkNotNull(path);
+        this.baseType = baseType;
+    }
+
+    final T getBaseType() {
+        return baseType;
+    }
+
+    final SchemaPath getPath() {
+        return path;
+    }
+
+    final List<UnknownSchemaNode> getUnknownSchemaNodes() {
+        return unknownSchemaNodes.build();
+    }
+
+    public final void addUnknownSchemaNode(final UnknownSchemaNode node) {
+        unknownSchemaNodes.add(node);
+    }
+}
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/UnionTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/UnionTypeBuilder.java
new file mode 100644 (file)
index 0000000..e14eb6f
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.util.type;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+
+public final class UnionTypeBuilder extends TypeBuilder<UnionTypeDefinition> {
+    private final Builder<TypeDefinition<?>> builder = ImmutableList.builder();
+
+    UnionTypeBuilder(final SchemaPath path) {
+        super(null, path);
+    }
+
+    public void addType(@Nonnull final TypeDefinition<?> type) {
+        builder.add(type);
+    }
+
+    @Override
+    public BaseUnionType build() {
+        return new BaseUnionType(getPath(), getUnknownSchemaNodes(), builder.build());
+    }
+}