Move UintConversions.throwIAE() 60/107560/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 29 Aug 2023 18:26:22 +0000 (20:26 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 29 Aug 2023 19:17:39 +0000 (21:17 +0200)
We have a single caller in Uint64, inline it and make the exception
throw explicit. Fixes a few Sonar duplication complaints.

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

index 7b170d57273ef57a5938948bb0b5ff05d15abfb4..d7e5e3a8290cb554fe2d2f87a472457e59971f94 100644 (file)
@@ -399,7 +399,7 @@ public class Uint64 extends Number implements CanonicalValue<Uint64> {
      */
     public final Uint8 toUint8() {
         if ((value & 0xFFFFFFFFFFFFFF00L) != 0) {
-            UintConversions.throwIAE(toString(), 255);
+            throw iae(toString(), 255);
         }
         return Uint8.fromByteBits((byte) value);
     }
@@ -412,7 +412,7 @@ public class Uint64 extends Number implements CanonicalValue<Uint64> {
      */
     public final Uint16 toUint16() {
         if ((value & 0xFFFFFFFFFFFF0000L) != 0) {
-            UintConversions.throwIAE(toString(), 65535);
+            throw iae(toString(), 65535);
         }
         return Uint16.fromShortBits((short) value);
     }
@@ -425,11 +425,16 @@ public class Uint64 extends Number implements CanonicalValue<Uint64> {
      */
     public final Uint32 toUint32() {
         if ((value & 0xFFFFFFFF00000000L) != 0) {
-            UintConversions.throwIAE(toString(), 4294967295L);
+            throw iae(toString(), 4294967295L);
         }
         return Uint32.fromIntBits((int) value);
     }
 
+    static IllegalArgumentException iae(final String value, final long max) {
+        // "Invalid range: 65536, expected: [[0..65535]]."
+        return new IllegalArgumentException("Invalid range: " + value + ", expected: [[0.." + max + "]].");
+    }
+
     @Override
     public final int hashCode() {
         return Long.hashCode(value);
index 02c918af09b08ee13b22a05614ff762e3e5e7305..1f22fe2f43c898a4d11b43f39e41332e4afbc43c 100644 (file)
@@ -135,16 +135,6 @@ public final class UintConversions {
         }
     }
 
-    static void throwIAE(final String value, final long max) {
-        // "Invalid range: 65536, expected: [[0..65535]]."
-        throw new IllegalArgumentException("Invalid range: " + value + ", expected: [[0.." + max + "]].");
-    }
-
-    private static void throwIAE(final int value, final int max) {
-        // "Invalid range: 65536, expected: [[0..65535]]."
-        throw new IllegalArgumentException("Invalid range: " + value + ", expected: [[0.." + max + "]].");
-    }
-
     private static void throwIAE(final long value, final long max) {
         // "Invalid range: 65536, expected: [[0..65535]]."
         throw new IllegalArgumentException("Invalid range: " + value + ", expected: [[0.." + max + "]].");