Fix string duplication in Ipv6Utils 92/83692/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Aug 2019 11:40:52 +0000 (13:40 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Aug 2019 11:41:39 +0000 (13:41 +0200)
This is minor code smell, create a method to concentrate common
functionality.

Change-Id: I32fb6c5c29a099885413cf18361e53098593054e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
model/ietf/ietf-type-util/src/main/java/org/opendaylight/mdsal/model/ietf/util/Ipv6Utils.java

index 86fcb224da019c6947ae14494a85507a045b10a4..c5e94e829257385af5b9785dd6a64aaa36db9a21 100644 (file)
@@ -118,19 +118,23 @@ final class Ipv6Utils {
         }
 
         if (haveVal) {
-            verify(j + INT16SZ <= INADDR6SZ, "Overrun in parsing of '%s', should not occur", str);
+            verifySize(j + INT16SZ <= INADDR6SZ, str);
             bytes[j++] = (byte) (val >> 8 & 0xff);
             bytes[j++] = (byte) (val & 0xff);
         }
 
         if (colonp != -1) {
-            verify(j != INADDR6SZ, "Overrun in parsing of '%s', should not occur", str);
+            verifySize(j != INADDR6SZ, str);
             expandZeros(bytes, colonp, j);
         } else {
-            verify(j == INADDR6SZ, "Overrun in parsing of '%s', should not occur", str);
+            verifySize(j == INADDR6SZ, str);
         }
     }
 
+    private static void verifySize(final boolean expression, final String str) {
+        verify(expression, "Overrun in parsing of '%s', should not occur", str);
+    }
+
     private static void expandZeros(final byte[] bytes, final int where, final int filledBytes) {
         final int tailLength = filledBytes - where;
         final int tailOffset = INADDR6SZ - tailLength;