Constraints Number type should match the Java type a particular type is
bound to. Users dealing with values trying to correlate it to the
metadata available can then rely on things like
value.getClass.cast(rangeMin) just working instead of concocting
conversions to deal with all possible combinations of types.
Also changes BaseConstraints to enforce the two components of a
constraint being the same type, preventing things like min being Integer
while max is a Long.
Change-Id: I38e646b4c08b032248349f3e618354aa2114efd3
Signed-off-by: Robert Varga <rovarga@cisco.com>
/**
* <code>Type</code> representation of <code>uint8</code> YANG type
*/
/**
* <code>Type</code> representation of <code>uint8</code> YANG type
*/
- public static final Type UINT8_TYPE = Types.typeForClass(Short.class, singleRangeRestrictions(0, 255));
+ public static final Type UINT8_TYPE = Types.typeForClass(Short.class, singleRangeRestrictions((short)0, (short)255));
/**
* <code>Type</code> representation of <code>uint16</code> YANG type
/**
* <code>Type</code> representation of <code>uint16</code> YANG type
/**
* <code>Type</code> representation of <code>uint32</code> YANG type
*/
/**
* <code>Type</code> representation of <code>uint32</code> YANG type
*/
- public static final Type UINT32_TYPE = Types.typeForClass(Long.class, singleRangeRestrictions(0, 4294967295L));
+ public static final Type UINT32_TYPE = Types.typeForClass(Long.class, singleRangeRestrictions(0L, 4294967295L));
/**
* <code>Type</code> representation of <code>uint64</code> YANG type
*/
public static final Type UINT64_TYPE = Types.typeForClass(BigInteger.class,
/**
* <code>Type</code> representation of <code>uint64</code> YANG type
*/
public static final Type UINT64_TYPE = Types.typeForClass(BigInteger.class,
- singleRangeRestrictions(0, new BigInteger("18446744073709551615")));
+ singleRangeRestrictions(BigInteger.ZERO, new BigInteger("18446744073709551615")));
public static final Type UNION_TYPE = new UnionType();
public static final Type UNION_TYPE = new UnionType();
- private static Restrictions singleRangeRestrictions(final Number min, final Number max) {
+ private static <T extends Number> Restrictions singleRangeRestrictions(final T min, final T max) {
return new Restrictions() {
@Override
public boolean isEmpty() {
return new Restrictions() {
@Override
public boolean isEmpty() {
*/
package org.opendaylight.yangtools.yang.model.util;
*/
package org.opendaylight.yangtools.yang.model.util;
+import com.google.common.base.Optional;
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 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.
*
/**
* Utility class which provides factory methods to construct Constraints.
*
*
* @see RangeConstraint
*
*
* @see RangeConstraint
*
+ * @param <T> Type of constraint
* @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}
*/
* @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,
+ public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max, final Optional<String> description,
final Optional<String> reference) {
return new RangeConstraintImpl(min, max, description, reference);
}
final Optional<String> reference) {
return new RangeConstraintImpl(min, max, description, reference);
}