Expose Uint*.{MIN,MAX}_VALUE constants 25/84025/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 28 Aug 2019 00:19:20 +0000 (02:19 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 28 Aug 2019 00:20:23 +0000 (02:20 +0200)
These contants are useful for outside users, as they allow them
to reference known invariants.

Change-Id: I28467737a2dfe5cac811e7ecbc9ead75c47d1344
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/Uint16.java
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/Uint32.java
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/Uint64.java
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/Uint8.java

index bbfbbdcab88151a24fd17c11d36dbdfa74c547f6..439ee37e3f776ca891d625a3d5ead1b15ad93f5b 100644 (file)
@@ -44,13 +44,13 @@ public class Uint16 extends Number implements CanonicalValue<Uint16> {
 
     private static final CanonicalValueSupport<Uint16> SUPPORT = new Support();
     private static final long serialVersionUID = 1L;
-    private static final int MIN_VALUE = 0;
-    private static final int MAX_VALUE = 65535;
+    private static final int MIN_VALUE_INT = 0;
+    private static final int MAX_VALUE_INT = 65535;
 
     /**
      * Cache of first 256 values.
      */
-    private static final Uint16[] CACHE = new Uint16[Uint8.MAX_VALUE];
+    private static final Uint16[] CACHE = new Uint16[Uint8.MAX_VALUE_SHORT];
 
     /**
      * Commonly encountered values.
@@ -61,13 +61,16 @@ public class Uint16 extends Number implements CanonicalValue<Uint16> {
         new Uint16((short)65535),
     };
 
+    public static final Uint16 MIN_VALUE = valueOf(MIN_VALUE_INT);
+    public static final Uint16 MAX_VALUE = valueOf(MAX_VALUE_INT);
+
     /**
      * Tunable weak LRU cache for other values. By default it holds {@value #DEFAULT_LRU_SIZE} entries. This can be
      * changed via {@value #LRU_SIZE_PROPERTY} system property.
      */
     private static final int DEFAULT_LRU_SIZE = 1024;
     private static final String LRU_SIZE_PROPERTY = "org.opendaylight.yangtools.yang.common.Uint16.LRU.size";
-    private static final int MAX_LRU_SIZE = MAX_VALUE + 1;
+    private static final int MAX_LRU_SIZE = MAX_VALUE_INT + 1;
     private static final int LRU_SIZE;
 
     static {
@@ -127,22 +130,24 @@ public class Uint16 extends Number implements CanonicalValue<Uint16> {
     }
 
     public static Uint16 valueOf(final byte byteVal) {
-        checkArgument(byteVal >= MIN_VALUE, "Negative values are not allowed");
+        checkArgument(byteVal >= MIN_VALUE_INT, "Negative values are not allowed");
         return instanceFor(byteVal);
     }
 
     public static Uint16 valueOf(final short shortVal) {
-        checkArgument(shortVal >= MIN_VALUE, "Negative values are not allowed");
+        checkArgument(shortVal >= MIN_VALUE_INT, "Negative values are not allowed");
         return instanceFor(shortVal);
     }
 
     public static Uint16 valueOf(final int intVal) {
-        checkArgument(intVal >= MIN_VALUE && intVal <= MAX_VALUE, "Value %s is outside of allowed range", intVal);
+        checkArgument(intVal >= MIN_VALUE_INT && intVal <= MAX_VALUE_INT, "Value %s is outside of allowed range",
+                intVal);
         return instanceFor((short)(intVal & 0xffff));
     }
 
     public static Uint16 valueOf(final long longVal) {
-        checkArgument(longVal >= MIN_VALUE && longVal <= MAX_VALUE, "Value %s is outside of allowed range", longVal);
+        checkArgument(longVal >= MIN_VALUE_INT && longVal <= MAX_VALUE_INT, "Value %s is outside of allowed range",
+                longVal);
         return instanceFor((short)(longVal & 0xffff));
     }
 
index 0818206172c6cdac457d19a2883d7666bae3eda5..4ef835c22cc11701655bfc2247f592af5b99c834 100644 (file)
@@ -45,13 +45,13 @@ public class Uint32 extends Number implements CanonicalValue<Uint32> {
 
     private static final CanonicalValueSupport<Uint32> SUPPORT = new Support();
     private static final long serialVersionUID = 1L;
-    private static final long MIN_VALUE = 0;
-    private static final long MAX_VALUE = 0xffffffffL;
+    private static final long MIN_VALUE_LONG = 0;
+    private static final long MAX_VALUE_LONG = 0xffffffffL;
 
     /**
      * Cache of first 256 values.
      */
-    private static final Uint32[] CACHE = new Uint32[Uint8.MAX_VALUE];
+    private static final Uint32[] CACHE = new Uint32[Uint8.MAX_VALUE_SHORT];
     /**
      * Commonly encountered values.
      */
@@ -61,8 +61,12 @@ public class Uint32 extends Number implements CanonicalValue<Uint32> {
         new Uint32(65535),
         new Uint32(65536),
         new Uint32(Integer.MAX_VALUE),
+        new Uint32(-1)
     };
 
+    public static final Uint32 MIN_VALUE = valueOf(MIN_VALUE_LONG);
+    public static final Uint32 MAX_VALUE = valueOf(MAX_VALUE_LONG);
+
     /**
      * Tunable weak LRU cache for other values. By default it holds {@value #DEFAULT_LRU_SIZE} entries. This can be
      * changed via {@value #LRU_SIZE_PROPERTY} system property.
@@ -133,22 +137,23 @@ public class Uint32 extends Number implements CanonicalValue<Uint32> {
     }
 
     public static Uint32 valueOf(final byte byteVal) {
-        checkArgument(byteVal >= MIN_VALUE, "Negative values are not allowed");
+        checkArgument(byteVal >= MIN_VALUE_LONG, "Negative values are not allowed");
         return instanceFor(byteVal);
     }
 
     public static Uint32 valueOf(final short shortVal) {
-        checkArgument(shortVal >= MIN_VALUE, "Negative values are not allowed");
+        checkArgument(shortVal >= MIN_VALUE_LONG, "Negative values are not allowed");
         return instanceFor(shortVal);
     }
 
     public static Uint32 valueOf(final int intVal) {
-        checkArgument(intVal >= MIN_VALUE, "Value %s is outside of allowed range", intVal);
+        checkArgument(intVal >= MIN_VALUE_LONG, "Value %s is outside of allowed range", intVal);
         return instanceFor(intVal);
     }
 
     public static Uint32 valueOf(final long longVal) {
-        checkArgument(longVal >= MIN_VALUE && longVal <= MAX_VALUE, "Value %s is outside of allowed range", longVal);
+        checkArgument(longVal >= MIN_VALUE_LONG && longVal <= MAX_VALUE_LONG, "Value %s is outside of allowed range",
+                longVal);
         return instanceFor((int)longVal);
     }
 
index d4aabc0525fe73d4c261e23ffd3235c273e9f26f..1c4f620ef2ec2e0e9de90eaa0a420b38159760af 100644 (file)
@@ -46,12 +46,12 @@ public class Uint64 extends Number implements CanonicalValue<Uint64> {
 
     private static final CanonicalValueSupport<Uint64> SUPPORT = new Support();
     private static final long serialVersionUID = 1L;
-    private static final long MIN_VALUE = 0;
+    private static final long MIN_VALUE_LONG = 0;
 
     /**
      * Cache of first 256 values.
      */
-    private static final Uint64[] CACHE = new Uint64[Uint8.MAX_VALUE];
+    private static final Uint64[] CACHE = new Uint64[Uint8.MAX_VALUE_SHORT];
     /**
      * Commonly encountered values.
      */
@@ -63,8 +63,12 @@ public class Uint64 extends Number implements CanonicalValue<Uint64> {
         new Uint64(Integer.MAX_VALUE),
         new Uint64(Integer.MAX_VALUE + 1L),
         new Uint64(Long.MAX_VALUE),
+        new Uint64(-1L)
     };
 
+    public static final Uint64 MIN_VALUE = valueOf(MIN_VALUE_LONG);
+    public static final Uint64 MAX_VALUE = fromLongBits(-1);
+
     /**
      * Tunable weak LRU cache for other values. By default it holds {@value #DEFAULT_LRU_SIZE} entries. This can be
      * changed via {@value #LRU_SIZE_PROPERTY} system property.
@@ -135,22 +139,22 @@ public class Uint64 extends Number implements CanonicalValue<Uint64> {
     }
 
     public static Uint64 valueOf(final byte byteVal) {
-        checkArgument(byteVal >= MIN_VALUE, "Negative values are not allowed");
+        checkArgument(byteVal >= MIN_VALUE_LONG, "Negative values are not allowed");
         return instanceFor(byteVal);
     }
 
     public static Uint64 valueOf(final short shortVal) {
-        checkArgument(shortVal >= MIN_VALUE, "Negative values are not allowed");
+        checkArgument(shortVal >= MIN_VALUE_LONG, "Negative values are not allowed");
         return instanceFor(shortVal);
     }
 
     public static Uint64 valueOf(final int intVal) {
-        checkArgument(intVal >= MIN_VALUE, "Value %s is outside of allowed range", intVal);
+        checkArgument(intVal >= MIN_VALUE_LONG, "Value %s is outside of allowed range", intVal);
         return instanceFor(intVal);
     }
 
     public static Uint64 valueOf(final long longVal) {
-        checkArgument(longVal >= MIN_VALUE, "Value %s is outside of allowed range", longVal);
+        checkArgument(longVal >= MIN_VALUE_LONG, "Value %s is outside of allowed range", longVal);
         return instanceFor(longVal);
     }
 
index b5adf503657c010273f60ea9c97770ae11973019..97e85c345c6025610e53070d54864f82b8b851a0 100644 (file)
@@ -41,11 +41,14 @@ public class Uint8 extends Number implements CanonicalValue<Uint8> {
 
     private static final CanonicalValueSupport<Uint8> SUPPORT = new Support();
 
-    static final short MIN_VALUE = 0;
-    static final short MAX_VALUE = 255;
+    static final short MIN_VALUE_SHORT = 0;
+    static final short MAX_VALUE_SHORT = 255;
 
     private static final long serialVersionUID = 1L;
-    private static final Uint8[] CACHE = new Uint8[MAX_VALUE + 1];
+    private static final Uint8[] CACHE = new Uint8[MAX_VALUE_SHORT + 1];
+
+    public static final Uint8 MIN_VALUE = valueOf(MIN_VALUE_SHORT);
+    public static final Uint8 MAX_VALUE = valueOf(MAX_VALUE_SHORT);
 
     private final byte value;
 
@@ -80,22 +83,25 @@ public class Uint8 extends Number implements CanonicalValue<Uint8> {
     }
 
     public static Uint8 valueOf(final byte byteVal) {
-        checkArgument(byteVal >= MIN_VALUE, "Negative values are not allowed");
+        checkArgument(byteVal >= MIN_VALUE_SHORT, "Negative values are not allowed");
         return instanceFor(byteVal);
     }
 
     public static Uint8 valueOf(final short shortVal) {
-        checkArgument(shortVal >= MIN_VALUE && shortVal <= MAX_VALUE, "Value %s is outside of allowed range", shortVal);
+        checkArgument(shortVal >= MIN_VALUE_SHORT && shortVal <= MAX_VALUE_SHORT,
+                "Value %s is outside of allowed range", shortVal);
         return instanceFor((byte)(shortVal & 0xff));
     }
 
     public static Uint8 valueOf(final int intVal) {
-        checkArgument(intVal >= MIN_VALUE && intVal <= MAX_VALUE, "Value %s is outside of allowed range", intVal);
+        checkArgument(intVal >= MIN_VALUE_SHORT && intVal <= MAX_VALUE_SHORT,
+                "Value %s is outside of allowed range", intVal);
         return instanceFor((byte)(intVal & 0xff));
     }
 
     public static Uint8 valueOf(final long longVal) {
-        checkArgument(longVal >= MIN_VALUE && longVal <= MAX_VALUE, "Value %s is outside of allowed range", longVal);
+        checkArgument(longVal >= MIN_VALUE_SHORT && longVal <= MAX_VALUE_SHORT,
+                "Value %s is outside of allowed range", longVal);
         return instanceFor((byte)(longVal & 0xff));
     }