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 2024/09/12 00:53:26 UTC
(commons-beanutils) branch 1.X updated (6ca3d0c0 -> 8059ab75)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch 1.X
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
from 6ca3d0c0 No need to use a FQCN for java.lang.UnsupportedOperationException
new 89b7ba18 Convert cascading if-else to switch
new 0b049cab Convert cascading if-else to switch
new 8059ab75 Convert cascading if-else to switch
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../commons/beanutils/PropertyUtilsTestCase.java | 29 +++++-----
.../apache/commons/beanutils/TestResultSet.java | 67 +++++++++-------------
.../commons/beanutils/TestResultSetMetaData.java | 51 ++++++++++------
3 files changed, 75 insertions(+), 72 deletions(-)
(commons-beanutils) 02/03: Convert cascading if-else to switch
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch 1.X
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
commit 0b049cab8f729a22246fd70d03e94d1e30207310
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 11 20:53:14 2024 -0400
Convert cascading if-else to switch
---
.../apache/commons/beanutils/TestResultSet.java | 67 +++++++++-------------
1 file changed, 27 insertions(+), 40 deletions(-)
diff --git a/src/test/java/org/apache/commons/beanutils/TestResultSet.java b/src/test/java/org/apache/commons/beanutils/TestResultSet.java
index 58f60f4e..32924282 100644
--- a/src/test/java/org/apache/commons/beanutils/TestResultSet.java
+++ b/src/test/java/org/apache/commons/beanutils/TestResultSet.java
@@ -315,47 +315,38 @@ public class TestResultSet implements InvocationHandler {
if (row > 5) {
throw new SQLException("No current row");
}
- if ("bigDecimalProperty".equals(columnName)) {
+ switch (columnName) {
+ case "bigDecimalProperty":
return new BigDecimal(123.45);
- }
- if ("booleanProperty".equals(columnName)) {
+ case "booleanProperty":
if (row % 2 == 0) {
return Boolean.TRUE;
}
return Boolean.FALSE;
- }
- if ("byteProperty".equals(columnName)) {
+ case "byteProperty":
return Byte.valueOf((byte) row);
- }
- if ("dateProperty".equals(columnName)) {
+ case "dateProperty":
return new Date(timestamp);
- }
- if ("doubleProperty".equals(columnName)) {
+ case "doubleProperty":
return Double.valueOf(321.0);
- }
- if ("floatProperty".equals(columnName)) {
+ case "floatProperty":
return Float.valueOf((float) 123.0);
- }
- if ("intProperty".equals(columnName)) {
+ case "intProperty":
return Integer.valueOf(100 + row);
- }
- if ("longProperty".equals(columnName)) {
+ case "longProperty":
return Long.valueOf(200 + row);
- }
- if ("nullProperty".equals(columnName)) {
+ case "nullProperty":
return null;
- }
- if ("shortProperty".equals(columnName)) {
+ case "shortProperty":
return Short.valueOf((short) (300 + row));
- }
- if ("stringProperty".equals(columnName)) {
+ case "stringProperty":
return "This is a string";
- }
- if ("timeProperty".equals(columnName)) {
+ case "timeProperty":
return new Time(timestamp);
- }
- if ("timestampProperty".equals(columnName)) {
+ case "timestampProperty":
return new Timestamp(timestamp);
+ default:
+ break;
}
throw new SQLException("Unknown column name " + columnName);
}
@@ -472,30 +463,26 @@ public class TestResultSet implements InvocationHandler {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
final String methodName = method.getName();
- if ("close".equals(methodName)) {
+ switch (methodName) {
+ case "close":
return null;
- }
- if ("getMetaData".equals(methodName)) {
+ case "getMetaData":
return getMetaData();
- }
- if ("getObject".equals(methodName)) {
+ case "getObject":
return getObject(columnName(args[0]));
- }
- if ("getDate".equals(methodName)) {
+ case "getDate":
return getDate(columnName(args[0]));
- }
- if ("getTime".equals(methodName)) {
+ case "getTime":
return getTime(columnName(args[0]));
- }
- if ("getTimestamp".equals(methodName)) {
+ case "getTimestamp":
return getTimestamp(columnName(args[0]));
- }
- if ("next".equals(methodName)) {
+ case "next":
return next() ? Boolean.TRUE : Boolean.FALSE;
- }
- if ("updateObject".equals(methodName)) {
+ case "updateObject":
updateObject((String) args[0], args[1]);
return null;
+ default:
+ break;
}
throw new UnsupportedOperationException(methodName + " not implemented");
(commons-beanutils) 03/03: Convert cascading if-else to switch
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch 1.X
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
commit 8059ab75915356da966888eb62dabebfe798f0b7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 11 20:53:21 2024 -0400
Convert cascading if-else to switch
---
.../commons/beanutils/TestResultSetMetaData.java | 51 ++++++++++++++--------
1 file changed, 34 insertions(+), 17 deletions(-)
diff --git a/src/test/java/org/apache/commons/beanutils/TestResultSetMetaData.java b/src/test/java/org/apache/commons/beanutils/TestResultSetMetaData.java
index 92091f77..51de547e 100644
--- a/src/test/java/org/apache/commons/beanutils/TestResultSetMetaData.java
+++ b/src/test/java/org/apache/commons/beanutils/TestResultSetMetaData.java
@@ -114,35 +114,49 @@ public class TestResultSetMetaData implements InvocationHandler {
public Integer getColumnType(final int columnIndex) throws SQLException {
final String columnName = getColumnName(columnIndex);
int sqlType = Types.OTHER;
- if (columnName.equals("bigDecimalProperty")) {
+ switch (columnName) {
+ case "bigDecimalProperty":
sqlType = Types.DECIMAL;
// Types.BOOLEAN only introduced in JDK 1.4
// } else if (columnName.equals("booleanProperty")) {
// sqlType = Types.BOOLEAN;
- } else if (columnName.equals("byteProperty")) {
+ break;
+ case "byteProperty":
sqlType = Types.TINYINT;
- } else if (columnName.equals("dateProperty")) {
+ break;
+ case "dateProperty":
sqlType = Types.DATE;
- } else if (columnName.equals("doubleProperty")) {
+ break;
+ case "doubleProperty":
sqlType = Types.DOUBLE;
- } else if (columnName.equals("floatProperty")) {
+ break;
+ case "floatProperty":
sqlType = Types.FLOAT;
- } else if (columnName.equals("intProperty")) {
+ break;
+ case "intProperty":
sqlType = Types.INTEGER;
- } else if (columnName.equals("longProperty")) {
+ break;
+ case "longProperty":
sqlType = Types.BIGINT;
- } else if (columnName.equals("nullProperty")) {
+ break;
+ case "nullProperty":
sqlType = Types.VARCHAR;
- } else if (columnName.equals("shortProperty")) {
+ break;
+ case "shortProperty":
sqlType = Types.SMALLINT;
- } else if (columnName.equals("stringProperty")) {
+ break;
+ case "stringProperty":
sqlType = Types.VARCHAR;
- } else if (columnName.equals("timeProperty")) {
+ break;
+ case "timeProperty":
sqlType = Types.TIME;
- } else if (columnName.equals("timestampProperty")) {
+ break;
+ case "timestampProperty":
sqlType = Types.TIMESTAMP;
- } else {
+ break;
+ default:
sqlType = Types.OTHER;
+ break;
}
return Integer.valueOf(sqlType);
}
@@ -185,14 +199,17 @@ public class TestResultSetMetaData implements InvocationHandler {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
final String methodName = method.getName();
- if ("getColumnClassName".equals(methodName)) {
+ switch (methodName) {
+ case "getColumnClassName":
return getColumnClassName(((Integer)args[0]).intValue());
- } if ("getColumnCount".equals(methodName)) {
+ case "getColumnCount":
return Integer.valueOf(getColumnCount());
- } if ("getColumnName".equals(methodName)) {
+ case "getColumnName":
return getColumnName(((Integer)args[0]).intValue());
- } if ("getColumnType".equals(methodName)) {
+ case "getColumnType":
return getColumnType(((Integer)args[0]).intValue());
+ default:
+ break;
}
throw new UnsupportedOperationException(methodName + " not implemented");
(commons-beanutils) 01/03: Convert cascading if-else to switch
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch 1.X
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
commit 89b7ba18b9c4f789c638430d7905f37669701fc9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 11 20:53:08 2024 -0400
Convert cascading if-else to switch
---
.../commons/beanutils/PropertyUtilsTestCase.java | 29 +++++++++++-----------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/src/test/java/org/apache/commons/beanutils/PropertyUtilsTestCase.java b/src/test/java/org/apache/commons/beanutils/PropertyUtilsTestCase.java
index 1050ca51..0aa711a1 100644
--- a/src/test/java/org/apache/commons/beanutils/PropertyUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils/PropertyUtilsTestCase.java
@@ -2006,14 +2006,15 @@ public class PropertyUtilsTestCase extends TestCase {
for (final String propertie : properties) {
// Identify the property descriptor for this property
- if (propertie.equals("intIndexed")) {
+ switch (propertie) {
+ case "intIndexed":
continue;
- }
- if (propertie.equals("stringIndexed")) {
+ case "stringIndexed":
continue;
- }
- if (propertie.equals("writeOnlyProperty")) {
+ case "writeOnlyProperty":
continue;
+ default:
+ break;
}
int n = -1;
for (int j = 0; j < pd.length; j++) {
@@ -2517,21 +2518,19 @@ public class PropertyUtilsTestCase extends TestCase {
for (final String propertie : properties) {
// Identify the property descriptor for this property
- if (propertie.equals("intIndexed")) {
+ switch (propertie) {
+ case "intIndexed":
continue;
- }
- if (propertie.equals("listIndexed")) {
+ case "listIndexed":
continue;
- }
- if (propertie.equals("nested"))
- {
+ case "nested":
continue; // This property is read only
- }
- if (propertie.equals("readOnlyProperty")) {
+ case "readOnlyProperty":
continue;
- }
- if (propertie.equals("stringIndexed")) {
+ case "stringIndexed":
continue;
+ default:
+ break;
}
int n = -1;
for (int j = 0; j < pd.length; j++) {