No need to nest in else.
diff --git a/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java b/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java
index 2ba7ec3..6ec11c6 100644
--- a/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java
+++ b/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java
@@ -120,12 +120,12 @@
if (value == null) {
throw new NullPointerException
("No mapped value for '" + name + "(" + key + ")'");
- } else if (value instanceof Map) {
- return ((Map<?, ?>) value).containsKey(key);
- } else {
- throw new IllegalArgumentException
- ("Non-mapped property for '" + name + "(" + key + ")'");
}
+ if (value instanceof Map) {
+ return ((Map<?, ?>) value).containsKey(key);
+ }
+ throw new IllegalArgumentException
+ ("Non-mapped property for '" + name + "(" + key + ")'");
}
@@ -156,23 +156,29 @@
// Manufacture default values for primitive properties
if (type == Boolean.TYPE) {
return Boolean.FALSE;
- } else if (type == Byte.TYPE) {
- return BYTE_ZERO;
- } else if (type == Character.TYPE) {
- return CHARACTER_ZERO;
- } else if (type == Double.TYPE) {
- return DOUBLE_ZERO;
- } else if (type == Float.TYPE) {
- return FLOAT_ZERO;
- } else if (type == Integer.TYPE) {
- return INTEGER_ZERO;
- } else if (type == Long.TYPE) {
- return LONG_ZERO;
- } else if (type == Short.TYPE) {
- return SHORT_ZERO;
- } else {
- return null;
}
+ if (type == Byte.TYPE) {
+ return BYTE_ZERO;
+ }
+ if (type == Character.TYPE) {
+ return CHARACTER_ZERO;
+ }
+ if (type == Double.TYPE) {
+ return DOUBLE_ZERO;
+ }
+ if (type == Float.TYPE) {
+ return FLOAT_ZERO;
+ }
+ if (type == Integer.TYPE) {
+ return INTEGER_ZERO;
+ }
+ if (type == Long.TYPE) {
+ return LONG_ZERO;
+ }
+ if (type == Short.TYPE) {
+ return SHORT_ZERO;
+ }
+ return null;
}
@@ -199,14 +205,15 @@
if (value == null) {
throw new NullPointerException
("No indexed value for '" + name + "[" + index + "]'");
- } else if (value.getClass().isArray()) {
- return Array.get(value, index);
- } else if (value instanceof List) {
- return ((List<?>) value).get(index);
- } else {
- throw new IllegalArgumentException
- ("Non-indexed property for '" + name + "[" + index + "]'");
}
+ if (value.getClass().isArray()) {
+ return Array.get(value, index);
+ }
+ if (value instanceof List) {
+ return ((List<?>) value).get(index);
+ }
+ throw new IllegalArgumentException
+ ("Non-indexed property for '" + name + "[" + index + "]'");
}
@@ -230,12 +237,12 @@
if (value == null) {
throw new NullPointerException
("No mapped value for '" + name + "(" + key + ")'");
- } else if (value instanceof Map) {
- return ((Map<?, ?>) value).get(key);
- } else {
- throw new IllegalArgumentException
- ("Non-mapped property for '" + name + "(" + key + ")'");
}
+ if (value instanceof Map) {
+ return ((Map<?, ?>) value).get(key);
+ }
+ throw new IllegalArgumentException
+ ("Non-mapped property for '" + name + "(" + key + ")'");
}
@@ -270,12 +277,12 @@
if (value == null) {
throw new NullPointerException
("No mapped value for '" + name + "(" + key + ")'");
- } else if (value instanceof Map) {
- ((Map<?, ?>) value).remove(key);
- } else {
+ }
+ if (!(value instanceof Map)) {
throw new IllegalArgumentException
("Non-mapped property for '" + name + "(" + key + ")'");
}
+ ((Map<?, ?>) value).remove(key);
}
@@ -335,7 +342,8 @@
if (prop == null) {
throw new NullPointerException
("No indexed value for '" + name + "[" + index + "]'");
- } else if (prop.getClass().isArray()) {
+ }
+ if (prop.getClass().isArray()) {
Array.set(prop, index, value);
} else if (prop instanceof List) {
try {
@@ -376,17 +384,17 @@
if (prop == null) {
throw new NullPointerException
("No mapped value for '" + name + "(" + key + ")'");
- } else if (prop instanceof Map) {
- @SuppressWarnings("unchecked")
- final
- // This is safe to cast because mapped properties are always
- // maps of types String -> Object
- Map<String, Object> map = (Map<String, Object>) prop;
- map.put(key, value);
- } else {
+ }
+ if (!(prop instanceof Map)) {
throw new IllegalArgumentException
("Non-mapped property for '" + name + "(" + key + ")'");
}
+ @SuppressWarnings("unchecked")
+ final
+ // This is safe to cast because mapped properties are always
+ // maps of types String -> Object
+ Map<String, Object> map = (Map<String, Object>) prop;
+ map.put(key, value);
}
diff --git a/src/main/java/org/apache/commons/beanutils2/BeanComparator.java b/src/main/java/org/apache/commons/beanutils2/BeanComparator.java
index 70a21b4..14b4b3f 100644
--- a/src/main/java/org/apache/commons/beanutils2/BeanComparator.java
+++ b/src/main/java/org/apache/commons/beanutils2/BeanComparator.java
@@ -171,13 +171,12 @@
if (!comparator.equals(beanComparator.comparator)) {
return false;
}
- if (property != null) {
- if (!property.equals(beanComparator.property)) {
- return false;
- }
- } else {
+ if (property == null) {
return beanComparator.property == null;
}
+ if (!property.equals(beanComparator.property)) {
+ return false;
+ }
return true;
}
diff --git a/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumer.java b/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumer.java
index 4a63373..7fa6a40 100644
--- a/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumer.java
+++ b/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumer.java
@@ -135,13 +135,12 @@
* @throws IllegalArgumentException If the propertyName provided is null or empty.
*/
public BeanPropertyValueChangeConsumer(final String propertyName, final V propertyValue, final boolean ignoreNull) {
- if (propertyName != null && !propertyName.isEmpty()) {
- this.propertyName = propertyName;
- this.propertyValue = propertyValue;
- this.ignoreNull = ignoreNull;
- } else {
+ if (propertyName == null || propertyName.isEmpty()) {
throw new IllegalArgumentException("propertyName cannot be null or empty");
}
+ this.propertyName = propertyName;
+ this.propertyValue = propertyValue;
+ this.ignoreNull = ignoreNull;
}
/**
@@ -166,15 +165,14 @@
} catch (final IllegalArgumentException e) {
final String errorMsg = "Unable to execute Closure. Null value encountered in property path...";
- if (ignoreNull) {
- log.warn(errorMsg, e);
- } else {
+ if (!ignoreNull) {
final IllegalArgumentException iae = new IllegalArgumentException(errorMsg);
if (!BeanUtils.initCause(iae, e)) {
log.error(errorMsg, e);
}
throw iae;
}
+ log.warn(errorMsg, e);
} catch (final IllegalAccessException e) {
final String errorMsg = "Unable to access the property provided.";
final IllegalArgumentException iae = new IllegalArgumentException(errorMsg);
diff --git a/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicate.java b/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicate.java
index d84d01e..8f03bde 100644
--- a/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicate.java
+++ b/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicate.java
@@ -166,13 +166,12 @@
*/
public BeanPropertyValueEqualsPredicate(final String propertyName, final V propertyValue,
final boolean ignoreNull) {
- if (propertyName != null && !propertyName.isEmpty()) {
- this.propertyName = propertyName;
- this.propertyValue = propertyValue;
- this.ignoreNull = ignoreNull;
- } else {
+ if (propertyName == null || propertyName.isEmpty()) {
throw new IllegalArgumentException("propertyName cannot be null or empty");
}
+ this.propertyName = propertyName;
+ this.propertyValue = propertyValue;
+ this.ignoreNull = ignoreNull;
}
/**
@@ -204,15 +203,14 @@
} catch (final IllegalArgumentException e) {
final String errorMsg = "Problem during evaluation. Null value encountered in property path...";
- if (ignoreNull) {
- log.warn(errorMsg, e);
- } else {
+ if (!ignoreNull) {
final IllegalArgumentException iae = new IllegalArgumentException(errorMsg);
if (!BeanUtils.initCause(iae, e)) {
log.error(errorMsg, e);
}
throw iae;
}
+ log.warn(errorMsg, e);
} catch (final IllegalAccessException e) {
final String errorMsg = "Unable to access the property provided.";
final IllegalArgumentException iae = new IllegalArgumentException(errorMsg);
diff --git a/src/main/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformer.java b/src/main/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformer.java
index e531b05..4ed4b2f 100644
--- a/src/main/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformer.java
+++ b/src/main/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformer.java
@@ -120,13 +120,12 @@
* empty.
*/
public BeanToPropertyValueTransformer(final String propertyName, final boolean ignoreNull) {
- if (propertyName != null && !propertyName.isEmpty()) {
- this.propertyName = propertyName;
- this.ignoreNull = ignoreNull;
- } else {
+ if (propertyName == null || propertyName.isEmpty()) {
throw new IllegalArgumentException(
"propertyName cannot be null or empty");
}
+ this.propertyName = propertyName;
+ this.ignoreNull = ignoreNull;
}
/**
@@ -155,15 +154,14 @@
} catch (final IllegalArgumentException e) {
final String errorMsg = "Problem during transformation. Null value encountered in property path...";
- if (ignoreNull) {
- log.warn(errorMsg, e);
- } else {
+ if (!ignoreNull) {
final IllegalArgumentException iae = new IllegalArgumentException(errorMsg);
if (!BeanUtils.initCause(iae, e)) {
log.error(errorMsg, e);
}
throw iae;
}
+ log.warn(errorMsg, e);
} catch (final IllegalAccessException e) {
final String errorMsg = "Unable to access the property provided.";
final IllegalArgumentException iae = new IllegalArgumentException(errorMsg);
diff --git a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java
index 815b531..4a571a6 100644
--- a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java
+++ b/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java
@@ -532,7 +532,8 @@
final Object value = getPropertyUtils().getProperty(bean, name);
if (value == null) {
return null;
- } else if (value instanceof Collection) {
+ }
+ if (value instanceof Collection) {
final ArrayList<String> values = new ArrayList<>();
for (final Object item : (Collection<?>) value) {
if (item == null) {
@@ -543,24 +544,24 @@
}
}
return values.toArray(new String[values.size()]);
- } else if (value.getClass().isArray()) {
- final int n = Array.getLength(value);
- final String[] results = new String[n];
- for (int i = 0; i < n; i++) {
- final Object item = Array.get(value, i);
- if (item == null) {
- results[i] = null;
- } else {
- // convert to string using convert utils
- results[i] = getConvertUtils().convert(item);
- }
- }
- return results;
- } else {
+ }
+ if (!value.getClass().isArray()) {
final String[] results = new String[1];
results[0] = getConvertUtils().convert(value);
return results;
}
+ final int n = Array.getLength(value);
+ final String[] results = new String[n];
+ for (int i = 0; i < n; i++) {
+ final Object item = Array.get(value, i);
+ if (item == null) {
+ results[i] = null;
+ } else {
+ // convert to string using convert utils
+ results[i] = getConvertUtils().convert(item);
+ }
+ }
+ return results;
}
diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java
index 07ccede..51817c2 100644
--- a/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java
+++ b/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java
@@ -191,22 +191,28 @@
if (type == Integer.TYPE) {
return (Class<T>) Integer.class;
- } else if (type == Double.TYPE) {
- return (Class<T>) Double.class;
- } else if (type == Long.TYPE) {
- return (Class<T>) Long.class;
- } else if (type == Boolean.TYPE) {
- return (Class<T>) Boolean.class;
- } else if (type == Float.TYPE) {
- return (Class<T>) Float.class;
- } else if (type == Short.TYPE) {
- return (Class<T>) Short.class;
- } else if (type == Byte.TYPE) {
- return (Class<T>) Byte.class;
- } else if (type == Character.TYPE) {
- return (Class<T>) Character.class;
- } else {
- return type;
}
+ if (type == Double.TYPE) {
+ return (Class<T>) Double.class;
+ }
+ if (type == Long.TYPE) {
+ return (Class<T>) Long.class;
+ }
+ if (type == Boolean.TYPE) {
+ return (Class<T>) Boolean.class;
+ }
+ if (type == Float.TYPE) {
+ return (Class<T>) Float.class;
+ }
+ if (type == Short.TYPE) {
+ return (Class<T>) Short.class;
+ }
+ if (type == Byte.TYPE) {
+ return (Class<T>) Byte.class;
+ }
+ if (type == Character.TYPE) {
+ return (Class<T>) Character.class;
+ }
+ return type;
}
}
diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java
index 7a551b8..19a5463 100644
--- a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java
+++ b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java
@@ -224,20 +224,20 @@
if (value == null) {
return null;
- } else if (value.getClass().isArray()) {
- if (Array.getLength(value) < 1) {
- return null;
- }
- value = Array.get(value, 0);
- if (value == null) {
- return null;
- }
- final Converter converter = lookup(String.class);
- return converter.convert(String.class, value);
- } else {
+ }
+ if (!value.getClass().isArray()) {
final Converter converter = lookup(String.class);
return converter.convert(String.class, value);
}
+ if (Array.getLength(value) < 1) {
+ return null;
+ }
+ value = Array.get(value, 0);
+ if (value == null) {
+ return null;
+ }
+ final Converter converter = lookup(String.class);
+ return converter.convert(String.class, value);
}
diff --git a/src/main/java/org/apache/commons/beanutils2/DynaProperty.java b/src/main/java/org/apache/commons/beanutils2/DynaProperty.java
index 6291b88..f8e9b8b 100644
--- a/src/main/java/org/apache/commons/beanutils2/DynaProperty.java
+++ b/src/main/java/org/apache/commons/beanutils2/DynaProperty.java
@@ -168,11 +168,11 @@
if (type == null) {
return false;
- } else if (type.isArray() || List.class.isAssignableFrom(type)) {
- return true;
- } else {
- return false;
}
+ if (type.isArray() || List.class.isAssignableFrom(type)) {
+ return true;
+ }
+ return false;
}
diff --git a/src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java b/src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java
index fbc612e..04fb9bd 100644
--- a/src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java
+++ b/src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java
@@ -367,13 +367,13 @@
// Return the indexed value
if (indexedProperty.getClass().isArray()) {
return Array.get(indexedProperty, index);
- } else if (indexedProperty instanceof List) {
- return ((List<?>)indexedProperty).get(index);
- } else {
- throw new IllegalArgumentException
- ("Non-indexed property for '" + name + "[" + index + "]' "
- + indexedProperty.getClass().getName());
}
+ if (indexedProperty instanceof List) {
+ return ((List<?>)indexedProperty).get(index);
+ }
+ throw new IllegalArgumentException
+ ("Non-indexed property for '" + name + "[" + index + "]' "
+ + indexedProperty.getClass().getName());
}
@@ -452,13 +452,12 @@
return;
}
- if (value instanceof Map) {
- ((Map<?, ?>) value).remove(key);
- } else {
+ if (!(value instanceof Map)) {
throw new IllegalArgumentException
("Non-mapped property for '" + name + "(" + key + ")'"
+ value.getClass().getName());
}
+ ((Map<?, ?>) value).remove(key);
}
@@ -800,23 +799,29 @@
if (type == Boolean.TYPE) {
return Boolean.FALSE;
- } else if (type == Integer.TYPE) {
- return Integer_ZERO;
- } else if (type == Long.TYPE) {
- return Long_ZERO;
- } else if (type == Double.TYPE) {
- return Double_ZERO;
- } else if (type == Float.TYPE) {
- return Float_ZERO;
- } else if (type == Byte.TYPE) {
- return Byte_ZERO;
- } else if (type == Short.TYPE) {
- return Short_ZERO;
- } else if (type == Character.TYPE) {
- return Character_SPACE;
- } else {
- return null;
}
+ if (type == Integer.TYPE) {
+ return Integer_ZERO;
+ }
+ if (type == Long.TYPE) {
+ return Long_ZERO;
+ }
+ if (type == Double.TYPE) {
+ return Double_ZERO;
+ }
+ if (type == Float.TYPE) {
+ return Float_ZERO;
+ }
+ if (type == Byte.TYPE) {
+ return Byte_ZERO;
+ }
+ if (type == Short.TYPE) {
+ return Short_ZERO;
+ }
+ if (type == Character.TYPE) {
+ return Character_SPACE;
+ }
+ return null;
}
diff --git a/src/main/java/org/apache/commons/beanutils2/MethodUtils.java b/src/main/java/org/apache/commons/beanutils2/MethodUtils.java
index 838884a..55c2f52 100644
--- a/src/main/java/org/apache/commons/beanutils2/MethodUtils.java
+++ b/src/main/java/org/apache/commons/beanutils2/MethodUtils.java
@@ -1174,24 +1174,29 @@
// does anyone know a better strategy than comparing names?
if (boolean.class.equals(primitiveType)) {
return Boolean.class;
- } else if (float.class.equals(primitiveType)) {
- return Float.class;
- } else if (long.class.equals(primitiveType)) {
- return Long.class;
- } else if (int.class.equals(primitiveType)) {
- return Integer.class;
- } else if (short.class.equals(primitiveType)) {
- return Short.class;
- } else if (byte.class.equals(primitiveType)) {
- return Byte.class;
- } else if (double.class.equals(primitiveType)) {
- return Double.class;
- } else if (char.class.equals(primitiveType)) {
- return Character.class;
- } else {
-
- return null;
}
+ if (float.class.equals(primitiveType)) {
+ return Float.class;
+ }
+ if (long.class.equals(primitiveType)) {
+ return Long.class;
+ }
+ if (int.class.equals(primitiveType)) {
+ return Integer.class;
+ }
+ if (short.class.equals(primitiveType)) {
+ return Short.class;
+ }
+ if (byte.class.equals(primitiveType)) {
+ return Byte.class;
+ }
+ if (double.class.equals(primitiveType)) {
+ return Double.class;
+ }
+ if (char.class.equals(primitiveType)) {
+ return Character.class;
+ }
+ return null;
}
/**
@@ -1205,27 +1210,33 @@
// does anyone know a better strategy than comparing names?
if (Boolean.class.equals(wrapperType)) {
return boolean.class;
- } else if (Float.class.equals(wrapperType)) {
- return float.class;
- } else if (Long.class.equals(wrapperType)) {
- return long.class;
- } else if (Integer.class.equals(wrapperType)) {
- return int.class;
- } else if (Short.class.equals(wrapperType)) {
- return short.class;
- } else if (Byte.class.equals(wrapperType)) {
- return byte.class;
- } else if (Double.class.equals(wrapperType)) {
- return double.class;
- } else if (Character.class.equals(wrapperType)) {
- return char.class;
- } else {
- final Log log = LogFactory.getLog(MethodUtils.class);
- if (log.isDebugEnabled()) {
- log.debug("Not a known primitive wrapper class: " + wrapperType);
- }
- return null;
}
+ if (Float.class.equals(wrapperType)) {
+ return float.class;
+ }
+ if (Long.class.equals(wrapperType)) {
+ return long.class;
+ }
+ if (Integer.class.equals(wrapperType)) {
+ return int.class;
+ }
+ if (Short.class.equals(wrapperType)) {
+ return short.class;
+ }
+ if (Byte.class.equals(wrapperType)) {
+ return byte.class;
+ }
+ if (Double.class.equals(wrapperType)) {
+ return double.class;
+ }
+ if (Character.class.equals(wrapperType)) {
+ return char.class;
+ }
+ final Log log = LogFactory.getLog(MethodUtils.class);
+ if (log.isDebugEnabled()) {
+ log.debug("Not a known primitive wrapper class: " + wrapperType);
+ }
+ return null;
}
/**
diff --git a/src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java
index 9b49dce..4628ffb 100644
--- a/src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java
+++ b/src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java
@@ -464,7 +464,8 @@
if (name == null || name.isEmpty()) {
if (bean.getClass().isArray()) {
return Array.get(bean, index);
- } else if (bean instanceof List) {
+ }
+ if (bean instanceof List) {
return ((List<?>)bean).get(index);
}
}
@@ -652,29 +653,27 @@
Method readMethod = ((MappedPropertyDescriptor) descriptor).
getMappedReadMethod();
readMethod = MethodUtils.getAccessibleMethod(bean.getClass(), readMethod);
- if (readMethod != null) {
- final Object[] keyArray = new Object[1];
- keyArray[0] = key;
- result = invokeMethod(readMethod, bean, keyArray);
- } else {
+ if (readMethod == null) {
throw new NoSuchMethodException("Property '" + name +
"' has no mapped getter method on bean class '" +
bean.getClass() + "'");
}
+ final Object[] keyArray = new Object[1];
+ keyArray[0] = key;
+ result = invokeMethod(readMethod, bean, keyArray);
} else {
/* means that the result has to be retrieved from a map */
final Method readMethod = getReadMethod(bean.getClass(), descriptor);
- if (readMethod != null) {
- final Object invokeResult = invokeMethod(readMethod, bean, BeanUtils.EMPTY_OBJECT_ARRAY);
- /* test and fetch from the map */
- if (invokeResult instanceof java.util.Map) {
- result = ((java.util.Map<?, ?>)invokeResult).get(key);
- }
- } else {
+ if (readMethod == null) {
throw new NoSuchMethodException("Property '" + name +
"' has no mapped getter method on bean class '" +
bean.getClass() + "'");
}
+ final Object invokeResult = invokeMethod(readMethod, bean, BeanUtils.EMPTY_OBJECT_ARRAY);
+ /* test and fetch from the map */
+ if (invokeResult instanceof java.util.Map) {
+ result = ((java.util.Map<?, ?>)invokeResult).get(key);
+ }
}
return result;
@@ -1111,26 +1110,27 @@
final Class<?> type = descriptor.getType();
if (type == null) {
return null;
- } else if (type.isArray()) {
- return type.getComponentType();
- } else {
- return type;
}
+ if (type.isArray()) {
+ return type.getComponentType();
+ }
+ return type;
}
final PropertyDescriptor descriptor =
getPropertyDescriptor(bean, name);
if (descriptor == null) {
return null;
- } else if (descriptor instanceof IndexedPropertyDescriptor) {
+ }
+ if (descriptor instanceof IndexedPropertyDescriptor) {
return ((IndexedPropertyDescriptor) descriptor).
getIndexedPropertyType();
- } else if (descriptor instanceof MappedPropertyDescriptor) {
+ }
+ if (descriptor instanceof MappedPropertyDescriptor) {
return ((MappedPropertyDescriptor) descriptor).
getMappedPropertyType();
- } else {
- return descriptor.getPropertyType();
}
+ return descriptor.getPropertyType();
}
@@ -1199,11 +1199,13 @@
throw new IllegalArgumentException
("Nested property names are not allowed: Property '" +
name + "' on bean class '" + bean.getClass() + "'");
- } else if (resolver.isIndexed(name)) {
+ }
+ if (resolver.isIndexed(name)) {
throw new IllegalArgumentException
("Indexed property names are not allowed: Property '" +
name + "' on bean class '" + bean.getClass() + "'");
- } else if (resolver.isMapped(name)) {
+ }
+ if (resolver.isMapped(name)) {
throw new IllegalArgumentException
("Mapped property names are not allowed: Property '" +
name + "' on bean class '" + bean.getClass() + "'");
@@ -1530,7 +1532,8 @@
if (bean.getClass().isArray()) {
Array.set(bean, index, value);
return;
- } else if (bean instanceof List) {
+ }
+ if (bean instanceof List) {
final List<Object> list = toObjectList(bean);
list.set(index, value);
return;
@@ -1603,14 +1606,13 @@
// Call the property getter to get the array or list
final Object array = invokeMethod(readMethod, bean, BeanUtils.EMPTY_OBJECT_ARRAY);
if (!array.getClass().isArray()) {
- if (array instanceof List) {
- // Modify the specified value in the List
- final List<Object> list = toObjectList(array);
- list.set(index, value);
- } else {
+ if (!(array instanceof List)) {
throw new IllegalArgumentException("Property '" + name +
"' is not indexed on bean class '" + bean.getClass() + "'");
}
+ // Modify the specified value in the List
+ final List<Object> list = toObjectList(array);
+ list.set(index, value);
} else {
// Modify the specified value in the array
Array.set(array, index, value);
@@ -1732,39 +1734,37 @@
((MappedPropertyDescriptor) descriptor).
getMappedWriteMethod();
mappedWriteMethod = MethodUtils.getAccessibleMethod(bean.getClass(), mappedWriteMethod);
- if (mappedWriteMethod != null) {
- final Object[] params = new Object[2];
- params[0] = key;
- params[1] = value;
- if (log.isTraceEnabled()) {
- final String valueClassName =
- value == null ? "<null>" : value.getClass().getName();
- log.trace("setSimpleProperty: Invoking method "
- + mappedWriteMethod + " with key=" + key
- + ", value=" + value
- + " (class " + valueClassName +")");
- }
- invokeMethod(mappedWriteMethod, bean, params);
- } else {
+ if (mappedWriteMethod == null) {
throw new NoSuchMethodException
("Property '" + name + "' has no mapped setter method" +
"on bean class '" + bean.getClass() + "'");
}
+ final Object[] params = new Object[2];
+ params[0] = key;
+ params[1] = value;
+ if (log.isTraceEnabled()) {
+ final String valueClassName =
+ value == null ? "<null>" : value.getClass().getName();
+ log.trace("setSimpleProperty: Invoking method "
+ + mappedWriteMethod + " with key=" + key
+ + ", value=" + value
+ + " (class " + valueClassName +")");
+ }
+ invokeMethod(mappedWriteMethod, bean, params);
} else {
/* means that the result has to be retrieved from a map */
final Method readMethod = getReadMethod(bean.getClass(), descriptor);
- if (readMethod != null) {
- final Object invokeResult = invokeMethod(readMethod, bean, BeanUtils.EMPTY_OBJECT_ARRAY);
- /* test and fetch from the map */
- if (invokeResult instanceof java.util.Map) {
- final java.util.Map<String, Object> map = toPropertyMap(invokeResult);
- map.put(key, value);
- }
- } else {
+ if (readMethod == null) {
throw new NoSuchMethodException("Property '" + name +
"' has no mapped getter method on bean class '" +
bean.getClass() + "'");
}
+ final Object invokeResult = invokeMethod(readMethod, bean, BeanUtils.EMPTY_OBJECT_ARRAY);
+ /* test and fetch from the map */
+ if (invokeResult instanceof java.util.Map) {
+ final java.util.Map<String, Object> map = toPropertyMap(invokeResult);
+ map.put(key, value);
+ }
}
}
@@ -1987,11 +1987,13 @@
throw new IllegalArgumentException
("Nested property names are not allowed: Property '" +
name + "' on bean class '" + bean.getClass() + "'");
- } else if (resolver.isIndexed(name)) {
+ }
+ if (resolver.isIndexed(name)) {
throw new IllegalArgumentException
("Indexed property names are not allowed: Property '" +
name + "' on bean class '" + bean.getClass() + "'");
- } else if (resolver.isMapped(name)) {
+ }
+ if (resolver.isMapped(name)) {
throw new IllegalArgumentException
("Mapped property names are not allowed: Property '" +
name + "' on bean class '" + bean.getClass() + "'");
diff --git a/src/main/java/org/apache/commons/beanutils2/WeakFastHashMap.java b/src/main/java/org/apache/commons/beanutils2/WeakFastHashMap.java
index 0518640..e1f5c5f 100644
--- a/src/main/java/org/apache/commons/beanutils2/WeakFastHashMap.java
+++ b/src/main/java/org/apache/commons/beanutils2/WeakFastHashMap.java
@@ -329,7 +329,8 @@
// Simple tests that require no synchronization
if (o == this) {
return true;
- } else if (!(o instanceof Map)) {
+ }
+ if (!(o instanceof Map)) {
return false;
}
final Map<?, ?> mo = (Map<?, ?>) o;
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/AbstractConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/AbstractConverter.java
index 2f72db0..af44f88 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/AbstractConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/AbstractConverter.java
@@ -187,7 +187,8 @@
return targetType.cast(convertToString(value));
// No conversion necessary
- } else if (targetType.equals(sourceType)) {
+ }
+ if (targetType.equals(sourceType)) {
if (log().isDebugEnabled()) {
log().debug(" No conversion required, value is already a "
+ toString(targetType));
@@ -195,14 +196,13 @@
return targetType.cast(value);
// Convert --> Type
- } else {
- final Object result = convertToType(targetType, value);
- if (log().isDebugEnabled()) {
- log().debug(" Converted to " + toString(targetType) +
- " value '" + result + "'");
- }
- return targetType.cast(result);
}
+ final Object result = convertToType(targetType, value);
+ if (log().isDebugEnabled()) {
+ log().debug(" Converted to " + toString(targetType) +
+ " value '" + result + "'");
+ }
+ return targetType.cast(result);
} catch (final Throwable t) {
return handleError(targetType, value, t);
}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/NumberConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/NumberConverter.java
index 1b33725..11ece55 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/NumberConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/NumberConverter.java
@@ -370,13 +370,14 @@
if (targetType.equals(BigDecimal.class)) {
if (value instanceof Float || value instanceof Double) {
return targetType.cast(new BigDecimal(value.toString()));
- } else if (value instanceof BigInteger) {
- return targetType.cast(new BigDecimal((BigInteger)value));
- } else if (value instanceof BigDecimal) {
- return targetType.cast(new BigDecimal(value.toString()));
- } else {
- return targetType.cast(BigDecimal.valueOf(value.longValue()));
}
+ if (value instanceof BigInteger) {
+ return targetType.cast(new BigDecimal((BigInteger)value));
+ }
+ if (value instanceof BigDecimal) {
+ return targetType.cast(new BigDecimal(value.toString()));
+ }
+ return targetType.cast(BigDecimal.valueOf(value.longValue()));
}
// BigInteger
diff --git a/src/main/java/org/apache/commons/beanutils2/expression/DefaultResolver.java b/src/main/java/org/apache/commons/beanutils2/expression/DefaultResolver.java
index 29d8bd1..90fc16b 100644
--- a/src/main/java/org/apache/commons/beanutils2/expression/DefaultResolver.java
+++ b/src/main/java/org/apache/commons/beanutils2/expression/DefaultResolver.java
@@ -84,7 +84,8 @@
final char c = expression.charAt(i);
if (c == NESTED || c == MAPPED_START) {
return -1;
- } else if (c == INDEXED_START) {
+ }
+ if (c == INDEXED_START) {
final int end = expression.indexOf(INDEXED_END, i);
if (end < 0) {
throw new IllegalArgumentException("Missing End Delimiter");
@@ -122,7 +123,8 @@
final char c = expression.charAt(i);
if (c == NESTED || c == INDEXED_START) {
return null;
- } else if (c == MAPPED_START) {
+ }
+ if (c == MAPPED_START) {
final int end = expression.indexOf(MAPPED_END, i);
if (end < 0) {
throw new IllegalArgumentException("Missing End Delimiter");
@@ -184,7 +186,8 @@
final char c = expression.charAt(i);
if (c == NESTED || c == MAPPED_START) {
return false;
- } else if (c == INDEXED_START) {
+ }
+ if (c == INDEXED_START) {
return true;
}
}
@@ -207,7 +210,8 @@
final char c = expression.charAt(i);
if (c == NESTED || c == INDEXED_START) {
return false;
- } else if (c == MAPPED_START) {
+ }
+ if (c == MAPPED_START) {
return true;
}
}
diff --git a/src/test/java/org/apache/commons/beanutils2/DynaRowSetTestCase.java b/src/test/java/org/apache/commons/beanutils2/DynaRowSetTestCase.java
index ab5529e..3f451b6 100644
--- a/src/test/java/org/apache/commons/beanutils2/DynaRowSetTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/DynaRowSetTestCase.java
@@ -369,11 +369,11 @@
final String columnName = getColumnName(columnIndex);
if (columnName.equals("dateProperty")) {
return java.sql.Timestamp.class.getName();
- } else if (columnName.equals("timestampProperty")) {
- return CustomTimestamp.class.getName();
- } else {
- return super.getColumnClassName(columnIndex);
}
+ if (columnName.equals("timestampProperty")) {
+ return CustomTimestamp.class.getName();
+ }
+ return super.getColumnClassName(columnIndex);
}
}
private static class CustomTimestamp {
diff --git a/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java b/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java
index ee9df63..86bde3a 100644
--- a/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java
@@ -3837,12 +3837,11 @@
try {
final PropertyDescriptor pd =
PropertyUtils.getPropertyDescriptor(bean, name);
- if (read != null || write != null) {
- assertNotNull("Got descriptor", pd);
- } else {
+ if (read == null && write == null) {
assertNull("Got descriptor", pd);
return;
}
+ assertNotNull("Got descriptor", pd);
final Method rm = pd.getReadMethod();
if (read != null) {
assertNotNull("Got read method", rm);
diff --git a/src/test/java/org/apache/commons/beanutils2/TestResultSet.java b/src/test/java/org/apache/commons/beanutils2/TestResultSet.java
index 73dd859..7447a29 100644
--- a/src/test/java/org/apache/commons/beanutils2/TestResultSet.java
+++ b/src/test/java/org/apache/commons/beanutils2/TestResultSet.java
@@ -158,36 +158,47 @@
}
if ("bigDecimalProperty".equals(columnName)) {
return new BigDecimal(123.45);
- } else if ("booleanProperty".equals(columnName)) {
+ }
+ if ("booleanProperty".equals(columnName)) {
if (row % 2 == 0) {
return Boolean.TRUE;
}
return Boolean.FALSE;
- } else if ("byteProperty".equals(columnName)) {
- return new Byte((byte) row);
- } else if ("dateProperty".equals(columnName)) {
- return new Date(timestampMillis);
- } else if ("doubleProperty".equals(columnName)) {
- return new Double(321.0);
- } else if ("floatProperty".equals(columnName)) {
- return new Float((float) 123.0);
- } else if ("intProperty".equals(columnName)) {
- return new Integer(100 + row);
- } else if ("longProperty".equals(columnName)) {
- return new Long(200 + row);
- } else if ("nullProperty".equals(columnName)) {
- return null;
- } else if ("shortProperty".equals(columnName)) {
- return new Short((short) (300 + row));
- } else if ("stringProperty".equals(columnName)) {
- return "This is a string";
- } else if ("timeProperty".equals(columnName)) {
- return new Time(timestampMillis);
- } else if ("timestampProperty".equals(columnName)) {
- return new Timestamp(timestampMillis);
- } else {
- throw new SQLException("Unknown column name " + columnName);
}
+ if ("byteProperty".equals(columnName)) {
+ return new Byte((byte) row);
+ }
+ if ("dateProperty".equals(columnName)) {
+ return new Date(timestampMillis);
+ }
+ if ("doubleProperty".equals(columnName)) {
+ return new Double(321.0);
+ }
+ if ("floatProperty".equals(columnName)) {
+ return new Float((float) 123.0);
+ }
+ if ("intProperty".equals(columnName)) {
+ return new Integer(100 + row);
+ }
+ if ("longProperty".equals(columnName)) {
+ return new Long(200 + row);
+ }
+ if ("nullProperty".equals(columnName)) {
+ return null;
+ }
+ if ("shortProperty".equals(columnName)) {
+ return new Short((short) (300 + row));
+ }
+ if ("stringProperty".equals(columnName)) {
+ return "This is a string";
+ }
+ if ("timeProperty".equals(columnName)) {
+ return new Time(timestampMillis);
+ }
+ if ("timestampProperty".equals(columnName)) {
+ return new Timestamp(timestampMillis);
+ }
+ throw new SQLException("Unknown column name " + columnName);
}
public Date getDate(final String columnName) throws SQLException {