From 5494a87bbb6d6b6f0d176d0c93e4f25718ed3c2a Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Sat, 9 Jan 2010 11:44:06 +0000 Subject: [PATCH] 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 --- .../org/apache/commons/lang3/builder/CompareToBuilder.java | 5 +++-- .../java/org/apache/commons/lang3/builder/EqualsBuilder.java | 5 +++-- .../org/apache/commons/lang3/builder/HashCodeBuilder.java | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java index f186e9e8f..bb6372825 100644 --- a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java @@ -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 excludedFieldList = excludeFields != null ? Arrays.asList(excludeFields) : Collections.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()))) { diff --git a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java index 9f590ec5a..9a1d7bece 100644 --- a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java @@ -24,6 +24,8 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import org.apache.commons.lang3.ArrayUtils; + /** *

Assists in implementing {@link Object#equals(Object)} methods.

* @@ -318,11 +320,10 @@ public class EqualsBuilder { boolean useTransients, String[] excludeFields) { Field[] fields = clazz.getDeclaredFields(); - List excludedFieldList = excludeFields != null ? Arrays.asList(excludeFields) : Collections.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()))) { diff --git a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java index 16e216dd6..6d98af015 100644 --- a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java @@ -27,6 +27,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.commons.lang3.ArrayUtils; + /** *

* Assists in implementing {@link Object#hashCode()} methods. @@ -179,10 +181,9 @@ public class HashCodeBuilder { try { register(object); Field[] fields = clazz.getDeclaredFields(); - List excludedFieldList = excludeFields != null ? Arrays.asList(excludeFields) : Collections.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()))) {