Skip to content

Commit 1c16973

Browse files
committed
Reduce whitespace
1 parent 258a19c commit 1c16973

File tree

1 file changed

+25
-95
lines changed

1 file changed

+25
-95
lines changed

src/main/java/org/apache/commons/beanutils/BeanUtilsBean.java

Lines changed: 25 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
* @see BeanUtils
4343
* @since 1.7
4444
*/
45-
4645
public class BeanUtilsBean {
4746

4847
/**
@@ -73,7 +72,6 @@ private static Class<?> dynaPropertyType(final DynaProperty dynaProperty,
7372
return value == null ? String.class : value.getClass();
7473
}
7574

76-
7775
/**
7876
* Gets the instance which provides the functionality for {@link BeanUtils}.
7977
* This is a pseudo-singleton - an single instance is provided per (thread) context classloader.
@@ -101,7 +99,6 @@ public static void setInstance(final BeanUtilsBean newInstance) {
10199
*/
102100
private final Log log = LogFactory.getLog(BeanUtils.class);
103101

104-
105102
/** Used to perform conversions between object types when setting properties */
106103
private final ConvertUtilsBean convertUtilsBean;
107104

@@ -116,7 +113,6 @@ public BeanUtilsBean() {
116113
this(new ConvertUtilsBean(), new PropertyUtilsBean());
117114
}
118115

119-
120116
/**
121117
* <p>Constructs an instance using given conversion instances
122118
* and new {@link PropertyUtilsBean} instance.</p>
@@ -130,7 +126,6 @@ public BeanUtilsBean(final ConvertUtilsBean convertUtilsBean) {
130126
this(convertUtilsBean, new PropertyUtilsBean());
131127
}
132128

133-
134129
/**
135130
* <p>Constructs an instance using given property and conversion instances.</p>
136131
*
@@ -139,15 +134,11 @@ public BeanUtilsBean(final ConvertUtilsBean convertUtilsBean) {
139134
* @param propertyUtilsBean use this <code>PropertyUtilsBean</code>
140135
* to access properties
141136
*/
142-
public BeanUtilsBean(
143-
final ConvertUtilsBean convertUtilsBean,
144-
final PropertyUtilsBean propertyUtilsBean) {
145-
137+
public BeanUtilsBean(final ConvertUtilsBean convertUtilsBean, final PropertyUtilsBean propertyUtilsBean) {
146138
this.convertUtilsBean = convertUtilsBean;
147139
this.propertyUtilsBean = propertyUtilsBean;
148140
}
149141

150-
151142
/**
152143
* <p>Clone a bean based on the available property getters and setters,
153144
* even if the bean class itself does not implement Cloneable.</p>
@@ -169,10 +160,7 @@ public BeanUtilsBean(
169160
* @throws NoSuchMethodException if an accessor method for this
170161
* property cannot be found
171162
*/
172-
public Object cloneBean(final Object bean)
173-
throws IllegalAccessException, InstantiationException,
174-
InvocationTargetException, NoSuchMethodException {
175-
163+
public Object cloneBean(final Object bean) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
176164
if (log.isDebugEnabled()) {
177165
log.debug("Cloning bean: " + bean.getClass().getName());
178166
}
@@ -184,10 +172,8 @@ public Object cloneBean(final Object bean)
184172
}
185173
getPropertyUtils().copyProperties(newBean, bean);
186174
return newBean;
187-
188175
}
189176

190-
191177
/**
192178
* <p>Convert the value to an object of the specified class (if
193179
* possible).</p>
@@ -207,7 +193,6 @@ protected Object convert(final Object value, final Class<?> type) {
207193
return value;
208194
}
209195

210-
211196
/**
212197
* Performs a type conversion of a property value before it is copied to a target
213198
* bean. This method delegates to {@link #convert(Object, Class)}, but <strong>null</strong>
@@ -221,7 +206,6 @@ private Object convertForCopy(final Object value, final Class<?> type) {
221206
return value != null ? convert(value, type) : value;
222207
}
223208

224-
225209
/**
226210
* <p>Copy property values from the origin bean to the destination bean
227211
* for all cases where the property names are the same. For each
@@ -327,7 +311,6 @@ public void copyProperties(final Object dest, final Object orig)
327311

328312
}
329313

330-
331314
/**
332315
* <p>Copy the specified property value to the specified destination bean,
333316
* performing any type conversion that is required. If the specified
@@ -477,7 +460,6 @@ public void copyProperty(final Object bean, String name, Object value)
477460

478461
}
479462

480-
481463
/**
482464
* <p>Return the entire set of properties for which the specified bean
483465
* provides a read method. This map contains the to <code>String</code>
@@ -552,7 +534,6 @@ public Map<String, String> describe(final Object bean)
552534

553535
}
554536

555-
556537
/**
557538
* Return the value of the specified array property of the specified
558539
* bean, as a String array.
@@ -607,7 +588,6 @@ public String[] getArrayProperty(final Object bean, final String name)
607588

608589
}
609590

610-
611591
/**
612592
* Gets the <code>ConvertUtilsBean</code> instance used to perform the conversions.
613593
*
@@ -617,7 +597,6 @@ public ConvertUtilsBean getConvertUtils() {
617597
return convertUtilsBean;
618598
}
619599

620-
621600
/**
622601
* Return the value of the specified indexed property of the specified
623602
* bean, as a String. The zero-relative index of the
@@ -636,16 +615,11 @@ public ConvertUtilsBean getConvertUtils() {
636615
* @throws NoSuchMethodException if an accessor method for this
637616
* property cannot be found
638617
*/
639-
public String getIndexedProperty(final Object bean, final String name)
640-
throws IllegalAccessException, InvocationTargetException,
641-
NoSuchMethodException {
642-
618+
public String getIndexedProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
643619
final Object value = getPropertyUtils().getIndexedProperty(bean, name);
644620
return getConvertUtils().convert(value);
645-
646621
}
647622

648-
649623
/**
650624
* Return the value of the specified indexed property of the specified
651625
* bean, as a String. The index is specified as a method parameter and
@@ -662,17 +636,12 @@ public String getIndexedProperty(final Object bean, final String name)
662636
* @throws NoSuchMethodException if an accessor method for this
663637
* property cannot be found
664638
*/
665-
public String getIndexedProperty(final Object bean,
666-
final String name, final int index)
667-
throws IllegalAccessException, InvocationTargetException,
668-
NoSuchMethodException {
669-
639+
public String getIndexedProperty(final Object bean, final String name, final int index)
640+
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
670641
final Object value = getPropertyUtils().getIndexedProperty(bean, name, index);
671642
return getConvertUtils().convert(value);
672-
673643
}
674644

675-
676645
/**
677646
* Return the value of the specified indexed property of the specified
678647
* bean, as a String. The String-valued key of the required value
@@ -691,16 +660,11 @@ public String getIndexedProperty(final Object bean,
691660
* @throws NoSuchMethodException if an accessor method for this
692661
* property cannot be found
693662
*/
694-
public String getMappedProperty(final Object bean, final String name)
695-
throws IllegalAccessException, InvocationTargetException,
696-
NoSuchMethodException {
697-
663+
public String getMappedProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
698664
final Object value = getPropertyUtils().getMappedProperty(bean, name);
699665
return getConvertUtils().convert(value);
700-
701666
}
702667

703-
704668
/**
705669
* Return the value of the specified mapped property of the specified
706670
* bean, as a String. The key is specified as a method parameter and
@@ -717,11 +681,8 @@ public String getMappedProperty(final Object bean, final String name)
717681
* @throws NoSuchMethodException if an accessor method for this
718682
* property cannot be found
719683
*/
720-
public String getMappedProperty(final Object bean,
721-
final String name, final String key)
722-
throws IllegalAccessException, InvocationTargetException,
723-
NoSuchMethodException {
724-
684+
public String getMappedProperty(final Object bean, final String name, final String key)
685+
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
725686
final Object value = getPropertyUtils().getMappedProperty(bean, name, key);
726687
return getConvertUtils().convert(value);
727688

@@ -743,13 +704,9 @@ public String getMappedProperty(final Object bean,
743704
* @throws NoSuchMethodException if an accessor method for this
744705
* property cannot be found
745706
*/
746-
public String getNestedProperty(final Object bean, final String name)
747-
throws IllegalAccessException, InvocationTargetException,
748-
NoSuchMethodException {
749-
707+
public String getNestedProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
750708
final Object value = getPropertyUtils().getNestedProperty(bean, name);
751709
return getConvertUtils().convert(value);
752-
753710
}
754711

755712
/**
@@ -767,12 +724,8 @@ public String getNestedProperty(final Object bean, final String name)
767724
* @throws NoSuchMethodException if an accessor method for this
768725
* property cannot be found
769726
*/
770-
public String getProperty(final Object bean, final String name)
771-
throws IllegalAccessException, InvocationTargetException,
772-
NoSuchMethodException {
773-
727+
public String getProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
774728
return getNestedProperty(bean, name);
775-
776729
}
777730

778731
/**
@@ -798,13 +751,9 @@ public PropertyUtilsBean getPropertyUtils() {
798751
* @throws NoSuchMethodException if an accessor method for this
799752
* property cannot be found
800753
*/
801-
public String getSimpleProperty(final Object bean, final String name)
802-
throws IllegalAccessException, InvocationTargetException,
803-
NoSuchMethodException {
804-
754+
public String getSimpleProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
805755
final Object value = getPropertyUtils().getSimpleProperty(bean, name);
806756
return getConvertUtils().convert(value);
807-
808757
}
809758

810759
/**
@@ -860,7 +809,6 @@ public boolean initCause(final Throwable throwable, final Throwable cause) {
860809
*/
861810
public void populate(final Object bean, final Map<String, ? extends Object> properties)
862811
throws IllegalAccessException, InvocationTargetException {
863-
864812
// Do nothing unless both arguments have been specified
865813
if (bean == null || properties == null) {
866814
return;
@@ -869,20 +817,16 @@ public void populate(final Object bean, final Map<String, ? extends Object> prop
869817
log.debug("BeanUtils.populate(" + bean + ", " +
870818
properties + ")");
871819
}
872-
873820
// Loop through the property name/value pairs to be set
874821
for(final Map.Entry<String, ? extends Object> entry : properties.entrySet()) {
875822
// Identify the property name and value(s) to be assigned
876823
final String name = entry.getKey();
877824
if (name == null) {
878825
continue;
879826
}
880-
881827
// Perform the assignment for this property
882828
setProperty(bean, name, entry.getValue());
883-
884829
}
885-
886830
}
887831

888832
/**
@@ -914,9 +858,7 @@ public void populate(final Object bean, final Map<String, ? extends Object> prop
914858
* @throws InvocationTargetException if the property accessor method
915859
* throws an exception
916860
*/
917-
public void setProperty(final Object bean, String name, final Object value)
918-
throws IllegalAccessException, InvocationTargetException {
919-
861+
public void setProperty(final Object bean, String name, final Object value) throws IllegalAccessException, InvocationTargetException {
920862
// Trace logging (if enabled)
921863
if (log.isTraceEnabled()) {
922864
final StringBuilder sb = new StringBuilder(" setProperty(");
@@ -944,7 +886,6 @@ public void setProperty(final Object bean, String name, final Object value)
944886
sb.append(')');
945887
log.trace(sb.toString());
946888
}
947-
948889
// Resolve any nested expression to get the actual target bean
949890
Object target = bean;
950891
final Resolver resolver = getPropertyUtils().getResolver();
@@ -963,12 +904,11 @@ public void setProperty(final Object bean, String name, final Object value)
963904
log.trace(" Target bean = " + target);
964905
log.trace(" Target name = " + name);
965906
}
966-
967907
// Declare local variables we will require
968908
final String propName = resolver.getProperty(name); // Simple name of target property
969-
Class<?> type = null; // Java type of target property
970-
final int index = resolver.getIndex(name); // Indexed subscript value (if any)
971-
final String key = resolver.getKey(name); // Mapped key value (if any)
909+
Class<?> type = null; // Java type of target property
910+
final int index = resolver.getIndex(name); // Indexed subscript value (if any)
911+
final String key = resolver.getKey(name); // Mapped key value (if any)
972912

973913
// Calculate the property type
974914
if (target instanceof DynaBean) {
@@ -979,7 +919,7 @@ public void setProperty(final Object bean, String name, final Object value)
979919
}
980920
type = dynaPropertyType(dynaProperty, value);
981921
if (index >= 0 && List.class.isAssignableFrom(type)) {
982-
type = Object.class;
922+
type = Object.class;
983923
}
984924
} else if (target instanceof Map) {
985925
type = Object.class;
@@ -988,8 +928,7 @@ public void setProperty(final Object bean, String name, final Object value)
988928
} else {
989929
PropertyDescriptor descriptor = null;
990930
try {
991-
descriptor =
992-
getPropertyUtils().getPropertyDescriptor(target, name);
931+
descriptor = getPropertyUtils().getPropertyDescriptor(target, name);
993932
if (descriptor == null) {
994933
return; // Skip this property setter
995934
}
@@ -1003,17 +942,15 @@ public void setProperty(final Object bean, String name, final Object value)
1003942
}
1004943
return; // Read-only, skip this property setter
1005944
}
1006-
type = ((MappedPropertyDescriptor) descriptor).
1007-
getMappedPropertyType();
945+
type = ((MappedPropertyDescriptor) descriptor).getMappedPropertyType();
1008946
} else if (index >= 0 && descriptor instanceof IndexedPropertyDescriptor) {
1009947
if (((IndexedPropertyDescriptor) descriptor).getIndexedWriteMethod() == null) {
1010948
if (log.isDebugEnabled()) {
1011949
log.debug("Skipping read-only property");
1012950
}
1013951
return; // Read-only, skip this property setter
1014952
}
1015-
type = ((IndexedPropertyDescriptor) descriptor).
1016-
getIndexedPropertyType();
953+
type = ((IndexedPropertyDescriptor) descriptor).getIndexedPropertyType();
1017954
} else if (index >= 0 && List.class.isAssignableFrom(descriptor.getPropertyType())) {
1018955
type = Object.class;
1019956
} else if (key != null) {
@@ -1034,7 +971,6 @@ public void setProperty(final Object bean, String name, final Object value)
1034971
type = descriptor.getPropertyType();
1035972
}
1036973
}
1037-
1038974
// Convert the specified value to the required type
1039975
Object newValue = null;
1040976
if (type.isArray() && index < 0) { // Scalar value into array
@@ -1049,32 +985,26 @@ public void setProperty(final Object bean, String name, final Object value)
1049985
} else {
1050986
newValue = convert(value, type);
1051987
}
1052-
} else if (type.isArray()) { // Indexed value into array
988+
} else if (type.isArray()) { // Indexed value into array
1053989
if (value instanceof String || value == null) {
1054-
newValue = getConvertUtils().convert((String) value,
1055-
type.getComponentType());
990+
newValue = getConvertUtils().convert((String) value, type.getComponentType());
1056991
} else if (value instanceof String[]) {
1057-
newValue = getConvertUtils().convert(((String[]) value)[0],
1058-
type.getComponentType());
992+
newValue = getConvertUtils().convert(((String[]) value)[0], type.getComponentType());
1059993
} else {
1060994
newValue = convert(value, type.getComponentType());
1061995
}
1062996
} else if (value instanceof String) {
1063997
newValue = getConvertUtils().convert((String) value, type);
1064998
} else if (value instanceof String[]) {
1065-
newValue = getConvertUtils().convert(((String[]) value)[0],
1066-
type);
999+
newValue = getConvertUtils().convert(((String[]) value)[0], type);
10671000
} else {
10681001
newValue = convert(value, type);
10691002
}
1070-
10711003
// Invoke the setter method
10721004
try {
1073-
getPropertyUtils().setProperty(target, name, newValue);
1005+
getPropertyUtils().setProperty(target, name, newValue);
10741006
} catch (final NoSuchMethodException e) {
1075-
throw new InvocationTargetException
1076-
(e, "Cannot set " + propName);
1007+
throw new InvocationTargetException(e, "Cannot set " + propName);
10771008
}
1078-
10791009
}
10801010
}

0 commit comments

Comments
 (0)