Replacing the creation of a List in the core of each Builder class to test contains on the excludeFields with a call to ArrayUtils.contains. Reported by Anthony Whitford in LANG-575

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@897421 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2010-01-09 11:44:06 +00:00
parent 8d518b7786
commit 5494a87bbb
3 changed files with 9 additions and 6 deletions

View File

@ -25,6 +25,8 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
/**
* Assists in implementing {@link java.lang.Comparable#compareTo(Object)} methods.
*
@ -353,11 +355,10 @@ public class CompareToBuilder {
String[] excludeFields) {
Field[] fields = clazz.getDeclaredFields();
List<String> excludedFieldList = excludeFields != null ? Arrays.asList(excludeFields) : Collections.<String>emptyList();
AccessibleObject.setAccessible(fields, true);
for (int i = 0; i < fields.length && builder.comparison == 0; i++) {
Field f = fields[i];
if (!excludedFieldList.contains(f.getName())
if (!ArrayUtils.contains(excludeFields, f.getName())
&& (f.getName().indexOf('$') == -1)
&& (useTransients || !Modifier.isTransient(f.getModifiers()))
&& (!Modifier.isStatic(f.getModifiers()))) {

View File

@ -24,6 +24,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
/**
* <p>Assists in implementing {@link Object#equals(Object)} methods.</p>
*
@ -318,11 +320,10 @@ public class EqualsBuilder {
boolean useTransients,
String[] excludeFields) {
Field[] fields = clazz.getDeclaredFields();
List<String> excludedFieldList = excludeFields != null ? Arrays.asList(excludeFields) : Collections.<String>emptyList();
AccessibleObject.setAccessible(fields, true);
for (int i = 0; i < fields.length && builder.isEquals; i++) {
Field f = fields[i];
if (!excludedFieldList.contains(f.getName())
if (!ArrayUtils.contains(excludeFields, f.getName())
&& (f.getName().indexOf('$') == -1)
&& (useTransients || !Modifier.isTransient(f.getModifiers()))
&& (!Modifier.isStatic(f.getModifiers()))) {

View File

@ -27,6 +27,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
/**
* <p>
* Assists in implementing {@link Object#hashCode()} methods.
@ -179,10 +181,9 @@ public class HashCodeBuilder {
try {
register(object);
Field[] fields = clazz.getDeclaredFields();
List<String> excludedFieldList = excludeFields != null ? Arrays.asList(excludeFields) : Collections.<String>emptyList();
AccessibleObject.setAccessible(fields, true);
for (Field field : fields) {
if (!excludedFieldList.contains(field.getName())
if (!ArrayUtils.contains(excludeFields, field.getName())
&& (field.getName().indexOf('$') == -1)
&& (useTransients || !Modifier.isTransient(field.getModifiers()))
&& (!Modifier.isStatic(field.getModifiers()))) {