|
13 | 13 | import java.util.HashMap; |
14 | 14 | import java.util.Locale; |
15 | 15 | import java.util.Map; |
16 | | -import java.util.Optional; |
17 | 16 | import java.util.Random; |
18 | 17 | import java.util.concurrent.TimeUnit; |
19 | 18 | import java.util.function.Function; |
@@ -66,13 +65,19 @@ public String getValue() { |
66 | 65 | } |
67 | 66 |
|
68 | 67 | public static Tiny1 fromValue(String value) { |
69 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CS.get(v)) |
70 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 68 | + Tiny1 result = BY_VALUE_CS.get(value); |
| 69 | + if (result != null) { |
| 70 | + return result; |
| 71 | + } |
| 72 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
71 | 73 | } |
72 | 74 |
|
73 | 75 | public static Tiny1 fromValueCaseInsensitive(String value) { |
74 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CI.get(v.toLowerCase(Locale.ROOT))) |
75 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 76 | + Tiny1 result = BY_VALUE_CI.get(value.toLowerCase(Locale.ROOT)); |
| 77 | + if (result != null) { |
| 78 | + return result; |
| 79 | + } |
| 80 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
76 | 81 | } |
77 | 82 |
|
78 | 83 | public static Tiny1 fromValueLinear(String value) { |
@@ -124,13 +129,19 @@ public String getValue() { |
124 | 129 | } |
125 | 130 |
|
126 | 131 | public static Tiny2 fromValue(String value) { |
127 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CS.get(v)) |
128 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 132 | + Tiny2 result = BY_VALUE_CS.get(value); |
| 133 | + if (result != null) { |
| 134 | + return result; |
| 135 | + } |
| 136 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
129 | 137 | } |
130 | 138 |
|
131 | 139 | public static Tiny2 fromValueCaseInsensitive(String value) { |
132 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CI.get(v.toLowerCase(Locale.ROOT))) |
133 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 140 | + Tiny2 result = BY_VALUE_CI.get(value.toLowerCase(Locale.ROOT)); |
| 141 | + if (result != null) { |
| 142 | + return result; |
| 143 | + } |
| 144 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
134 | 145 | } |
135 | 146 |
|
136 | 147 | public static Tiny2 fromValueLinear(String value) { |
@@ -183,13 +194,19 @@ public String getValue() { |
183 | 194 | } |
184 | 195 |
|
185 | 196 | public static Tiny3 fromValue(String value) { |
186 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CS.get(v)) |
187 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 197 | + Tiny3 result = BY_VALUE_CS.get(value); |
| 198 | + if (result != null) { |
| 199 | + return result; |
| 200 | + } |
| 201 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
188 | 202 | } |
189 | 203 |
|
190 | 204 | public static Tiny3 fromValueCaseInsensitive(String value) { |
191 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CI.get(v.toLowerCase(Locale.ROOT))) |
192 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 205 | + Tiny3 result = BY_VALUE_CI.get(value.toLowerCase(Locale.ROOT)); |
| 206 | + if (result != null) { |
| 207 | + return result; |
| 208 | + } |
| 209 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
193 | 210 | } |
194 | 211 |
|
195 | 212 | public static Tiny3 fromValueLinear(String value) { |
@@ -243,13 +260,19 @@ public String getValue() { |
243 | 260 | } |
244 | 261 |
|
245 | 262 | public static Tiny4 fromValue(String value) { |
246 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CS.get(v)) |
247 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 263 | + Tiny4 result = BY_VALUE_CS.get(value); |
| 264 | + if (result != null) { |
| 265 | + return result; |
| 266 | + } |
| 267 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
248 | 268 | } |
249 | 269 |
|
250 | 270 | public static Tiny4 fromValueCaseInsensitive(String value) { |
251 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CI.get(v.toLowerCase(Locale.ROOT))) |
252 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 271 | + Tiny4 result = BY_VALUE_CI.get(value.toLowerCase(Locale.ROOT)); |
| 272 | + if (result != null) { |
| 273 | + return result; |
| 274 | + } |
| 275 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
253 | 276 | } |
254 | 277 |
|
255 | 278 | public static Tiny4 fromValueLinear(String value) { |
@@ -304,13 +327,19 @@ public String getValue() { |
304 | 327 | } |
305 | 328 |
|
306 | 329 | public static Tiny5 fromValue(String value) { |
307 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CS.get(v)) |
308 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 330 | + Tiny5 result = BY_VALUE_CS.get(value); |
| 331 | + if (result != null) { |
| 332 | + return result; |
| 333 | + } |
| 334 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
309 | 335 | } |
310 | 336 |
|
311 | 337 | public static Tiny5 fromValueCaseInsensitive(String value) { |
312 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CI.get(v.toLowerCase(Locale.ROOT))) |
313 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 338 | + Tiny5 result = BY_VALUE_CI.get(value.toLowerCase(Locale.ROOT)); |
| 339 | + if (result != null) { |
| 340 | + return result; |
| 341 | + } |
| 342 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
314 | 343 | } |
315 | 344 |
|
316 | 345 | public static Tiny5 fromValueLinear(String value) { |
@@ -366,13 +395,19 @@ public String getValue() { |
366 | 395 | } |
367 | 396 |
|
368 | 397 | public static Tiny6 fromValue(String value) { |
369 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CS.get(v)) |
370 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 398 | + Tiny6 result = BY_VALUE_CS.get(value); |
| 399 | + if (result != null) { |
| 400 | + return result; |
| 401 | + } |
| 402 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
371 | 403 | } |
372 | 404 |
|
373 | 405 | public static Tiny6 fromValueCaseInsensitive(String value) { |
374 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CI.get(v.toLowerCase(Locale.ROOT))) |
375 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 406 | + Tiny6 result = BY_VALUE_CI.get(value.toLowerCase(Locale.ROOT)); |
| 407 | + if (result != null) { |
| 408 | + return result; |
| 409 | + } |
| 410 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
376 | 411 | } |
377 | 412 |
|
378 | 413 | public static Tiny6 fromValueLinear(String value) { |
@@ -429,13 +464,19 @@ public String getValue() { |
429 | 464 | } |
430 | 465 |
|
431 | 466 | public static Tiny7 fromValue(String value) { |
432 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CS.get(v)) |
433 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 467 | + Tiny7 result = BY_VALUE_CS.get(value); |
| 468 | + if (result != null) { |
| 469 | + return result; |
| 470 | + } |
| 471 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
434 | 472 | } |
435 | 473 |
|
436 | 474 | public static Tiny7 fromValueCaseInsensitive(String value) { |
437 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CI.get(v.toLowerCase(Locale.ROOT))) |
438 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 475 | + Tiny7 result = BY_VALUE_CI.get(value.toLowerCase(Locale.ROOT)); |
| 476 | + if (result != null) { |
| 477 | + return result; |
| 478 | + } |
| 479 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
439 | 480 | } |
440 | 481 |
|
441 | 482 | public static Tiny7 fromValueLinear(String value) { |
@@ -493,13 +534,19 @@ public String getValue() { |
493 | 534 | } |
494 | 535 |
|
495 | 536 | public static Tiny8 fromValue(String value) { |
496 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CS.get(v)) |
497 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 537 | + Tiny8 result = BY_VALUE_CS.get(value); |
| 538 | + if (result != null) { |
| 539 | + return result; |
| 540 | + } |
| 541 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
498 | 542 | } |
499 | 543 |
|
500 | 544 | public static Tiny8 fromValueCaseInsensitive(String value) { |
501 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CI.get(v.toLowerCase(Locale.ROOT))) |
502 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 545 | + Tiny8 result = BY_VALUE_CI.get(value.toLowerCase(Locale.ROOT)); |
| 546 | + if (result != null) { |
| 547 | + return result; |
| 548 | + } |
| 549 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
503 | 550 | } |
504 | 551 |
|
505 | 552 | public static Tiny8 fromValueLinear(String value) { |
@@ -558,13 +605,19 @@ public String getValue() { |
558 | 605 | } |
559 | 606 |
|
560 | 607 | public static Tiny9 fromValue(String value) { |
561 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CS.get(v)) |
562 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 608 | + Tiny9 result = BY_VALUE_CS.get(value); |
| 609 | + if (result != null) { |
| 610 | + return result; |
| 611 | + } |
| 612 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
563 | 613 | } |
564 | 614 |
|
565 | 615 | public static Tiny9 fromValueCaseInsensitive(String value) { |
566 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CI.get(v.toLowerCase(Locale.ROOT))) |
567 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 616 | + Tiny9 result = BY_VALUE_CI.get(value.toLowerCase(Locale.ROOT)); |
| 617 | + if (result != null) { |
| 618 | + return result; |
| 619 | + } |
| 620 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
568 | 621 | } |
569 | 622 |
|
570 | 623 | public static Tiny9 fromValueLinear(String value) { |
@@ -624,13 +677,19 @@ public String getValue() { |
624 | 677 | } |
625 | 678 |
|
626 | 679 | public static Tiny10 fromValue(String value) { |
627 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CS.get(v)) |
628 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 680 | + Tiny10 result = BY_VALUE_CS.get(value); |
| 681 | + if (result != null) { |
| 682 | + return result; |
| 683 | + } |
| 684 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
629 | 685 | } |
630 | 686 |
|
631 | 687 | public static Tiny10 fromValueCaseInsensitive(String value) { |
632 | | - return Optional.ofNullable(value).map(v -> BY_VALUE_CI.get(v.toLowerCase(Locale.ROOT))) |
633 | | - .orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")); |
| 688 | + Tiny10 result = BY_VALUE_CI.get(value.toLowerCase(Locale.ROOT)); |
| 689 | + if (result != null) { |
| 690 | + return result; |
| 691 | + } |
| 692 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
634 | 693 | } |
635 | 694 |
|
636 | 695 | public static Tiny10 fromValueLinear(String value) { |
@@ -696,6 +755,7 @@ private LookupFunctions( |
696 | 755 | Function<String, Object> linear, |
697 | 756 | Function<String, Object> linearCaseInsensitive) { |
698 | 757 | this.values = values; |
| 758 | + // Methods |
699 | 759 | this.hashMap = hashMap; |
700 | 760 | this.hashMapCaseInsensitive = hashMapCaseInsensitive; |
701 | 761 | this.linear = linear; |
|
0 commit comments