Use a switch expression
[yangtools.git] / common / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / Decimal64.java
index d6b891ae0ff968cb81e9b13fb72a25c3e34211c6..bbf66fd22cc6b54e49653cd14c426a90d7f0692f 100644 (file)
@@ -48,21 +48,20 @@ public class Decimal64 extends Number implements CanonicalValue<Decimal64> {
 
             // Deal with optional sign
             final boolean negative;
-            int idx;
-            switch (str.charAt(0)) {
-                case '-':
+            int idx = switch (str.charAt(0)) {
+                case '-' -> {
                     negative = true;
-                    idx = 1;
-                    break;
-                case '+':
+                    yield 1;
+                }
+                case '+' -> {
                     negative = false;
-                    idx = 1;
-                    break;
-                default:
+                    yield 1;
+                }
+                default -> {
                     negative = false;
-                    idx = 0;
-            }
-
+                    yield 0;
+                }
+            };
             // Sanity check length
             if (idx == str.length()) {
                 return CanonicalValueViolation.variantOf("Missing digits after sign");