From af2244fc083e788645ac689b543af447efdf5b70 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 28 May 2015 01:06:14 +0200 Subject: [PATCH] BUG-3399: fix BaseYangTypes' range constraints 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 --- .../yangtools/sal/binding/yang/types/BaseYangTypes.java | 8 ++++---- .../yangtools/yang/model/util/BaseConstraints.java | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java b/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java index d0b02e6d2f..7aeaf1d9c5 100644 --- a/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java +++ b/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java @@ -81,7 +81,7 @@ public final class BaseYangTypes { /** * Type representation of uint8 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)); /** * Type representation of uint16 YANG type @@ -91,13 +91,13 @@ public final class BaseYangTypes { /** * Type representation of uint32 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)); /** * Type representation of uint64 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(); @@ -219,7 +219,7 @@ public final class BaseYangTypes { } }; - private static Restrictions singleRangeRestrictions(final Number min, final Number max) { + private static Restrictions singleRangeRestrictions(final T min, final T max) { return new Restrictions() { @Override public boolean isEmpty() { diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java index 9fe6805c81..8a186ce853 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java @@ -7,12 +7,11 @@ */ 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 com.google.common.base.Optional; - /** * Utility class which provides factory methods to construct Constraints. * @@ -67,13 +66,14 @@ public final class BaseConstraints { * * @see RangeConstraint * + * @param 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} */ - public static RangeConstraint newRangeConstraint(final Number min, final Number max, final Optional description, + public static RangeConstraint newRangeConstraint(final T min, final T max, final Optional description, final Optional reference) { return new RangeConstraintImpl(min, max, description, reference); } -- 2.36.6