API Claratity: Documented package o.o.y.yang.model.util 20/7420/7
authorTony Tkacik <ttkacik@cisco.com>
Tue, 27 May 2014 10:04:38 +0000 (12:04 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Fri, 30 May 2014 10:02:17 +0000 (12:02 +0200)
Documented package o.o.y.yang.model.util,
documented differences between base YANG types
which resulted in different instantiation pattern for
some of built-in types.

Deprecated utility YangTypesConverter which name was
confusing, added replacement methods in BaseTypes
which name is less confusing and more clearly
comunicates its functions.

Improved hashCode and equals after introducing
static constants.

Change-Id: I300d64cb38ded6989afa0eb841dca61a0efbf8f0
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
32 files changed:
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSignedInteger.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractUnsignedInteger.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseTypes.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BinaryType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BitsType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BooleanType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Decimal64.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EmptyType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EnumerationType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ExtendedType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/IdentityrefType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/InstanceIdentifier.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int16.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int32.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int64.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int8.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Leafref.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/LengthConstraintImpl.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java [new file with mode: 0644]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RevisionAwareXPathImpl.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/StringType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint16.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint32.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint64.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint8.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnionType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnknownType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/YangTypesConverter.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/package-info.java [new file with mode: 0644]

index 29de860253a6f1ddf264d0eaf243fdb06ae7bda5..6cfa27e6d3096df806fbf056f1529cac63d28993 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -18,6 +17,8 @@ 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;
 
+import com.google.common.base.Optional;
+
 /**
  * The Abstract Integer class defines implementation of IntegerTypeDefinition
  * interface which represents SIGNED Integer values defined in Yang language. <br>
@@ -43,22 +44,23 @@ abstract class AbstractSignedInteger implements IntegerTypeDefinition {
     private final List<RangeConstraint> rangeStatements;
 
     /**
-     * @param name
-     * @param description
-     * @param minRange
-     * @param maxRange
-     * @param units
+     * Construct SignedInteger
+     *
+     * @param name Name of type
+     * @param description Description of type
+     * @param minRange Minimal range
+     * @param maxRange Maxium range
+     * @param units Units
      */
-    public AbstractSignedInteger(final QName name, final String description, final Number minRange,
+    protected AbstractSignedInteger(final QName name, final String description, final Number minRange,
             final Number maxRange, final String units) {
         this.name = name;
         this.path = SchemaPath.create(Collections.singletonList(name), true);
         this.description = description;
         this.units = units;
-        this.rangeStatements = new ArrayList<RangeConstraint>();
         final String rangeDescription = "Integer values between " + minRange + " and " + maxRange + ", inclusively.";
-        this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange, maxRange, rangeDescription,
-                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
+        this.rangeStatements = Collections.singletonList(BaseConstraints.newRangeConstraint(minRange, maxRange, Optional.of(rangeDescription),
+                Optional.of("https://tools.ietf.org/html/rfc6020#section-9.2.4")));
     }
 
     @Override
index ae7a61016a6910926024fce88e8e8939acf65b4f..b33392a7a0fcf1632694da9dee3510c7c4310d90 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -18,6 +17,8 @@ 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;
 
+import com.google.common.base.Optional;
+
 /**
  * The Abstract Integer class defines implementation of IntegerTypeDefinition
  * interface which represents UNSIGNED Integer values defined in Yang language. <br>
@@ -44,21 +45,21 @@ abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefinition
     private final List<RangeConstraint> rangeStatements;
 
     /**
+     * Construct Unsigned Integer
      *
-     * @param name
-     * @param description
-     * @param maxRange
-     * @param units
+     * @param name Name of type
+     * @param description Description of type
+     * @param maxRange Maximum value
+     * @param units Units
      */
     public AbstractUnsignedInteger(final QName name, final String description, final Number maxRange, final String units) {
         this.name = name;
         this.path = SchemaPath.create(Collections.singletonList(name), true);
         this.description = description;
         this.units = units;
-        this.rangeStatements = new ArrayList<RangeConstraint>();
         final String rangeDescription = "Integer values between " + MIN_VALUE + " and " + maxRange + ", inclusively.";
-        this.rangeStatements.add(BaseConstraints.rangeConstraint(MIN_VALUE, maxRange, rangeDescription,
-                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
+        this.rangeStatements = Collections.singletonList(BaseConstraints.newRangeConstraint(MIN_VALUE, maxRange, Optional.of(rangeDescription),
+                Optional.of("https://tools.ietf.org/html/rfc6020#section-9.2.4")));
     }
 
     @Override
index c6ba5d619c0605e0d8dbab39ccb4d81b9f3d4687..7dd5fb402934afbb3caad6913c409e587caf1a59 100644 (file)
@@ -11,423 +11,172 @@ 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.RangeConstraint;
 
+import com.google.common.base.Optional;
+
+/**
+ * Utility class which provides factory methods to construct Constraints.
+ *
+ * Provides static factory methods which constructs instances of
+ * <ul>
+ * <li>{@link LengthConstraint} - {@link #lengthConstraint(Number, Number, String, String)}
+ * <li>{@link RangeConstraint} - {@link #rangeConstraint(Number, Number, String, String)}
+ * <li>{@link PatternConstraint} - {@link #patternConstraint(String, String, String)}
+ * </ul>
+ */
 public final class BaseConstraints {
 
     private BaseConstraints() {
     }
 
-    public static LengthConstraint lengthConstraint(final Number min, final Number max, final String description,
-            final String reference) {
+
+    /**
+     * Creates a {@link LengthConstraint}.
+     *
+     * Creates an instance of Length constraint based on supplied parameters
+     * with additional behaviour:
+     *
+     * <ul>
+     * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
+     * <li>{@link LengthConstraint#getErrorMessage() returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
+     * </ul>
+     *
+     * @see LengthConstraint
+     *
+     * @param min  length-restricting lower bound value. The value MUST NOT be negative.
+     * @param max length-restricting upper bound value. The value MUST NOT be negative.
+     * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
+     * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
+     * @return Instance of {@link LengthConstraint}
+     */
+    public static LengthConstraint newLengthConstraint(final Number min, final Number max, final Optional<String> description,
+            final Optional<String> reference) {
         return new LengthConstraintImpl(min, max, description, reference);
     }
 
-    public static RangeConstraint rangeConstraint(final Number min, final Number max, final String description,
-            final String reference) {
+    /**
+     * Creates a {@link RangeConstraint}.
+     *
+     * Creates an instance of Range constraint based on supplied parameters
+     * with additional behaviour:
+     *
+     * <ul>
+     * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
+     * <li>{@link RangeConstraint#getErrorMessage() returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
+     * </ul>
+     *
+     *
+     * @see RangeConstraint
+     *
+     * @param min value-restricting lower bound value. The value MUST NOT Be null.
+     * @param max value-restricting upper bound value. The value MUST NOT Be null.
+     * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
+     * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
+     * @return Instance of {@link RangeConstraint}
+     */
+    public static RangeConstraint newRangeConstraint(final Number min, final Number max, final Optional<String> description,
+            final Optional<String> reference) {
         return new RangeConstraintImpl(min, max, description, reference);
     }
 
-    public static PatternConstraint patternConstraint(final String pattern, final String description,
-            final String reference) {
+
+    /**
+     * Creates a {@link PatternConstraint}.
+     *
+     * Creates an instance of Pattern constraint based on supplied parameters
+     * with additional behaviour:
+     *
+     * <ul>
+     * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
+     * </ul>
+     *
+     * @see PatternConstraint
+     *
+     * @param pattern Regular expression, MUST NOT BE null.
+     * @param description Description associated with constraint.
+     * @param reference Reference associated with constraint.
+     * @returnInstance of {@link PatternConstraint}
+     */
+    public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
+            final Optional<String> reference) {
         return new PatternConstraintImpl(pattern, description, reference);
     }
 
-    private static final class LengthConstraintImpl implements LengthConstraint {
-
-        private final Number min;
-        private final Number max;
-
-        private final String description;
-        private final String reference;
-
-        private final String errorAppTag;
-        private final String errorMessage;
 
-        public LengthConstraintImpl(Number min, Number max, final String description, final String reference) {
-            super();
-            this.min = min;
-            this.max = max;
-            this.description = description;
-            this.reference = reference;
-
-            this.errorAppTag = "length-out-of-specified-bounds";
-            this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
-        }
-
-        @Override
-        public String getDescription() {
-            return description;
-        }
-
-        @Override
-        public String getErrorAppTag() {
-            return errorAppTag;
-        }
-
-        @Override
-        public String getErrorMessage() {
-            return errorMessage;
-        }
-
-        @Override
-        public String getReference() {
-            return reference;
-        }
-
-        @Override
-        public Number getMin() {
-            return min;
-        }
-
-        @Override
-        public Number getMax() {
-            return max;
-        }
-
-        @Override
-        public int hashCode() {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ((description == null) ? 0 : description.hashCode());
-            result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
-            result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode());
-            result = prime * result + ((max == null) ? 0 : max.hashCode());
-            result = prime * result + ((min == null) ? 0 : min.hashCode());
-            result = prime * result + ((reference == null) ? 0 : reference.hashCode());
-            return result;
-        }
-
-        @Override
-        public boolean equals(final Object obj) {
-            if (this == obj) {
-                return true;
-            }
-            if (obj == null) {
-                return false;
-            }
-            if (getClass() != obj.getClass()) {
-                return false;
-            }
-            final LengthConstraintImpl other = (LengthConstraintImpl) obj;
-            if (description == null) {
-                if (other.description != null) {
-                    return false;
-                }
-            } else if (!description.equals(other.description)) {
-                return false;
-            }
-            if (errorAppTag == null) {
-                if (other.errorAppTag != null) {
-                    return false;
-                }
-            } else if (!errorAppTag.equals(other.errorAppTag)) {
-                return false;
-            }
-            if (errorMessage == null) {
-                if (other.errorMessage != null) {
-                    return false;
-                }
-            } else if (!errorMessage.equals(other.errorMessage)) {
-                return false;
-            }
-            if (max != other.max) {
-                return false;
-            }
-            if (min != other.min) {
-                return false;
-            }
-            if (reference == null) {
-                if (other.reference != null) {
-                    return false;
-                }
-            } else if (!reference.equals(other.reference)) {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder builder = new StringBuilder();
-            builder.append("LengthConstraintImpl [min=");
-            builder.append(min);
-            builder.append(", max=");
-            builder.append(max);
-            builder.append(", description=");
-            builder.append(description);
-            builder.append(", errorAppTag=");
-            builder.append(errorAppTag);
-            builder.append(", reference=");
-            builder.append(reference);
-            builder.append(", errorMessage=");
-            builder.append(errorMessage);
-            builder.append("]");
-            return builder.toString();
-        }
+    /**
+     * Creates a {@link LengthConstraint}.
+     *
+     * Creates an instance of Length constraint based on supplied parameters
+     * with additional behaviour:
+     *
+     * <ul>
+     * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
+     * <li>{@link LengthConstraint#getErrorMessage() returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
+     * </ul>
+     *
+     * @see LengthConstraint
+     *
+     * @param min  length-restricting lower bound value. The value MUST NOT be negative.
+     * @param max length-restricting upper bound value. The value MUST NOT be negative.
+     * @param description Description associated with constraint.
+     * @param reference Reference associated with constraint.
+     * @return Instance of {@link LengthConstraint}
+     * @deprecated Use {@link #newLengthConstraint(Number, Number, Optional, Optional)} instead.
+     */
+    @Deprecated
+    public static LengthConstraint lengthConstraint(final Number min, final Number max, final String description,
+            final String reference) {
+        return newLengthConstraint(min, max, Optional.fromNullable(description), Optional.fromNullable(reference));
     }
 
-    private static final class RangeConstraintImpl implements RangeConstraint {
-        private final Number min;
-        private final Number max;
-
-        private final String description;
-        private final String reference;
-
-        private final String errorAppTag;
-        private final String errorMessage;
-
-        public RangeConstraintImpl(Number min, Number max, String description, String reference) {
-            super();
-            this.min = min;
-            this.max = max;
-            this.description = description;
-            this.reference = reference;
-
-            this.errorAppTag = "range-out-of-specified-bounds";
-            this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
-        }
-
-        @Override
-        public String getDescription() {
-            return description;
-        }
-
-        @Override
-        public String getErrorAppTag() {
-            return errorAppTag;
-        }
-
-        @Override
-        public String getErrorMessage() {
-            return errorMessage;
-        }
-
-        @Override
-        public String getReference() {
-            return reference;
-        }
-
-        @Override
-        public Number getMin() {
-            return min;
-        }
-
-        @Override
-        public Number getMax() {
-            return max;
-        }
-
-        @Override
-        public int hashCode() {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ((description == null) ? 0 : description.hashCode());
-            result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
-            result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode());
-            result = prime * result + ((max == null) ? 0 : max.hashCode());
-            result = prime * result + ((min == null) ? 0 : min.hashCode());
-            result = prime * result + ((reference == null) ? 0 : reference.hashCode());
-            return result;
-        }
-
-        @Override
-        public boolean equals(final Object obj) {
-            if (this == obj) {
-                return true;
-            }
-            if (obj == null) {
-                return false;
-            }
-            if (getClass() != obj.getClass()) {
-                return false;
-            }
-            final RangeConstraintImpl other = (RangeConstraintImpl) obj;
-            if (description == null) {
-                if (other.description != null) {
-                    return false;
-                }
-            } else if (!description.equals(other.description)) {
-                return false;
-            }
-            if (errorAppTag == null) {
-                if (other.errorAppTag != null) {
-                    return false;
-                }
-            } else if (!errorAppTag.equals(other.errorAppTag)) {
-                return false;
-            }
-            if (errorMessage == null) {
-                if (other.errorMessage != null) {
-                    return false;
-                }
-            } else if (!errorMessage.equals(other.errorMessage)) {
-                return false;
-            }
-            if (max == null) {
-                if (other.max != null) {
-                    return false;
-                }
-            } else if (!max.equals(other.max)) {
-                return false;
-            }
-            if (min == null) {
-                if (other.min != null) {
-                    return false;
-                }
-            } else if (!min.equals(other.min)) {
-                return false;
-            }
-            if (reference == null) {
-                if (other.reference != null) {
-                    return false;
-                }
-            } else if (!reference.equals(other.reference)) {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public String toString() {
-            final StringBuilder builder = new StringBuilder();
-            builder.append("RangeConstraintImpl [min=");
-            builder.append(min);
-            builder.append(", max=");
-            builder.append(max);
-            builder.append(", description=");
-            builder.append(description);
-            builder.append(", reference=");
-            builder.append(reference);
-            builder.append(", errorAppTag=");
-            builder.append(errorAppTag);
-            builder.append(", errorMessage=");
-            builder.append(errorMessage);
-            builder.append("]");
-            return builder.toString();
-        }
+    /**
+     * Creates a {@link RangeConstraint}.
+     *
+     * Creates an instance of Range constraint based on supplied parameters
+     * with additional behaviour:
+     *
+     * <ul>
+     * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
+     * <li>{@link RangeConstraint#getErrorMessage() returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
+     * </ul>
+     *
+     *
+     * @see RangeConstraint
+     *
+     * @param min value-restricting lower bound value. The value MUST NOT Be null.
+     * @param max value-restricting upper bound value. The value MUST NOT Be null.
+     * @param description Description associated with constraint.
+     * @param reference Reference associated with constraint.
+     * @return Instance of {@link RangeConstraint}
+     * @deprecated Use {@link #newRangeConstraint(Number, Number, Optional, Optional)} instead.
+     */
+    @Deprecated
+    public static RangeConstraint rangeConstraint(final Number min, final Number max, final String description,
+            final String reference) {
+        return newRangeConstraint(min, max, Optional.fromNullable(description), Optional.fromNullable(reference));
     }
 
-    private static final class PatternConstraintImpl implements PatternConstraint {
-
-        private final String regex;
-        private final String description;
-        private final String reference;
-
-        private final String errorAppTag;
-        private final String errorMessage;
-
-        public PatternConstraintImpl(final String regex, final String description, final String reference) {
-            super();
-            this.regex = regex;
-            this.description = description;
-            this.reference = reference;
-
-            errorAppTag = "invalid-regular-expression";
-            // TODO: add erro message
-            errorMessage = "";
-        }
-
-        @Override
-        public String getDescription() {
-            return description;
-        }
-
-        @Override
-        public String getErrorAppTag() {
-            return errorAppTag;
-        }
-
-        @Override
-        public String getErrorMessage() {
-            return errorMessage;
-        }
-
-        @Override
-        public String getReference() {
-            return reference;
-        }
-
-        @Override
-        public String getRegularExpression() {
-            return regex;
-        }
-
-        @Override
-        public int hashCode() {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ((description == null) ? 0 : description.hashCode());
-            result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
-            result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode());
-            result = prime * result + ((reference == null) ? 0 : reference.hashCode());
-            result = prime * result + ((regex == null) ? 0 : regex.hashCode());
-            return result;
-        }
-
-        @Override
-        public boolean equals(final Object obj) {
-            if (this == obj) {
-                return true;
-            }
-            if (obj == null) {
-                return false;
-            }
-            if (getClass() != obj.getClass()) {
-                return false;
-            }
-            final PatternConstraintImpl other = (PatternConstraintImpl) obj;
-            if (description == null) {
-                if (other.description != null) {
-                    return false;
-                }
-            } else if (!description.equals(other.description)) {
-                return false;
-            }
-            if (errorAppTag == null) {
-                if (other.errorAppTag != null) {
-                    return false;
-                }
-            } else if (!errorAppTag.equals(other.errorAppTag)) {
-                return false;
-            }
-            if (errorMessage == null) {
-                if (other.errorMessage != null) {
-                    return false;
-                }
-            } else if (!errorMessage.equals(other.errorMessage)) {
-                return false;
-            }
-            if (reference == null) {
-                if (other.reference != null) {
-                    return false;
-                }
-            } else if (!reference.equals(other.reference)) {
-                return false;
-            }
-            if (regex == null) {
-                if (other.regex != null) {
-                    return false;
-                }
-            } else if (!regex.equals(other.regex)) {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder builder = new StringBuilder();
-            builder.append("PatternConstraintImpl [regex=");
-            builder.append(regex);
-            builder.append(", description=");
-            builder.append(description);
-            builder.append(", reference=");
-            builder.append(reference);
-            builder.append(", errorAppTag=");
-            builder.append(errorAppTag);
-            builder.append(", errorMessage=");
-            builder.append(errorMessage);
-            builder.append("]");
-            return builder.toString();
-        }
+    /**
+     * Creates a {@link PatternConstraint}.
+     *
+     * Creates an instance of Range constraint based on supplied parameters
+     * with additional behaviour:
+     *
+     * <ul>
+     * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
+     * </ul>
+     *
+     *
+     * @see PatternConstraint
+     *
+     * @param pattern Regular expression, MUST NOT
+     * @param description Description associated with constraint.
+     * @param reference Reference associated with constraint.
+     * @return Instance of {@link PatternConstraint}
+     * @deprecated Use {@link #newPatternConstraint(String, Optional, Optional)} Instead.
+     */
+    @Deprecated
+    public static PatternConstraint patternConstraint(final String pattern, final String description,
+            final String reference) {
+        return newPatternConstraint(pattern, Optional.fromNullable(description), Optional.fromNullable(reference));
     }
 }
index 7403099c0706fa492a764ef0bf4da5fc22cafcac..53dc55b58555f473eb4c838a39336dfd56a82ec5 100644 (file)
@@ -12,22 +12,36 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
+import java.util.Set;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Utility methods and constants to work with built-in YANG types
+ *
+ *
+ */
 public final class BaseTypes {
 
     private BaseTypes() {
     }
 
     public static final URI BASE_TYPES_NAMESPACE = URI.create("urn:ietf:params:xml:ns:yang:1");
+
     public static final QName BINARY_QNAME = constructQName("binary");
     public static final QName BITS_QNAME = constructQName("bits");
     public static final QName BOOLEAN_QNAME = constructQName("boolean");
     public static final QName DECIMAL64_QNAME = constructQName("decimal64");
     public static final QName EMPTY_QNAME = constructQName("empty");
     public static final QName ENUMERATION_QNAME = constructQName("enumeration");
+    public static final QName IDENTITYREF_QNAME = constructQName("identityref");
+    public static final QName INSTANCE_IDENTIFIER_QNAME = constructQName("instance-identifier");
     public static final QName INT8_QNAME = constructQName("int8");
     public static final QName INT16_QNAME = constructQName("int16");
     public static final QName INT32_QNAME = constructQName("int32");
@@ -38,6 +52,28 @@ public final class BaseTypes {
     public static final QName UINT16_QNAME = constructQName("uint16");
     public static final QName UINT32_QNAME = constructQName("uint32");
     public static final QName UINT64_QNAME = constructQName("uint64");
+    public static final QName UNION_QNAME = constructQName("union");
+
+    private static final Set<String> BUILD_IN_TYPES = ImmutableSet.<String> builder().add(BINARY_QNAME.getLocalName()) //
+            .add(BITS_QNAME.getLocalName()) //
+            .add(BOOLEAN_QNAME.getLocalName()) //
+            .add(DECIMAL64_QNAME.getLocalName()) //
+            .add(EMPTY_QNAME.getLocalName()) //
+            .add(ENUMERATION_QNAME.getLocalName()) //
+            .add(IDENTITYREF_QNAME.getLocalName()) //
+            .add(INSTANCE_IDENTIFIER_QNAME.getLocalName()) //
+            .add(INT8_QNAME.getLocalName()) //
+            .add(INT16_QNAME.getLocalName()) //
+            .add(INT32_QNAME.getLocalName()) //
+            .add(INT64_QNAME.getLocalName()) //
+            .add(LEAFREF_QNAME.getLocalName()) //
+            .add(STRING_QNAME.getLocalName()) //
+            .add(UINT8_QNAME.getLocalName()) //
+            .add(UINT16_QNAME.getLocalName()) //
+            .add(UINT32_QNAME.getLocalName()) //
+            .add(UINT64_QNAME.getLocalName()) //
+            .add(UNION_QNAME.getLocalName()) //
+            .build();
 
     /**
      * Construct QName for Built-in base Yang type. The namespace for built-in
@@ -52,12 +88,14 @@ public final class BaseTypes {
     }
 
     /**
-     * Creates Schema Path from Qname.
+     * Creates Schema Path from {@link QName}.
      *
      * @param typeName
      *            yang type QName
      * @return Schema Path from Qname.
+     * @deprecated Use {@link SchemaPath#create(boolean, QName...)} instead.
      */
+    @Deprecated
     public static SchemaPath schemaPath(final QName typeName) {
         return SchemaPath.create(Collections.singletonList(typeName), true);
     }
@@ -73,7 +111,11 @@ public final class BaseTypes {
      * @param revision
      *            Revision Date
      * @return Schema Path
+     *
+     * @deprecated Use {@link SchemaPath#create(boolean, Iterable)} with QNames
+     *             manually constructed.
      */
+    @Deprecated
     public static SchemaPath schemaPath(final List<String> actualPath, final URI namespace, final Date revision) {
         if (actualPath == null) {
             throw new IllegalArgumentException("The actual path List MUST be specified.");
@@ -87,4 +129,70 @@ public final class BaseTypes {
         }
         return SchemaPath.create(pathList, true);
     }
+
+    /**
+     * Returns true if supplied type is representation of built-in YANG type as
+     * per RFC 6020.
+     *
+     * See package documentation for description of base types.
+     *
+     * @param type
+     * @return true if type is built-in YANG Types.
+     */
+    public static boolean isYangBuildInType(final String type) {
+        return BUILD_IN_TYPES.contains(type);
+    }
+
+    /**
+     * Returns default instance of built-in for supplied type
+     *
+     * See package documentation for description of base build-in types
+     * with default instance.
+     *
+     * @param typeName
+     * @return Returns default instance or {@link Optional#absent()} if default
+     *         instance does not exists
+     *
+     */
+    public static Optional<TypeDefinition<?>> defaultBaseTypeFor(final String typeName) {
+        return Optional.<TypeDefinition<?>> fromNullable(defaultBaseTypeForImpl(typeName));
+    }
+
+    private static TypeDefinition<?> defaultBaseTypeForImpl(final String typeName) {
+        Preconditions.checkNotNull(typeName, "typeName must not be null.");
+
+        if (typeName.startsWith("int")) {
+            if ("int8".equals(typeName)) {
+                return Int8.getInstance();
+            } else if ("int16".equals(typeName)) {
+                return Int16.getInstance();
+            } else if ("int32".equals(typeName)) {
+                return Int32.getInstance();
+            } else if ("int64".equals(typeName)) {
+                return Int64.getInstance();
+            }
+        } else if (typeName.startsWith("uint")) {
+            if ("uint8".equals(typeName)) {
+                return Uint8.getInstance();
+            } else if ("uint16".equals(typeName)) {
+                return Uint16.getInstance();
+            } else if ("uint32".equals(typeName)) {
+                return Uint32.getInstance();
+            } else if ("uint64".equals(typeName)) {
+                return Uint64.getInstance();
+            }
+        } else if ("string".equals(typeName)) {
+            return StringType.getInstance();
+        } else if ("binary".equals(typeName)) {
+            return BinaryType.getInstance();
+        } else if ("boolean".equals(typeName)) {
+            return BooleanType.getInstance();
+        } else if ("empty".equals(typeName)) {
+            return EmptyType.getInstance();
+        } else if ("instance-identifier".equals(typeName)) {
+            return InstanceIdentifier.getInstance();
+        }
+        return null;
+    }
+
 }
index cda865d1a2fb3d7dade645513766d191793cdca9..9d93f745f3d8675bca3315c21dcdfd8afb7d7ee4 100644 (file)
@@ -17,6 +17,8 @@ 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;
 
+import com.google.common.base.Optional;
+
 /**
  * The <code>default</code> implementation of Binary Type Definition interface.
  *
@@ -27,16 +29,17 @@ public final class BinaryType implements BinaryTypeDefinition {
     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.8";
     private static final String UNITS = "";
 
+    private final static QName QNAME = BaseTypes.BINARY_QNAME;
+
     private static final BinaryType INSTANCE = new BinaryType();
 
-    private final QName name = BaseTypes.BINARY_QNAME;
-    private final SchemaPath path = SchemaPath.create(Collections.singletonList(name), true);
+    private final static SchemaPath PATH = SchemaPath.create(Collections.singletonList(QNAME), true);
     private final List<Byte> bytes = Collections.emptyList();
     private final List<LengthConstraint> lengthConstraints;
 
     private BinaryType() {
         this.lengthConstraints = Collections.singletonList(
-                BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
+                BaseConstraints.newLengthConstraint(0, Long.MAX_VALUE, Optional.of(""), Optional.of("")));
     }
 
     public static BinaryType getInstance() {
@@ -83,7 +86,7 @@ public final class BinaryType implements BinaryTypeDefinition {
      */
     @Override
     public QName getQName() {
-        return name;
+        return QNAME;
     }
 
     /*
@@ -93,7 +96,7 @@ public final class BinaryType implements BinaryTypeDefinition {
      */
     @Override
     public SchemaPath getPath() {
-        return path;
+        return PATH;
     }
 
     /*
@@ -150,8 +153,8 @@ public final class BinaryType implements BinaryTypeDefinition {
         int result = 1;
         result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
         result = prime * result + ((lengthConstraints == null) ? 0 : lengthConstraints.hashCode());
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result + ((path == null) ? 0 : path.hashCode());
+        result = prime * result + QNAME.hashCode();
+        result = prime * result + PATH.hashCode();
         return result;
     }
 
@@ -181,20 +184,6 @@ public final class BinaryType implements BinaryTypeDefinition {
         } else if (!lengthConstraints.equals(other.lengthConstraints)) {
             return false;
         }
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
-            return false;
-        }
         return true;
     }
 
@@ -202,9 +191,7 @@ public final class BinaryType implements BinaryTypeDefinition {
     public String toString() {
         StringBuilder builder = new StringBuilder();
         builder.append("BinaryType [name=");
-        builder.append(name);
-        builder.append(", path=");
-        builder.append(path);
+        builder.append(QNAME);
         builder.append(", description=");
         builder.append(DESCRIPTION);
         builder.append(", reference=");
index c53df1bc6aa71259f030a996bc4259f2d8378518..e89e6572f459730a09d1cb30e3956138ec962596 100644 (file)
@@ -16,13 +16,17 @@ 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;
 
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
 /**
  * The <code>default</code> implementation of Bits Type Definition interface.
  *
  * @see BitsTypeDefinition
  */
 public final class BitsType implements BitsTypeDefinition {
-    private final QName name = BaseTypes.constructQName("bits");
+    private final static QName NAME = BaseTypes.BITS_QNAME;
+
     private final SchemaPath path;
     private final String description = "The bits built-in type represents a bit set.  "
             + "That is, a bits value is a set of flags identified by small integer position "
@@ -37,11 +41,13 @@ public final class BitsType implements BitsTypeDefinition {
      * Instantiates Bits type as empty bits list.
      *
      * @param path
+     * @deprecated Use static factory method {@link #create(SchemaPath, List)} instead.
      */
+    @Deprecated
     public BitsType(final SchemaPath path) {
         super();
         this.bits = Collections.emptyList();
-        this.path = path;
+        this.path = Preconditions.checkNotNull(path,"path must not be null");
     }
 
     /**
@@ -49,11 +55,17 @@ public final class BitsType implements BitsTypeDefinition {
      *
      * @param path
      * @param bits
+     * @deprecated Use static factory method {@link #create(SchemaPath, List)} instead.
      */
+    @Deprecated
     public BitsType(final SchemaPath path, final List<Bit> bits) {
         super();
-        this.bits = Collections.unmodifiableList(bits);
-        this.path = path;
+        this.bits = ImmutableList.copyOf(bits);
+        this.path = Preconditions.checkNotNull(path,"path must not be null");
+    }
+
+    public static BitsType create(final SchemaPath path, final List<Bit> bits) {
+        return new BitsType(path,bits);
     }
 
     /*
@@ -96,7 +108,7 @@ public final class BitsType implements BitsTypeDefinition {
      */
     @Override
     public QName getQName() {
-        return name;
+        return NAME;
     }
 
     /*
@@ -156,13 +168,13 @@ public final class BitsType implements BitsTypeDefinition {
         int result = 1;
         result = prime * result + ((bits == null) ? 0 : bits.hashCode());
         result = prime * result + ((description == null) ? 0 : description.hashCode());
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result + ((path == null) ? 0 : path.hashCode());
+        result = prime * result + NAME.hashCode();
+        result = prime * result + path.hashCode();
         return result;
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -187,13 +199,7 @@ public final class BitsType implements BitsTypeDefinition {
         } else if (!description.equals(other.description)) {
             return false;
         }
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
+
         if (path == null) {
             if (other.path != null) {
                 return false;
@@ -208,7 +214,7 @@ public final class BitsType implements BitsTypeDefinition {
     public String toString() {
         StringBuilder builder = new StringBuilder();
         builder.append("BitsType [name=");
-        builder.append(name);
+        builder.append(NAME);
         builder.append(", path=");
         builder.append(path);
         builder.append(", description=");
index be35bf0b159f90d2abfade8ecd0adda93bc38f61..ad3a0ef6d29410beb12b3e5aaa30595058a7caf2 100644 (file)
@@ -34,6 +34,10 @@ public final class BooleanType implements BooleanTypeDefinition {
     private BooleanType() {
     }
 
+    /**
+     * Returns default instance of boolean built-in type.
+     * @return default instance of boolean built-in type.
+     */
     public static BooleanType getInstance() {
         return INSTANCE;
     }
index ed1db9a31505fc3ca961704e002862268975ca9f..850b51de87f52d091536008723b4075c1ba4763e 100644 (file)
@@ -24,6 +24,15 @@ import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
+/**
+ * DataNodeIterator is iterator, which walks down whole YANG DataNodeContainer
+ * and walks all instances of {@link DataSchemaNode} present in subtree.
+ *
+ * Iterator instance is eagerly created, walking happens on initialization.
+ *
+ * Iteration is not ordered.
+ *
+ */
 public class DataNodeIterator implements Iterator<DataSchemaNode> {
 
     private final DataNodeContainer container;
@@ -50,22 +59,47 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
         traverse(this.container);
     }
 
+    /**
+     * Returns list all containers present in subtree.
+     *
+     * @return Returns list all containers present in subtree.
+     */
     public List<ContainerSchemaNode> allContainers() {
         return allContainers;
     }
 
+    /**
+     * Returns list all lists present in subtree.
+     *
+     * @return Returns list all containers present in subtree.
+     */
     public List<ListSchemaNode> allLists() {
         return allLists;
     }
 
+    /**
+     * Returns list all choices present in subtree.
+     *
+     * @return Returns list all containers present in subtree.
+     */
     public List<ChoiceNode> allChoices() {
         return allChoices;
     }
 
+    /**
+     * Returns list all groupings present in subtree.
+     *
+     * @return Returns list all containers present in subtree.
+     */
     public List<GroupingDefinition> allGroupings() {
         return allGroupings;
     }
 
+    /**
+     * Returns list all typedefs present in subtree.
+     *
+     * @return Returns list all containers present in subtree.
+     */
     public List<TypeDefinition<?>> allTypedefs() {
         return allTypedefs;
     }
@@ -109,7 +143,7 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
 
     }
 
-    private void traverseModule(DataNodeContainer dataNode) {
+    private void traverseModule(final DataNodeContainer dataNode) {
         final Module module;
         if (dataNode instanceof Module) {
             module = (Module) dataNode;
@@ -136,7 +170,7 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
         }
     }
 
-    private void traverseGroupings(DataNodeContainer dataNode) {
+    private void traverseGroupings(final DataNodeContainer dataNode) {
         final Set<GroupingDefinition> groupings = dataNode.getGroupings();
         if (groupings != null) {
             for (GroupingDefinition grouping : groupings) {
index 666747915f3444becdf2e372b9fc9c15b6da1ab3..d975178a664015d4495b625ce173839fbb2ae85d 100644 (file)
@@ -19,6 +19,8 @@ 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 com.google.common.base.Optional;
+
 /**
  * The <code>default</code> implementation of Decimal Type Definition interface.
  *
@@ -26,7 +28,7 @@ import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
  * @see DecimalTypeDefinition
  */
 public final class Decimal64 implements DecimalTypeDefinition {
-    private final QName name = BaseTypes.constructQName("decimal64");
+    private static final QName NAME = BaseTypes.DECIMAL64_QNAME;
     private final SchemaPath path;
     private static final String UNITS = "";
     private static final BigDecimal DEFAULT_VALUE = null;
@@ -60,7 +62,9 @@ public final class Decimal64 implements DecimalTypeDefinition {
      *
      * @see DecimalTypeDefinition
      * @exception IllegalArgumentException
+     * @deprecated Use static factory {@link #create(SchemaPath, Integer)}.
      */
+    @Deprecated
     public Decimal64(final SchemaPath path, final Integer fractionDigits) {
         if (!((fractionDigits.intValue() >= 1) && (fractionDigits.intValue() <= MAX_NUMBER_OF_FRACTION_DIGITS))) {
             throw new IllegalArgumentException(
@@ -71,6 +75,10 @@ public final class Decimal64 implements DecimalTypeDefinition {
         this.path = path;
     }
 
+    public static Decimal64 create(final SchemaPath path, final Integer fractionDigits) {
+        return new Decimal64(path, fractionDigits);
+    }
+
     /**
      * Returns unmodifiable List with default definition of Range Statements.
      *
@@ -81,8 +89,8 @@ public final class Decimal64 implements DecimalTypeDefinition {
         final BigDecimal min = new BigDecimal("-922337203685477580.8");
         final BigDecimal max = new BigDecimal("922337203685477580.7");
         final String rangeDescription = "Integer values between " + min + " and " + max + ", inclusively.";
-        rangeStmts.add(BaseConstraints.rangeConstraint(min, max, rangeDescription,
-                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
+        rangeStmts.add(BaseConstraints.newRangeConstraint(min, max, Optional.of(rangeDescription),
+                Optional.of("https://tools.ietf.org/html/rfc6020#section-9.2.4")));
         return Collections.unmodifiableList(rangeStmts);
     }
 
@@ -103,7 +111,7 @@ public final class Decimal64 implements DecimalTypeDefinition {
 
     @Override
     public QName getQName() {
-        return name;
+        return NAME;
     }
 
     @Override
@@ -145,13 +153,13 @@ public final class Decimal64 implements DecimalTypeDefinition {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((NAME == null) ? 0 : NAME.hashCode());
         result = prime * result + ((path == null) ? 0 : path.hashCode());
         return result;
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -162,13 +170,6 @@ public final class Decimal64 implements DecimalTypeDefinition {
             return false;
         }
         Decimal64 other = (Decimal64) obj;
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
         if (path == null) {
             if (other.path != null) {
                 return false;
@@ -181,6 +182,6 @@ public final class Decimal64 implements DecimalTypeDefinition {
 
     @Override
     public String toString() {
-        return Decimal64.class.getSimpleName() + "[qname=" + name + ", fractionDigits=" + fractionDigits + "]";
+        return Decimal64.class.getSimpleName() + "[qname=" + NAME + ", fractionDigits=" + fractionDigits + "]";
     }
 }
index ed91d3358b4b42624edba5e15642d3251554bac6..7efebad4d43bdd4b0d2d5c8a84826de0ef09082e 100644 (file)
@@ -10,15 +10,16 @@ package org.opendaylight.yangtools.yang.model.util;
 import java.util.Collections;
 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.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
 
-public final class EmptyType implements EmptyTypeDefinition {
-    private static EmptyType instance;
-    private static final QName NAME = BaseTypes.constructQName("empty");
+public final class EmptyType implements EmptyTypeDefinition, Immutable {
+    private static final EmptyType INSTANCE = new EmptyType();
+    private static final QName NAME = BaseTypes.EMPTY_QNAME;
     private static final SchemaPath PATH = SchemaPath.create(Collections.singletonList(NAME), true);
     private static final String DESCRIPTION = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence.";
     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#page-131";
@@ -27,10 +28,7 @@ public final class EmptyType implements EmptyTypeDefinition {
     }
 
     public static EmptyType getInstance() {
-        if (instance == null) {
-            instance = new EmptyType();
-        }
-        return instance;
+        return INSTANCE;
     }
 
     @Override
index f359de0fddbfa9c7687197c89c62ea05fef152cb..1bd020019fa8fe63704dbd47572e9c478674bc7f 100644 (file)
@@ -16,6 +16,8 @@ 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;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 /**
@@ -33,18 +35,55 @@ public final class EnumerationType implements EnumTypeDefinition {
     private final EnumPair defaultEnum;
     private final List<EnumPair> enums;
 
+
+    /**
+     * Constructs EnumerationType
+     *
+     * @param path
+     * @param enums
+     * @deprecated Use {@link #create(SchemaPath, List, Optional)} instead.
+     */
+    @Deprecated
     public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
-        super();
-        this.path = path;
-        this.enums = ImmutableList.copyOf(enums);
-        this.defaultEnum = null;
+        this(path,enums,Optional.<EnumPair>absent());
     }
 
+    /**
+     * Constructs EnumerationType
+     *
+     * @param path
+     * @param defaultEnum
+     * @param enums
+     * @deprecated Use {@link #create(SchemaPath, List, Optional)} instead.
+     */
+    @Deprecated
     public EnumerationType(final SchemaPath path, final EnumPair defaultEnum, final List<EnumPair> enums) {
-        super();
-        this.path = path;
-        this.defaultEnum = defaultEnum;
-        this.enums = ImmutableList.copyOf(enums);
+        this(path,enums,Optional.fromNullable(defaultEnum));
+    }
+
+    private EnumerationType(final SchemaPath path, final List<EnumPair> enums, final Optional<EnumPair> defaultEnum) {
+        this.path = Preconditions.checkNotNull(path,"path must not be null");
+        this.enums = ImmutableList.copyOf(Preconditions.checkNotNull(enums, "enums must not be null."));
+        if(defaultEnum.isPresent()) {
+            Preconditions.checkArgument(enums.contains(defaultEnum.get()),"defaultEnum must be contained in defined enumerations.");
+            this.defaultEnum = defaultEnum.get();
+        } else {
+            this.defaultEnum = null;
+        }
+    }
+
+    /**
+     *
+     * Constructs new enumeration
+     *
+     * @param path Schema Path to definition point of this enumeration
+     * @param enums List of defined enumeration values
+     * @param defaultValue {@link Optional#of(Object)} of default value, {@link Optional#absent()} if no default value is defined.
+     *        If defaultValue is set, it must be present in provided list of enumerations.
+     *
+     */
+    public static EnumerationType create(final SchemaPath path, final List<EnumPair> enums, final Optional<EnumPair> defaultValue) {
+        return new EnumerationType(path, enums, defaultValue);
     }
 
     /*
index 4c2c17b63ad2aae304dc0802d9f050f296bd18ee..c5add934bee984990ec6d7e8eb2b213922c278b1 100644 (file)
@@ -21,6 +21,17 @@ 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.RangeConstraint;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+/**
+ * Extended Type represents YANG type derived from other type.
+ *
+ * Extended type object is decorator on top of existing {@link TypeDefinition}
+ * which represents original type, and extended type
+ * may define additional constraints, modify description or reference
+ * of parent type or provide new type capture for specific use-cases.
+ *
+ */
 public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
 
     private final QName typeName;
@@ -35,10 +46,24 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
     private List<PatternConstraint> patterns = Collections.emptyList();
     private Integer fractionDigits = null;
 
-    private Status status;
-    private String units;
-    private Object defaultValue;
-    private boolean addedByUses;
+    private final Status status;
+    private final String units;
+    private final Object defaultValue;
+    private final boolean addedByUses;
+
+    /**
+    *
+    * Creates Builder for extended / derived type.
+    *
+    * @param typeName QName of derived type
+    * @param baseType Base type of derived type
+    * @param description Description of type
+    * @param reference Reference of Type
+    * @param path Schema path to type definition.
+    */
+    public static final Builder builder(final QName typeName,final TypeDefinition<?> baseType,final Optional<String> description,final Optional<String> reference,final SchemaPath path) {
+        return new Builder(typeName, baseType, description.or(""), reference.or(""), path);
+    }
 
     public static class Builder {
         private final QName typeName;
@@ -60,33 +85,55 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         private List<PatternConstraint> patterns = Collections.emptyList();
         private Integer fractionDigits = null;
 
+        /**
+         *
+         * @param actualPath
+         * @param namespace
+         * @param revision
+         * @param typeName
+         * @param baseType
+         * @param description
+         * @param reference
+         *
+         * @deprecated Use {@link ExtendedType#builder(QName, TypeDefinition, Optional, Optional, SchemaPath) instead.
+         */
+        @Deprecated
         public Builder(final List<String> actualPath, final URI namespace,
                 final Date revision, final QName typeName,
-                TypeDefinition<?> baseType, final String description,
+                final TypeDefinition<?> baseType, final String description,
                 final String reference) {
-            this.typeName = typeName;
-            this.baseType = baseType;
-            this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
-            this.description = description;
-            this.reference = reference;
+            this(typeName,baseType,description,reference,BaseTypes.schemaPath(actualPath, namespace, revision));
         }
 
-        public Builder(final QName typeName, TypeDefinition<?> baseType,
+        /**
+         *
+         * Creates Builder for extended / derived type.
+         *
+         * @param typeName QName of derived type
+         * @param baseType Base type of derived type
+         * @param description Description of type
+         * @param reference Reference of Type
+         * @param path Schema path to type definition.
+         *
+         * @deprecated Use {@link ExtendedType#builder(QName, TypeDefinition, Optional, Optional, SchemaPath) instead.
+         */
+        @Deprecated
+        public Builder(final QName typeName, final TypeDefinition<?> baseType,
                 final String description, final String reference,
-                SchemaPath path) {
-            this.typeName = typeName;
-            this.baseType = baseType;
-            this.path = path;
+                final SchemaPath path) {
+            this.typeName = Preconditions.checkNotNull(typeName, "type name must not be null.");
+            this.baseType = Preconditions.checkNotNull(baseType, "base type must not be null");
+            this.path = Preconditions.checkNotNull(path, "path must not be null.");
             this.description = description;
             this.reference = reference;
         }
 
-        public Builder status(Status status) {
+        public Builder status(final Status status) {
             this.status = status;
             return this;
         }
 
-        public Builder units(String units) {
+        public Builder units(final String units) {
             this.units = units;
             return this;
         }
@@ -138,7 +185,7 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         }
     }
 
-    private ExtendedType(Builder builder) {
+    private ExtendedType(final Builder builder) {
         this.typeName = builder.typeName;
         this.baseType = builder.baseType;
         this.path = builder.path;
@@ -206,7 +253,7 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
     }
 
     @Override
-    public boolean equals(Object o) {
+    public boolean equals(final Object o) {
         if (this == o) {
             return true;
         }
index e34e0078588607c581c4f81e18d0ba37a9c170bf..16823e6708706682e24853627b07fc64581521f7 100644 (file)
@@ -17,6 +17,8 @@ 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;
 
+import com.google.common.base.Preconditions;
+
 /**
  * The <code>default</code> implementation of Identityref Type Definition
  * interface.
@@ -24,16 +26,39 @@ import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
  * @see IdentityrefTypeDefinition
  */
 public final class IdentityrefType implements IdentityrefTypeDefinition {
-    private final QName name = BaseTypes.constructQName("identityref");
+    private static final QName NAME = BaseTypes.IDENTITYREF_QNAME;
     private final SchemaPath path;
     private static final String DESCRIPTION = "The identityref type is used to reference an existing identity.";
     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.10";
     private final IdentitySchemaNode identity;
     private static final String UNITS = "";
 
-    public IdentityrefType(IdentitySchemaNode identity, SchemaPath schemaPath) {
-        this.identity = identity;
-        this.path = schemaPath;
+    /**
+     * Constructs new {@link IdentityrefTypeDefinition} definition.
+     *
+     * @param identity
+     * @param schemaPath
+     */
+    @Deprecated
+    public IdentityrefType(final IdentitySchemaNode identity, final SchemaPath schemaPath) {
+        this(schemaPath,identity);
+    }
+
+    private IdentityrefType(final SchemaPath path, final IdentitySchemaNode baseIdentity) {
+        this.path = Preconditions.checkNotNull(path, "Path must be specified");
+        this.identity = Preconditions.checkNotNull(baseIdentity,"baseIdentity must be specified.");
+    }
+
+    /**
+     *
+     * Constructs new {@link IdentityrefTypeDefinition} definition.
+     *
+     * @param path Path to the definition.
+     * @param baseIdentity Base Identity, all derived identities are valid arguments for instance of this type.
+     * @return New identityref definition.
+     */
+    public static IdentityrefType create(final SchemaPath path, final IdentitySchemaNode baseIdentity) {
+        return new IdentityrefType(path, baseIdentity);
     }
 
     @Override
@@ -48,7 +73,7 @@ public final class IdentityrefType implements IdentityrefTypeDefinition {
 
     @Override
     public QName getQName() {
-        return name;
+        return NAME;
     }
 
     @Override
index 6330801f35cb7424965e3584a1cd3114afb4089c..b2d5887a7e6cbef4be618d392a2b2f8bfc9ef3b8 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.model.util;
 import java.util.Collections;
 import java.util.List;
 
+import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
@@ -21,33 +22,62 @@ import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefi
  * The <code>default</code> implementation of Instance Identifier Type
  * Definition interface.
  *
+ * Instance Identifier has only two possible variants - one with
+ * {@link #requireInstance()} which returns true, other one
+ * returns false.
+ *
  * @see InstanceIdentifierTypeDefinition
- * @deprecated Depracated, use {@link org.opendaylight.yangtools.yang.data.api.InstanceIdentifier} instead
+ *
  */
-@Deprecated
-public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
-    private static final QName NAME = BaseTypes.constructQName("instance-identifier");
-    private static final SchemaPath PATH = new SchemaPath(Collections.singletonList(NAME), true);
+public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition, Immutable {
+
+    private static final QName NAME = BaseTypes.INSTANCE_IDENTIFIER_QNAME;
+    private static final SchemaPath PATH = SchemaPath.create(Collections.singletonList(NAME), true);
     private static final String DESCRIPTION = "The instance-identifier built-in type is used to "
             + "uniquely identify a particular instance node in the data tree.";
     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.13";
 
-    private final RevisionAwareXPath xpath;
     private static final String UNITS = "";
-    private boolean requireInstance = true;
+    private final Boolean requireInstance;
 
-    private static final int HASH_BOOLEAN_TRUE = 1231;
-    private static final int HASH_BOOLEAN_FALSE = 1237;
+    private static final InstanceIdentifier INSTANCE_WITH_REQUIRED_TRUE = new InstanceIdentifier(true);
+    private static final InstanceIdentifier INSTANCE_WITH_REQUIRED_FALSE = new InstanceIdentifier(false);
 
+    /**
+     * Constructs new instance identifier.
+     *
+     * @param xpath
+     * @deprecated Use {@link #getInstance()} for default one, since Instance Identifier does not have xpath.
+     */
+    @Deprecated
     public InstanceIdentifier(final RevisionAwareXPath xpath) {
-        this.xpath = xpath;
+        requireInstance = true;
     }
 
+    /**
+     * Constructs new instance identifier.
+     *
+     * @param xpath
+     * @param requireInstance if instance of data is required
+     * @deprecated Use {@link #create(boolean)}, since Instance Identifier does not have xpath.
+     */
+    @Deprecated
     public InstanceIdentifier(final RevisionAwareXPath xpath, final boolean requireInstance) {
-        this.xpath = xpath;
         this.requireInstance = requireInstance;
     }
 
+    private InstanceIdentifier(final boolean requiredInstance) {
+        this.requireInstance = requiredInstance;
+    }
+
+    public static InstanceIdentifier getInstance() {
+        return INSTANCE_WITH_REQUIRED_TRUE;
+    }
+
+    public static InstanceIdentifier create(final boolean requireInstance) {
+        return requireInstance ? INSTANCE_WITH_REQUIRED_TRUE : INSTANCE_WITH_REQUIRED_FALSE;
+    }
+
     /*
      * (non-Javadoc)
      *
@@ -78,7 +108,7 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
      */
     @Override
     public Object getDefaultValue() {
-        return xpath;
+        return null;
     }
 
     /*
@@ -151,8 +181,9 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
      * InstanceIdentifierTypeDefinition# getPathStatement()
      */
     @Override
+    @Deprecated
     public RevisionAwareXPath getPathStatement() {
-        return xpath;
+        return null;
     }
 
     /*
@@ -170,13 +201,12 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + (requireInstance ? HASH_BOOLEAN_TRUE : HASH_BOOLEAN_FALSE);
-        result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
+        result = prime * result + requireInstance.hashCode();
         return result;
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -187,17 +217,9 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
             return false;
         }
         InstanceIdentifier other = (InstanceIdentifier) obj;
-        if (requireInstance != other.requireInstance) {
-            return false;
-        }
-        if (xpath == null) {
-            if (other.xpath != null) {
-                return false;
-            }
-        } else if (!xpath.equals(other.xpath)) {
-            return false;
-        }
-        return true;
+        return requireInstance.equals(other.requireInstance);
     }
 
+
+
 }
index 63caa24500d6e285a685d80bc1a64ebcb992cfdb..f88e7984a16909b0682c60350662b6acf5aa664a 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
  * Implementation of Yang int16 built-in type. <br>
@@ -16,20 +16,21 @@ import org.opendaylight.yangtools.yang.common.QName;
  *
  * @see AbstractSignedInteger
  */
-public final class Int16 extends AbstractSignedInteger {
-    private static Int16 instance;
-    private static final QName NAME = BaseTypes.constructQName("int16");
+public final class Int16 extends AbstractSignedInteger implements Immutable {
     private static final String DESCRIPTION = "int16  represents integer values between -32768 and 32767, inclusively.";
 
+    private static final Int16 INSTANCE = new Int16();
+
     private Int16() {
-        super(NAME, DESCRIPTION, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        super(BaseTypes.INT16_QNAME, DESCRIPTION, Short.MIN_VALUE, Short.MAX_VALUE, "");
     }
 
+    /**
+     * Returns default instance of int16 type.
+     * @return default instance of int16 type.
+     */
     public static Int16 getInstance() {
-        if (instance == null) {
-            instance = new Int16();
-        }
-        return instance;
+        return INSTANCE;
     }
 
     @Override
@@ -39,7 +40,7 @@ public final class Int16 extends AbstractSignedInteger {
 
     @Override
     public String toString() {
-        return "type " + NAME;
+        return "type " + BaseTypes.INT16_QNAME;
     }
 
 }
index b043d40a7ed7b443557e6a34fc3ccd379db0d1bb..d42768bc71b14b2ffc88008673a049d8dc4e5a85 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
  * Implementation of Yang int32 built-in type. <br>
@@ -18,20 +18,22 @@ import org.opendaylight.yangtools.yang.common.QName;
  * @see AbstractSignedInteger
  *
  */
-public final class Int32 extends AbstractSignedInteger {
-    private static Int32 instance;
-    private static final QName NAME = BaseTypes.constructQName("int32");
+public final class Int32 extends AbstractSignedInteger implements Immutable {
     private static final String DESCRIPTION = "int32  represents integer values between -2147483648 and 2147483647, inclusively.";
 
+
+    private static final Int32 INSTANCE = new Int32();
+
     private Int32() {
-        super(Int32.NAME, Int32.DESCRIPTION, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        super(BaseTypes.INT32_QNAME, Int32.DESCRIPTION, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
     }
 
+    /**
+     * Returns default instance of int32 type.
+     * @return default instance of int32 type.
+     */
     public static Int32 getInstance() {
-        if (instance == null) {
-            instance = new Int32();
-        }
-        return instance;
+        return INSTANCE;
     }
 
     @Override
@@ -41,6 +43,7 @@ public final class Int32 extends AbstractSignedInteger {
 
     @Override
     public String toString() {
-        return "type " + NAME;
+        return "type " + BaseTypes.INT32_QNAME;
     }
+
 }
index 892a1436ee37441dc6d180b0b51cefa5c8b9b2b3..ea6830fa13e90572a7eb2e6c66d89ebec0976bd4 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
  * Implementation of Yang int64 built-in type. <br>
@@ -16,20 +16,22 @@ import org.opendaylight.yangtools.yang.common.QName;
  * type is {@link Long}.
  *
  */
-public final class Int64 extends AbstractSignedInteger {
-    private static Int64 instance;
-    private static final QName NAME = BaseTypes.constructQName("int64");
+public final class Int64 extends AbstractSignedInteger implements Immutable {
     private static final String DESCRIPTION = "int64  represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.";
 
     private Int64() {
-        super(NAME, DESCRIPTION, Long.MIN_VALUE, Long.MAX_VALUE, "");
+        super(BaseTypes.INT64_QNAME, DESCRIPTION, Long.MIN_VALUE, Long.MAX_VALUE, "");
     }
 
+
+    private static final Int64 INSTANCE = new Int64();
+
+    /**
+     * Returns default instance of int64 type.
+     * @return default instance of int64 type.
+     */
     public static Int64 getInstance() {
-        if (instance == null) {
-            instance = new Int64();
-        }
-        return instance;
+        return INSTANCE;
     }
 
     @Override
@@ -39,7 +41,6 @@ public final class Int64 extends AbstractSignedInteger {
 
     @Override
     public String toString() {
-        return "type " + NAME;
+        return "type " + BaseTypes.INT64_QNAME;
     }
-
 }
index 5df2db696f39a1391fd71441016c93dde6d6df0e..61d7a469491e3ee910fe29ebb332e9ae085c989f 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
  * Implementation of Yang int8 built-in type. <br>
@@ -16,20 +16,21 @@ import org.opendaylight.yangtools.yang.common.QName;
  *
  * @see AbstractSignedInteger
  */
-public final class Int8 extends AbstractSignedInteger {
-    private static Int8 instance;
-    private static final QName NAME = BaseTypes.constructQName("int8");
+public final class Int8 extends AbstractSignedInteger implements Immutable {
     private static final String DESCRIPTION = "represents integer values between -128 and 127, inclusively.";
 
     private Int8() {
-        super(NAME, DESCRIPTION, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
+        super(BaseTypes.INT8_QNAME, DESCRIPTION, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
     }
 
+    private static final Int8 INSTANCE = new Int8();
+
+    /**
+     * Returns default instance of int8 type.
+     * @return default instance of int8 type.
+     */
     public static Int8 getInstance() {
-        if (instance == null) {
-            instance = new Int8();
-        }
-        return instance;
+        return INSTANCE;
     }
 
     @Override
@@ -39,7 +40,7 @@ public final class Int8 extends AbstractSignedInteger {
 
     @Override
     public String toString() {
-        return "type " + NAME;
+        return "type " + BaseTypes.INT8_QNAME;
     }
 
 }
index 8ef325cfdf3bbc9aba90840b8b404d2c4bcdb0d9..65fd92458f72564de1f9fd084490854fc4c50498 100644 (file)
@@ -17,6 +17,8 @@ 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;
 
+import com.google.common.base.Preconditions;
+
 /**
  * The <code>default</code> implementation of Instance Leafref Type Definition
  * interface.
@@ -30,9 +32,21 @@ public final class Leafref implements LeafrefTypeDefinition {
     private static final String REF = "https://tools.ietf.org/html/rfc6020#section-9.9";
 
     private final RevisionAwareXPath xpath;
+    private final SchemaPath path;
 
+    @Deprecated
     public Leafref(final RevisionAwareXPath xpath) {
-        this.xpath = xpath;
+        this(PATH,xpath);
+
+    }
+
+    private Leafref(final SchemaPath path, final RevisionAwareXPath target) {
+        this.path = Preconditions.checkNotNull(path,"path must be specified");
+        this.xpath = Preconditions.checkNotNull(target,"target must not be null.");
+    }
+
+    public static Leafref create(final SchemaPath path,final RevisionAwareXPath target) {
+        return new Leafref(path,target);
     }
 
     @Override
@@ -57,7 +71,7 @@ public final class Leafref implements LeafrefTypeDefinition {
 
     @Override
     public SchemaPath getPath() {
-        return PATH;
+        return path;
     }
 
     @Override
@@ -94,7 +108,7 @@ public final class Leafref implements LeafrefTypeDefinition {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/LengthConstraintImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/LengthConstraintImpl.java
new file mode 100644 (file)
index 0000000..bbab950
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util;
+
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+
+/**
+ * {@link Immutable} implementation of {@link LengthConstraint}.
+ *
+ * Length constraint based on supplied parameters with additional behaviour:
+ *
+ * <ul>
+ * <li>{@link LengthConstraint#getErrorAppTag()} returns
+ * <code>length-out-of-specified-bounds</code>
+ * <li>{@link LengthConstraint#getErrorMessage() returns <code>The argument is
+ * out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
+ * </ul
+ */
+final class LengthConstraintImpl implements LengthConstraint, Immutable {
+
+    private final Number min;
+    private final Number max;
+
+    private final String description;
+    private final String reference;
+
+    private final String errorAppTag;
+    private final String errorMessage;
+
+    LengthConstraintImpl(final Number min, final Number max, final Optional<String> description,
+            final Optional<String> reference) {
+        super();
+        this.min = Preconditions.checkNotNull(min, "min must not be null.");
+        this.max = Preconditions.checkNotNull(max, "max must not be null");
+        this.description = description.orNull();
+        this.reference = reference.orNull();
+
+        this.errorAppTag = "length-out-of-specified-bounds";
+        this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public String getErrorAppTag() {
+        return errorAppTag;
+    }
+
+    @Override
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    @Override
+    public String getReference() {
+        return reference;
+    }
+
+    @Override
+    public Number getMin() {
+        return min;
+    }
+
+    @Override
+    public Number getMax() {
+        return max;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((description == null) ? 0 : description.hashCode());
+        result = prime * result + errorAppTag.hashCode();
+        result = prime * result + errorMessage.hashCode();
+        result = prime * result + max.hashCode();
+        result = prime * result + min.hashCode();
+        result = prime * result + ((reference == null) ? 0 : reference.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final LengthConstraintImpl other = (LengthConstraintImpl) obj;
+        if (description == null) {
+            if (other.description != null) {
+                return false;
+            }
+        } else if (!description.equals(other.description)) {
+            return false;
+        }
+        if (errorAppTag == null) {
+            if (other.errorAppTag != null) {
+                return false;
+            }
+        } else if (!errorAppTag.equals(other.errorAppTag)) {
+            return false;
+        }
+        if (errorMessage == null) {
+            if (other.errorMessage != null) {
+                return false;
+            }
+        } else if (!errorMessage.equals(other.errorMessage)) {
+            return false;
+        }
+        if (max != other.max) {
+            return false;
+        }
+        if (min != other.min) {
+            return false;
+        }
+        if (reference == null) {
+            if (other.reference != null) {
+                return false;
+            }
+        } else if (!reference.equals(other.reference)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("LengthConstraintImpl [min=");
+        builder.append(min);
+        builder.append(", max=");
+        builder.append(max);
+        builder.append(", description=");
+        builder.append(description);
+        builder.append(", errorAppTag=");
+        builder.append(errorAppTag);
+        builder.append(", reference=");
+        builder.append(reference);
+        builder.append(", errorMessage=");
+        builder.append(errorMessage);
+        builder.append("]");
+        return builder.toString();
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java
new file mode 100644 (file)
index 0000000..8ab67a7
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util;
+
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+
+/**
+ * {@link Immutable} implementation of {@link PatternConstraint}
+ *
+ * Creates an instance of Range constraint based on supplied parameters with
+ * additional behaviour:
+ *
+ * <ul>
+ * <li>{@link PatternConstraint#getErrorAppTag()} returns
+ * <code>invalid-regular-expression</code>
+ * </ul>
+ *
+ */
+final class PatternConstraintImpl implements PatternConstraint, Immutable {
+
+    private final String regex;
+    private final String description;
+    private final String reference;
+
+    private final String errorAppTag;
+    private final String errorMessage;
+
+    public PatternConstraintImpl(final String regex, final Optional<String> description,
+            final Optional<String> reference) {
+        super();
+        this.regex = Preconditions.checkNotNull(regex, "regex must not be null.");
+        this.description = description.orNull();
+        this.reference = reference.orNull();
+
+        // FIXME: Lookup better suitable error tag.
+        errorAppTag = "invalid-regular-expression";
+        // TODO: add erro message
+        errorMessage = "";
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public String getErrorAppTag() {
+        return errorAppTag;
+    }
+
+    @Override
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    @Override
+    public String getReference() {
+        return reference;
+    }
+
+    @Override
+    public String getRegularExpression() {
+        return regex;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((description == null) ? 0 : description.hashCode());
+        result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
+        result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode());
+        result = prime * result + ((reference == null) ? 0 : reference.hashCode());
+        result = prime * result + regex.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final PatternConstraintImpl other = (PatternConstraintImpl) obj;
+        if (description == null) {
+            if (other.description != null) {
+                return false;
+            }
+        } else if (!description.equals(other.description)) {
+            return false;
+        }
+        if (errorAppTag == null) {
+            if (other.errorAppTag != null) {
+                return false;
+            }
+        } else if (!errorAppTag.equals(other.errorAppTag)) {
+            return false;
+        }
+        if (errorMessage == null) {
+            if (other.errorMessage != null) {
+                return false;
+            }
+        } else if (!errorMessage.equals(other.errorMessage)) {
+            return false;
+        }
+        if (reference == null) {
+            if (other.reference != null) {
+                return false;
+            }
+        } else if (!reference.equals(other.reference)) {
+            return false;
+        }
+        if (regex == null) {
+            if (other.regex != null) {
+                return false;
+            }
+        } else if (!regex.equals(other.regex)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("PatternConstraintImpl [regex=");
+        builder.append(regex);
+        builder.append(", description=");
+        builder.append(description);
+        builder.append(", reference=");
+        builder.append(reference);
+        builder.append(", errorAppTag=");
+        builder.append(errorAppTag);
+        builder.append(", errorMessage=");
+        builder.append(errorMessage);
+        builder.append("]");
+        return builder.toString();
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java
new file mode 100644 (file)
index 0000000..70acbc8
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util;
+
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+
+/**
+ * {@link Immutable} implementation of {@link LengthConstraint}.
+ *
+ * Range constraint based on supplied parameters with additional behaviour:
+ *
+ * <ul>
+ * <li>{@link RangeConstraint#getErrorAppTag()} returns
+ * <code>range-out-of-specified-bounds</code>
+ * <li>{@link RangeConstraint#getErrorMessage() returns <code>The argument is
+ * out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
+ * </ul>
+ */
+final class RangeConstraintImpl implements RangeConstraint, Immutable {
+    private final Number min;
+    private final Number max;
+
+    private final String description;
+    private final String reference;
+
+    private final String errorAppTag;
+    private final String errorMessage;
+
+    RangeConstraintImpl(final Number min, final Number max, final Optional<String> description,
+            final Optional<String> reference) {
+        super();
+        this.min = Preconditions.checkNotNull(min, "min must not be null.");
+        this.max = Preconditions.checkNotNull(max, "max must not be null.");
+        this.description = description.orNull();
+        this.reference = reference.orNull();
+
+        this.errorAppTag = "range-out-of-specified-bounds";
+        this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public String getErrorAppTag() {
+        return errorAppTag;
+    }
+
+    @Override
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    @Override
+    public String getReference() {
+        return reference;
+    }
+
+    @Override
+    public Number getMin() {
+        return min;
+    }
+
+    @Override
+    public Number getMax() {
+        return max;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((description == null) ? 0 : description.hashCode());
+        result = prime * result + errorAppTag.hashCode();
+        result = prime * result + errorMessage.hashCode();
+        result = prime * result + max.hashCode();
+        result = prime * result + min.hashCode();
+        result = prime * result + ((reference == null) ? 0 : reference.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final RangeConstraintImpl other = (RangeConstraintImpl) obj;
+        if (description == null) {
+            if (other.description != null) {
+                return false;
+            }
+        } else if (!description.equals(other.description)) {
+            return false;
+        }
+        if (max == null) {
+            if (other.max != null) {
+                return false;
+            }
+        } else if (!max.equals(other.max)) {
+            return false;
+        }
+        if (min == null) {
+            if (other.min != null) {
+                return false;
+            }
+        } else if (!min.equals(other.min)) {
+            return false;
+        }
+        if (reference == null) {
+            if (other.reference != null) {
+                return false;
+            }
+        } else if (!reference.equals(other.reference)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder builder = new StringBuilder();
+        builder.append("RangeConstraintImpl [min=");
+        builder.append(min);
+        builder.append(", max=");
+        builder.append(max);
+        builder.append(", description=");
+        builder.append(description);
+        builder.append(", reference=");
+        builder.append(reference);
+        builder.append(", errorAppTag=");
+        builder.append(errorAppTag);
+        builder.append(", errorMessage=");
+        builder.append(errorMessage);
+        builder.append("]");
+        return builder.toString();
+    }
+}
\ No newline at end of file
index c5852696e4ec14b9c516d00aae66b1de5397a72b..3ef6d5a64e12eb5a4b08ebdf6ab94f5acbd11f52 100644 (file)
@@ -10,9 +10,9 @@ package org.opendaylight.yangtools.yang.model.util;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 
 /**
- * The <code>default</code> implementation of Instance Rewision Aware XPath
+ * The <code>helper</code> implementation of Instance Rewision Aware XPath
  * interface.
- * 
+ *
  * @see RevisionAwareXPath
  */
 public class RevisionAwareXPathImpl implements RevisionAwareXPath {
@@ -23,7 +23,7 @@ public class RevisionAwareXPathImpl implements RevisionAwareXPath {
     private static final int HASH_BOOLEAN_TRUE = 1231;
     private static final int HASH_BOOLEAN_FALSE = 1237;
 
-    public RevisionAwareXPathImpl(String xpath, boolean absolute) {
+    public RevisionAwareXPathImpl(final String xpath, final boolean absolute) {
         this.xpath = xpath;
         this.absolute = absolute;
     }
@@ -43,7 +43,7 @@ public class RevisionAwareXPathImpl implements RevisionAwareXPath {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
index a6623b6d2d2fdc506556ef5f62a6ce9229d3c8bc..857e6a4d030037e89bc8dc7b01607149542a463c 100644 (file)
@@ -7,10 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import java.util.ArrayList;
 import java.util.Collections;
 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;
@@ -19,15 +19,16 @@ 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 com.google.common.base.Optional;
+
 /**
  * The <code>default</code> implementation of String Type Definition interface.
  *
  * @see StringTypeDefinition
  */
-public final class StringType implements StringTypeDefinition {
-    private static final StringType INSTANCE = new StringType();
-    private final QName name = BaseTypes.constructQName("string");
-    private final SchemaPath path = SchemaPath.create(Collections.singletonList(name), true);
+public final class StringType implements StringTypeDefinition, Immutable {
+    private static final QName NAME = BaseTypes.STRING_QNAME;
+    private static final SchemaPath PATH = SchemaPath.create(Collections.singletonList(NAME), true);
     private static final String DEFAULT_VALUE = "";
     private static final String DESCRIPTION = "";
     private static final String REFERENCE = "";
@@ -35,13 +36,13 @@ public final class StringType implements StringTypeDefinition {
     private final List<PatternConstraint> patterns;
     private static final String UNITS = "";
 
+    private static final StringType INSTANCE = new StringType();
+
     /**
      * Default Constructor.
      */
     private StringType() {
-        final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-        constraints.add(BaseConstraints.lengthConstraint(0, Integer.MAX_VALUE, "", ""));
-        lengthStatements = Collections.unmodifiableList(constraints);
+        lengthStatements = Collections.singletonList(BaseConstraints.newLengthConstraint(0, Integer.MAX_VALUE, Optional.of(""), Optional.of("")));
         patterns = Collections.emptyList();
     }
 
@@ -89,7 +90,7 @@ public final class StringType implements StringTypeDefinition {
      */
     @Override
     public QName getQName() {
-        return name;
+        return NAME;
     }
 
     /*
@@ -99,7 +100,7 @@ public final class StringType implements StringTypeDefinition {
      */
     @Override
     public SchemaPath getPath() {
-        return path;
+        return PATH;
     }
 
     /*
@@ -166,8 +167,8 @@ public final class StringType implements StringTypeDefinition {
         final int prime = 31;
         int result = 1;
         result = prime * result + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result + ((path == null) ? 0 : path.hashCode());
+        result = prime * result + NAME.hashCode();
+        result = prime * result + PATH.hashCode();
         result = prime * result + ((patterns == null) ? 0 : patterns.hashCode());
         return result;
     }
@@ -191,20 +192,6 @@ public final class StringType implements StringTypeDefinition {
         } else if (!lengthStatements.equals(other.lengthStatements)) {
             return false;
         }
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.getPath().equals(other.path.getPath())) {
-            return false;
-        }
         if (patterns == null) {
             if (other.patterns != null) {
                 return false;
@@ -219,9 +206,9 @@ public final class StringType implements StringTypeDefinition {
     public String toString() {
         StringBuilder builder = new StringBuilder();
         builder.append("StringType [name=");
-        builder.append(name);
+        builder.append(NAME);
         builder.append(", path=");
-        builder.append(path);
+        builder.append(PATH);
         builder.append(", defaultValue=");
         builder.append(DEFAULT_VALUE);
         builder.append(", description=");
index 4c386c48d5b3988f083bb794f2840e745158746f..d557449220a153d725772905490748b080c8fe35 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
  * Implementation of Yang uint16 built-in type. <br>
@@ -15,21 +15,18 @@ import org.opendaylight.yangtools.yang.common.QName;
  * counterpart of Yang uint16 built-in type is {@link Integer}.
  *
  */
-public final class Uint16 extends AbstractUnsignedInteger {
+public final class Uint16 extends AbstractUnsignedInteger implements Immutable {
     public static final int MAX_VALUE = 65535;
-    private static Uint16 instance;
-    private static final QName NAME = BaseTypes.constructQName("uint16");
     private static final String DESCRIPTION = "uint16 represents integer values between 0 and 65535, inclusively.";
 
+    private static Uint16 INSTANCE = new Uint16();
+
     private Uint16() {
-        super(NAME, DESCRIPTION, MAX_VALUE, "");
+        super(BaseTypes.UINT16_QNAME, DESCRIPTION, MAX_VALUE, "");
     }
 
     public static Uint16 getInstance() {
-        if (instance == null) {
-            instance = new Uint16();
-        }
-        return instance;
+        return INSTANCE;
     }
 
     @Override
@@ -39,7 +36,7 @@ public final class Uint16 extends AbstractUnsignedInteger {
 
     @Override
     public String toString() {
-        return "type " + NAME;
+        return "type " + BaseTypes.UINT16_QNAME;
     }
 
 }
index dd3183d51bf028fdc605e3381f28fe7920224122..aef0f8fac27ff60928a27d9b251b772c0fab3f54 100644 (file)
@@ -7,28 +7,26 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
  * Implementation of Yang uint32 built-in type. <br>
  * uint32 represents integer values between 0 and 4294967295, inclusively.
  *
  */
-public final class Uint32 extends AbstractUnsignedInteger {
+public final class Uint32 extends AbstractUnsignedInteger implements Immutable {
     public static final long MAX_VALUE = 4294967295L;
-    private static Uint32 instance;
-    private static final QName NAME = BaseTypes.constructQName("uint32");
     private static final String DESCRIPTION = "uint32 represents integer values between 0 and 4294967295, inclusively.";
 
+    private static final Uint32 INSTANCE = new Uint32();
+
+
     private Uint32() {
-        super(NAME, DESCRIPTION, MAX_VALUE, "");
+        super(BaseTypes.UINT32_QNAME, DESCRIPTION, MAX_VALUE, "");
     }
 
     public static Uint32 getInstance() {
-        if (instance == null) {
-            instance = new Uint32();
-        }
-        return instance;
+        return INSTANCE;
     }
 
     @Override
@@ -38,7 +36,7 @@ public final class Uint32 extends AbstractUnsignedInteger {
 
     @Override
     public String toString() {
-        return "type " + NAME;
+        return "type " + BaseTypes.UINT32_QNAME;
     }
 
 }
index 555b76f5feb96ac74a99ee4d285a5edb707b9bae..3ec9d25369eb3c966fab370a661cc0a8aea750ab 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.yangtools.yang.model.util;
 
 import java.math.BigInteger;
 
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
  * Implementation of Yang uint64 built-in type. <br>
@@ -18,21 +18,18 @@ import org.opendaylight.yangtools.yang.common.QName;
  * {@link BigInteger}.
  *
  */
-public final class Uint64 extends AbstractUnsignedInteger {
+public final class Uint64 extends AbstractUnsignedInteger implements Immutable {
     public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
-    private static Uint64 instance;
-    private static final QName NAME = BaseTypes.constructQName("uint64");
     private static final String DESCRIPTION = "uint64 represents integer values between 0 and 18446744073709551615, inclusively.";
 
+    private static final Uint64 INSTANCE = new Uint64();
+
     private Uint64() {
-        super(NAME, DESCRIPTION, MAX_VALUE, "");
+        super(BaseTypes.UINT64_QNAME, DESCRIPTION, MAX_VALUE, "");
     }
 
     public static Uint64 getInstance() {
-        if (instance == null) {
-            instance = new Uint64();
-        }
-        return instance;
+        return INSTANCE;
     }
 
     @Override
@@ -42,7 +39,7 @@ public final class Uint64 extends AbstractUnsignedInteger {
 
     @Override
     public String toString() {
-        return "type " + NAME;
+        return "type " + BaseTypes.UINT64_QNAME;
     }
 
 }
index 2212585f0238e69746df6a75f79b2e86424077cd..f44ba754a7d62c8c94310382c1e0b2c569799f62 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
  * Implementation of Yang uint8 built-in type. <br>
@@ -15,21 +15,18 @@ import org.opendaylight.yangtools.yang.common.QName;
  *
  * @see AbstractUnsignedInteger
  */
-public final class Uint8 extends AbstractUnsignedInteger {
+public final class Uint8 extends AbstractUnsignedInteger implements Immutable {
     public static final int MAX_VALUE = 255;
-    private static Uint8 instance;
-    private static final QName NAME = BaseTypes.constructQName("uint8");
     private static final String DESCRIPTION = "uint8  represents integer values between 0 and 255, inclusively.";
 
+    private static final Uint8 INSTANCE = new Uint8();
+
     private Uint8() {
-        super(NAME, DESCRIPTION, MAX_VALUE, "");
+        super(BaseTypes.UINT8_QNAME, DESCRIPTION, MAX_VALUE, "");
     }
 
     public static Uint8 getInstance() {
-        if (instance == null) {
-            instance = new Uint8();
-        }
-        return instance;
+        return INSTANCE;
     }
 
     @Override
@@ -39,7 +36,7 @@ public final class Uint8 extends AbstractUnsignedInteger {
 
     @Override
     public String toString() {
-        return "type " + NAME;
+        return "type " + BaseTypes.UINT8_QNAME;
     }
 
 }
index 99390b09803a438152bba18f0cee6ceaf8e196b5..3386bb720f5e238d8760f6b1cc7bc765070d3e7e 100644 (file)
@@ -17,18 +17,23 @@ 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;
 
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
 public final class UnionType implements UnionTypeDefinition {
-    private final QName name = BaseTypes.constructQName("union");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
+    private final SchemaPath path = SchemaPath.create(Collections.singletonList(BaseTypes.UNION_QNAME),true);
     private static final String DESCRIPTION = "The union built-in type represents a value that corresponds to one of its member types.";
     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.12";
     private final List<TypeDefinition<?>> types;
 
-    public UnionType(List<TypeDefinition<?>> types) {
-        if (types == null) {
-            throw new IllegalArgumentException("When the type is 'union', the 'type' statement MUST be present.");
-        }
-        this.types = types;
+    @Deprecated
+    public UnionType(final List<TypeDefinition<?>> types) {
+        Preconditions.checkNotNull(types,"When the type is 'union', the 'type' statement MUST be present.");
+        this.types = ImmutableList.copyOf(types);
+    }
+
+    public static UnionType create(final List<TypeDefinition<?>> types) {
+        return new UnionType(types);
     }
 
     @Override
@@ -48,7 +53,7 @@ public final class UnionType implements UnionTypeDefinition {
 
     @Override
     public QName getQName() {
-        return name;
+        return BaseTypes.UNION_QNAME;
     }
 
     @Override
@@ -90,7 +95,7 @@ public final class UnionType implements UnionTypeDefinition {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -111,7 +116,7 @@ public final class UnionType implements UnionTypeDefinition {
     public String toString() {
         StringBuilder builder = new StringBuilder();
         builder.append("type ");
-        builder.append(name);
+        builder.append(BaseTypes.UNION_QNAME);
         builder.append(" (types=[");
         for (TypeDefinition<?> td : types) {
             builder.append(", " + td.getQName().getLocalName());
index 23bb8395ca059cf83eeb61e7863a3e4d977d43d2..2e23b81db600af9e5db25af9b484a543aee50527 100644 (file)
@@ -19,6 +19,16 @@ import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition;
 
+/**
+ * Utility implementation of unknown type definition.
+ *
+ * Unknown type definition is derived type, for
+ * which base built-in type is not yet known. This types
+ * are possible during parsing and resolving of YANG model
+ * without all requisites allready processed.
+ *
+ *
+ */
 public final class UnknownType implements UnknownTypeDefinition {
 
     private final QName name;
@@ -66,12 +76,12 @@ public final class UnknownType implements UnknownTypeDefinition {
             this.path = BaseTypes.schemaPath(name);
         }
 
-        public Builder description(String description) {
+        public Builder description(final String description) {
             this.description = description;
             return this;
         }
 
-        public Builder reference(String reference) {
+        public Builder reference(final String reference) {
             this.reference = reference;
             return this;
         }
@@ -106,12 +116,12 @@ public final class UnknownType implements UnknownTypeDefinition {
             return this;
         }
 
-        public Builder status(Status status) {
+        public Builder status(final Status status) {
             this.status = status;
             return this;
         }
 
-        public Builder units(String units) {
+        public Builder units(final String units) {
             this.units = units;
             return this;
         }
@@ -126,7 +136,7 @@ public final class UnknownType implements UnknownTypeDefinition {
         }
     }
 
-    private UnknownType(Builder builder) {
+    private UnknownType(final Builder builder) {
         this.name = builder.name;
         this.path = builder.path;
         this.description = builder.description;
@@ -296,7 +306,7 @@ public final class UnknownType implements UnknownTypeDefinition {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
index f156dafabcfe7ee550d6d8a3d59fb86e3f4cf30c..98c63d022ba6a8a3a734a7b03897e8526e174afc 100644 (file)
@@ -7,83 +7,40 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import java.util.HashSet;
-import java.util.Set;
-
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
+/**
+ * Utility class which provides various helper methods for working with YANG
+ * built-in types.
+ *
+ * @deprecated Use {@link BaseTypes} instead.
+ */
+@Deprecated
 public final class YangTypesConverter {
-    private static final Set<String> BASE_YANG_TYPES = new HashSet<String>();
-
     /**
      * It isn't desirable to create the instances of this class
      */
     private YangTypesConverter() {
     }
 
-    static {
-        BASE_YANG_TYPES.add("binary");
-        BASE_YANG_TYPES.add("bits");
-        BASE_YANG_TYPES.add("boolean");
-        BASE_YANG_TYPES.add("decimal64");
-        BASE_YANG_TYPES.add("empty");
-        BASE_YANG_TYPES.add("enumeration");
-        BASE_YANG_TYPES.add("identityref");
-        BASE_YANG_TYPES.add("instance-identifier");
-        BASE_YANG_TYPES.add("int8");
-        BASE_YANG_TYPES.add("int16");
-        BASE_YANG_TYPES.add("int32");
-        BASE_YANG_TYPES.add("int64");
-        BASE_YANG_TYPES.add("leafref");
-        BASE_YANG_TYPES.add("string");
-        BASE_YANG_TYPES.add("uint8");
-        BASE_YANG_TYPES.add("uint16");
-        BASE_YANG_TYPES.add("uint32");
-        BASE_YANG_TYPES.add("uint64");
-        BASE_YANG_TYPES.add("union");
-    }
-
-    public static boolean isBaseYangType(String type) {
-        return BASE_YANG_TYPES.contains(type);
+    @Deprecated
+    public static boolean isBaseYangType(final String type) {
+        return BaseTypes.isYangBuildInType(type);
     }
 
-    public static TypeDefinition<?> javaTypeForBaseYangType(String typeName) {
-        TypeDefinition<?> type = null;
-
-        if (typeName.startsWith("int")) {
-            if ("int8".equals(typeName)) {
-                type = Int8.getInstance();
-            } else if ("int16".equals(typeName)) {
-                type = Int16.getInstance();
-            } else if ("int32".equals(typeName)) {
-                type = Int32.getInstance();
-            } else if ("int64".equals(typeName)) {
-                type = Int64.getInstance();
-            }
-        } else if (typeName.startsWith("uint")) {
-            if ("uint8".equals(typeName)) {
-                type = Uint8.getInstance();
-            } else if ("uint16".equals(typeName)) {
-                type = Uint16.getInstance();
-            } else if ("uint32".equals(typeName)) {
-                type = Uint32.getInstance();
-            } else if ("uint64".equals(typeName)) {
-                type = Uint64.getInstance();
-            }
-        } else if ("string".equals(typeName)) {
-            type = StringType.getInstance();
-        } else if ("binary".equals(typeName)) {
-            type = BinaryType.getInstance();
-        } else if ("boolean".equals(typeName)) {
-            type = BooleanType.getInstance();
-        } else if ("empty".equals(typeName)) {
-            type = EmptyType.getInstance();
-        } else if ("instance-identifier".equals(typeName)) {
-            // FIXME
-            type = new InstanceIdentifier(null, true);
-        }
-
-        return type;
+    /**
+     *
+     * Returns default instance of built-in type for supplied string.
+     *
+     * @param typeName
+     * @return default instance of built-in type for supplied string or null, if
+     *         default instance does not exist.
+     *
+     * @deprecated Use {@link BaseTypes#defaultBaseTypeFor(String)} instead.
+     */
+    @Deprecated
+    public static TypeDefinition<?> javaTypeForBaseYangType(final String typeName) {
+        return BaseTypes.defaultBaseTypeFor(typeName).orNull();
     }
 
 }
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/package-info.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/package-info.java
new file mode 100644 (file)
index 0000000..ec30f79
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+/**
+ * Utility classes and implementations for concepts defined in yang-model-api.
+ *
+ *
+ * <h2>Base Types</h2>
+ *
+ * YANG specification defines several base types, for which YANG model does not
+ * exists, but have same properties as derived types. This package provides
+ * implementation of {@link org.opendaylight.yangtools.yang.model.api.TypeDefinition}
+ * interface and it's subinterfaces which represent YANG base types and
+ * types derived from them.
+ * <p>
+ * YANG Specification implicitly defines two types of base types - ones with default version,
+ * and ones which needs to be derived.
+ *
+ * <h3>Base built-in types with default instance and semantics</h3>
+ *
+ *    <dl>
+ *       <dt>empty</dt>
+ *       <dd>A leaf that does not have any value - {@link org.opendaylight.yangtools.yang.model.util.EmptyType}</dd>
+ *       <dt>binary</dt>
+ *       <dd>Any binary data - {@link org.opendaylight.yangtools.yang.model.util.BinaryType}
+ *       <dt>boolean</dt>
+ *       <dd>"true" or "false" - {@link org.opendaylight.yangtools.yang.model.util.BinaryType}</dd>
+ *       <dt>int8</dt>
+ *       <dd>8-bit signed integer - {@link org.opendaylight.yangtools.yang.model.util.Int8}</dd>
+ *       <dt>int16</dt>
+ *       <dd>16-bit signed integer - {@link org.opendaylight.yangtools.yang.model.util.Int16}</dd>
+ *       <dt>int32</dt>
+ *       <dd>32-bit signed integer - {@link org.opendaylight.yangtools.yang.model.util.Int32}</dd>
+ *       <dt>int64</dt>
+ *       <dd>64-bit signed integer - {@link org.opendaylight.yangtools.yang.model.util.Int64}</dd>
+ *       <dt>uint8</dt>
+ *       <dd>8-bit unsigned integer -{@link org.opendaylight.yangtools.yang.model.util.Uint8}</dd>
+ *       <dt>uint16</dt>
+ *       <dd>16-bit unsigned integer - {@link org.opendaylight.yangtools.yang.model.util.Int16}</dd>
+ *       <dt>uint32</dt>
+ *       <dd>32-bit unsigned integer - {@link org.opendaylight.yangtools.yang.model.util.Int32}</dd>
+ *       <dt>uint64</dt>
+ *       <dd>64-bit unsigned integer -{@link org.opendaylight.yangtools.yang.model.util.Int64}</dd>
+ *       <dt>instance-identifier</dt>
+ *       <dd>References a data tree node - {@link org.opendaylight.yangtools.yang.model.util.InstanceIdentifier}</dd>
+ *       <dt>string</dt>
+ *       <dd>{@link org.opendaylight.yangtools.yang.model.util.StringType}</dd>
+ *     </dl>
+ *
+ * Common trait of base types with default instance is, that there is no requirement
+ * for user input in YANG schema to further modify this types.
+ * <p>
+ * The implementation classes for these base types contains static method <code>getInstance()</code>
+ * which provides reusable {@link org.opendaylight.yangtools.concepts.Immutable} instance of type.
+ *
+ * <h3>Base built-in types without default instance</h3>
+ *
+ *     <dl>
+ *       <dt>bits</dt>
+ *       <dd>A set of bits or flags - {@link org.opendaylight.yangtools.yang.model.util.BitsType}</dd>
+ *       <dt>decimal64</dt>
+ *       <dd>64-bit signed decimal number - {@link org.opendaylight.yangtools.yang.model.util.Decimal64}</dd>
+ *       <dt>enumeration</dt>
+ *       <dd>Enumerated strings - {@link org.opendaylight.yangtools.yang.model.util.EnumerationType}</dd>
+ *       <dt>union</dt>
+ *       <dd>Choice of member types - {@link org.opendaylight.yangtools.yang.model.util.UnionType}</dd>
+ *       <dt>identity-ref</dt>
+ *       <dd>A reference to an abstract identity - {@link org.opendaylight.yangtools.yang.model.util.IdentityrefType}</dd>
+ *       <dt>leafref</dt>
+ *       <dd>A reference to a leaf instance - {@link org.opendaylight.yangtools.yang.model.util.Leafref}</dd>
+ *     </dl>
+ *
+ * Common trait of these base types without default instance is, that they require
+ * user input in YANG schema to create instance of this types, and may have infinity number of
+ * possible permutations.
+ * <p>
+ * The implementations have static factory method <code>create(SchemaPath,...)</code>
+ * which provides {@link org.opendaylight.yangtools.concepts.Immutable} instance of type.
+ *
+ */
+package org.opendaylight.yangtools.yang.model.util;
\ No newline at end of file