*/
package org.opendaylight.yangtools.yang.model.util;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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>
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
*/
package org.opendaylight.yangtools.yang.model.util;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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>
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
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 <<i>min</i>, <i>max</i> ></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 <<i>min</i>, <i>max</i> ></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 <<i>min</i>, <i>max</i> ></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 <<i>min</i>, <i>max</i> ></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));
}
}
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");
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
}
/**
- * 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);
}
* @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.");
}
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;
+ }
+
}
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.
*
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() {
*/
@Override
public QName getQName() {
- return name;
+ return QNAME;
}
/*
*/
@Override
public SchemaPath getPath() {
- return path;
+ return PATH;
}
/*
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;
}
} 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;
}
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=");
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 "
* 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");
}
/**
*
* @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);
}
/*
*/
@Override
public QName getQName() {
- return name;
+ return NAME;
}
/*
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;
}
} 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;
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=");
private BooleanType() {
}
+ /**
+ * Returns default instance of boolean built-in type.
+ * @return default instance of boolean built-in type.
+ */
public static BooleanType getInstance() {
return INSTANCE;
}
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;
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;
}
}
- private void traverseModule(DataNodeContainer dataNode) {
+ private void traverseModule(final DataNodeContainer dataNode) {
final Module module;
if (dataNode instanceof Module) {
module = (Module) dataNode;
}
}
- private void traverseGroupings(DataNodeContainer dataNode) {
+ private void traverseGroupings(final DataNodeContainer dataNode) {
final Set<GroupingDefinition> groupings = dataNode.getGroupings();
if (groupings != null) {
for (GroupingDefinition grouping : groupings) {
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.
*
* @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;
*
* @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(
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.
*
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);
}
@Override
public QName getQName() {
- return name;
+ return NAME;
}
@Override
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;
}
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;
@Override
public String toString() {
- return Decimal64.class.getSimpleName() + "[qname=" + name + ", fractionDigits=" + fractionDigits + "]";
+ return Decimal64.class.getSimpleName() + "[qname=" + NAME + ", fractionDigits=" + fractionDigits + "]";
}
}
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";
}
public static EmptyType getInstance() {
- if (instance == null) {
- instance = new EmptyType();
- }
- return instance;
+ return INSTANCE;
}
@Override
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;
/**
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);
}
/*
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;
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;
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;
}
}
}
- private ExtendedType(Builder builder) {
+ private ExtendedType(final Builder builder) {
this.typeName = builder.typeName;
this.baseType = builder.baseType;
this.path = builder.path;
}
@Override
- public boolean equals(Object o) {
+ public boolean equals(final Object o) {
if (this == o) {
return true;
}
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.
* @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
@Override
public QName getQName() {
- return name;
+ return NAME;
}
@Override
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;
* 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)
*
*/
@Override
public Object getDefaultValue() {
- return xpath;
+ return null;
}
/*
* InstanceIdentifierTypeDefinition# getPathStatement()
*/
@Override
+ @Deprecated
public RevisionAwareXPath getPathStatement() {
- return xpath;
+ return null;
}
/*
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;
}
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);
}
+
+
}
*/
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>
*
* @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
@Override
public String toString() {
- return "type " + NAME;
+ return "type " + BaseTypes.INT16_QNAME;
}
}
*/
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>
* @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
@Override
public String toString() {
- return "type " + NAME;
+ return "type " + BaseTypes.INT32_QNAME;
}
+
}
*/
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>
* 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
@Override
public String toString() {
- return "type " + NAME;
+ return "type " + BaseTypes.INT64_QNAME;
}
-
}
*/
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>
*
* @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
@Override
public String toString() {
- return "type " + NAME;
+ return "type " + BaseTypes.INT8_QNAME;
}
}
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.
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
@Override
public SchemaPath getPath() {
- return PATH;
+ return path;
}
@Override
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
--- /dev/null
+/*
+ * 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 <<i>min</i>, <i>max</i> ></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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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 <<i>min</i>, <i>max</i> ></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
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 {
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;
}
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
*/
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;
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 = "";
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();
}
*/
@Override
public QName getQName() {
- return name;
+ return NAME;
}
/*
*/
@Override
public SchemaPath getPath() {
- return path;
+ return PATH;
}
/*
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;
}
} 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;
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=");
*/
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>
* 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
@Override
public String toString() {
- return "type " + NAME;
+ return "type " + BaseTypes.UINT16_QNAME;
}
}
*/
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
@Override
public String toString() {
- return "type " + NAME;
+ return "type " + BaseTypes.UINT32_QNAME;
}
}
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>
* {@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
@Override
public String toString() {
- return "type " + NAME;
+ return "type " + BaseTypes.UINT64_QNAME;
}
}
*/
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>
*
* @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
@Override
public String toString() {
- return "type " + NAME;
+ return "type " + BaseTypes.UINT8_QNAME;
}
}
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
@Override
public QName getQName() {
- return name;
+ return BaseTypes.UNION_QNAME;
}
@Override
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
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());
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;
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;
}
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;
}
}
}
- private UnknownType(Builder builder) {
+ private UnknownType(final Builder builder) {
this.name = builder.name;
this.path = builder.path;
this.description = builder.description;
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
*/
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();
}
}
--- /dev/null
+/*
+ * 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