You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/01/03 16:08:32 UTC
[commons-lang] branch master updated: Replace cascading if-else's
with a case statement.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new e6e1682 Replace cascading if-else's with a case statement.
e6e1682 is described below
commit e6e16820893699da869136a28403a05e762c4778
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jan 3 11:08:27 2021 -0500
Replace cascading if-else's with a case statement.
---
.../java/org/apache/commons/lang3/JavaVersion.java | 63 +++++++++++-----------
1 file changed, 33 insertions(+), 30 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java b/src/main/java/org/apache/commons/lang3/JavaVersion.java
index 0837a39..847be56 100644
--- a/src/main/java/org/apache/commons/lang3/JavaVersion.java
+++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java
@@ -217,61 +217,64 @@ public enum JavaVersion {
* corresponding constant of this enumeration class. This method is used
* internally.
*
- * @param nom the Java version as string
+ * @param versionStr the Java version as string
* @return the corresponding enumeration constant or <b>null</b> if the
* version is unknown
*/
- static JavaVersion get(final String nom) {
- if (nom == null) {
+ static JavaVersion get(final String versionStr) {
+ if (versionStr == null) {
return null;
- } else if ("0.9".equals(nom)) {
+ }
+ switch (versionStr) {
+ case "0.9":
return JAVA_0_9;
- } else if ("1.1".equals(nom)) {
+ case "1.1":
return JAVA_1_1;
- } else if ("1.2".equals(nom)) {
+ case "1.2":
return JAVA_1_2;
- } else if ("1.3".equals(nom)) {
+ case "1.3":
return JAVA_1_3;
- } else if ("1.4".equals(nom)) {
+ case "1.4":
return JAVA_1_4;
- } else if ("1.5".equals(nom)) {
+ case "1.5":
return JAVA_1_5;
- } else if ("1.6".equals(nom)) {
+ case "1.6":
return JAVA_1_6;
- } else if ("1.7".equals(nom)) {
+ case "1.7":
return JAVA_1_7;
- } else if ("1.8".equals(nom)) {
+ case "1.8":
return JAVA_1_8;
- } else if ("9".equals(nom)) {
+ case "9":
return JAVA_9;
- } else if ("10".equals(nom)) {
+ case "10":
return JAVA_10;
- } else if ("11".equals(nom)) {
+ case "11":
return JAVA_11;
- } else if ("12".equals(nom)) {
+ case "12":
return JAVA_12;
- } else if ("13".equals(nom)) {
+ case "13":
return JAVA_13;
- } else if ("14".equals(nom)) {
+ case "14":
return JAVA_14;
- } else if ("15".equals(nom)) {
+ case "15":
return JAVA_15;
- } else if ("16".equals(nom)) {
+ case "16":
return JAVA_16;
- } else if ("17".equals(nom)) {
+ case "17":
return JAVA_17;
- }
- final float v = toFloatVersion(nom);
- if ((v - 1.) < 1.) { // then we need to check decimals > .9
- final int firstComma = Math.max(nom.indexOf('.'), nom.indexOf(','));
- final int end = Math.max(nom.length(), nom.indexOf(',', firstComma));
- if (Float.parseFloat(nom.substring(firstComma + 1, end)) > .9f) {
+ default:
+ final float v = toFloatVersion(versionStr);
+ if ((v - 1.) < 1.) { // then we need to check decimals > .9
+ final int firstComma = Math.max(versionStr.indexOf('.'), versionStr.indexOf(','));
+ final int end = Math.max(versionStr.length(), versionStr.indexOf(',', firstComma));
+ if (Float.parseFloat(versionStr.substring(firstComma + 1, end)) > .9f) {
+ return JAVA_RECENT;
+ }
+ } else if (v > 10) {
return JAVA_RECENT;
}
- } else if (v > 10) {
- return JAVA_RECENT;
+ return null;
}
- return null;
}
//-----------------------------------------------------------------------