Author: mbenson
Date: Fri Feb 5 23:18:32 2010
New Revision: 907129
URL: http://svn.apache.org/viewvc?rev=907129&view=rev
Log:
[LANG-586] merge
Modified:
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/builder/ToStringStyle.java
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/builder/ToStringBuilderTest.java
Modified:
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/builder/ToStringStyle.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/builder/ToStringStyle.java?rev=907129&r1=907128&r2=907129&view=diff
==============================================================================
---
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/builder/ToStringStyle.java
(original)
+++
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/builder/ToStringStyle.java
Fri Feb 5 23:18:32 2010
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,9 +19,8 @@
import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.Collection;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
+import java.util.WeakHashMap;
import org.apache.commons.lang.ClassUtils;
import org.apache.commons.lang.ObjectUtils;
@@ -46,7 +45,7 @@
* <p>For example, the detail version of the array based methods will
* output the whole array, whereas the summary method will just output
* the array length.</p>
- *
+ *
* <p>If you want to format the output of certain objects, such as dates, you
* must create a subclass and override a method.
* <pre>
@@ -73,17 +72,17 @@
/**
* The default toString style. Using the Using the <code>Person</code>
* example from {...@link ToStringBuilder}, the output would look like
this:
- *
+ *
* <pre>
* per...@182f0db[name=john Doe,age=33,smoker=false]
* </pre>
*/
public static final ToStringStyle DEFAULT_STYLE = new
DefaultToStringStyle();
-
+
/**
* The multi line toString style. Using the Using the <code>Person</code>
* example from {...@link ToStringBuilder}, the output would look like
this:
- *
+ *
* <pre>
* per...@182f0db[
* name=John Doe
@@ -93,26 +92,26 @@
* </pre>
*/
public static final ToStringStyle MULTI_LINE_STYLE = new
MultiLineToStringStyle();
-
+
/**
* The no field names toString style. Using the Using the
* <code>Person</code> example from {...@link ToStringBuilder}, the output
* would look like this:
- *
+ *
* <pre>
* per...@182f0db[john Doe,33,false]
* </pre>
*/
public static final ToStringStyle NO_FIELD_NAMES_STYLE = new
NoFieldNameToStringStyle();
-
+
/**
* The short prefix toString style. Using the <code>Person</code> example
* from {...@link ToStringBuilder}, the output would look like this:
- *
+ *
* <pre>
* Person[name=John Doe,age=33,smoker=false]
* </pre>
- *
+ *
* @since 2.1
*/
public static final ToStringStyle SHORT_PREFIX_STYLE = new
ShortPrefixToStringStyle();
@@ -120,37 +119,31 @@
/**
* The simple toString style. Using the Using the <code>Person</code>
* example from {...@link ToStringBuilder}, the output would look like
this:
- *
+ *
* <pre>
* John Doe,33,false
* </pre>
*/
public static final ToStringStyle SIMPLE_STYLE = new SimpleToStringStyle();
-
+
/**
* <p>
* A registry of objects used by <code>reflectionToString</code> methods
* to detect cyclical object references and avoid infinite loops.
* </p>
*/
- private static final ThreadLocal registry = new ThreadLocal() {
- protected Object initialValue() {
- // The HashSet implementation is not synchronized,
- // which is just what we need here.
- return new HashSet();
- }
- };
+ private static final ThreadLocal REGISTRY = new ThreadLocal();
/**
* <p>
* Returns the registry of objects being traversed by the
<code>reflectionToString</code>
* methods in the current thread.
* </p>
- *
+ *
* @return Set the registry of objects being traversed
*/
- static Set getRegistry() {
- return (Set) registry.get();
+ static Map getRegistry() {
+ return (Map) REGISTRY.get();
}
/**
@@ -158,14 +151,15 @@
* Returns <code>true</code> if the registry contains the given object.
* Used by the reflection methods to avoid infinite loops.
* </p>
- *
+ *
* @param value
* The object to lookup in the registry.
* @return boolean <code>true</code> if the registry contains the given
* object.
*/
static boolean isRegistered(Object value) {
- return getRegistry().contains(value);
+ Map m = getRegistry();
+ return m != null && m.containsKey(value);
}
/**
@@ -173,13 +167,18 @@
* Registers the given object. Used by the reflection methods to avoid
* infinite loops.
* </p>
- *
+ *
* @param value
* The object to register.
*/
static void register(Object value) {
if (value != null) {
- getRegistry().add(value);
+ Map m = getRegistry();
+ if (m == null) {
+ m = new WeakHashMap();
+ REGISTRY.set(m);
+ }
+ m.put(value, null);
}
}
@@ -187,33 +186,41 @@
* <p>
* Unregisters the given object.
* </p>
- *
+ *
* <p>
* Used by the reflection methods to avoid infinite loops.
* </p>
- *
+ *
* @param value
* The object to unregister.
*/
static void unregister(Object value) {
- getRegistry().remove(value);
+ if (value != null) {
+ Map m = getRegistry();
+ if (m != null) {
+ m.remove(value);
+ if (m.isEmpty()) {
+ REGISTRY.remove();
+ }
+ }
+ }
}
/**
* Whether to use the field names, the default is <code>true</code>.
*/
private boolean useFieldNames = true;
-
+
/**
* Whether to use the class name, the default is <code>true</code>.
*/
private boolean useClassName = true;
-
+
/**
* Whether to use short class names, the default is <code>false</code>.
*/
private boolean useShortClassName = false;
-
+
/**
* Whether to use the identity hash code, the default is <code>true</code>.
*/
@@ -223,78 +230,78 @@
* The content start <code>'['</code>.
*/
private String contentStart = "[";
-
+
/**
* The content end <code>']'</code>.
*/
private String contentEnd = "]";
-
+
/**
* The field name value separator <code>'='</code>.
*/
private String fieldNameValueSeparator = "=";
-
+
/**
* Whether the field separator should be added before any other fields.
*/
private boolean fieldSeparatorAtStart = false;
-
+
/**
* Whether the field separator should be added after any other fields.
*/
private boolean fieldSeparatorAtEnd = false;
-
+
/**
* The field separator <code>','</code>.
*/
private String fieldSeparator = ",";
-
+
/**
* The array start <code>'{'</code>.
*/
private String arrayStart = "{";
-
+
/**
* The array separator <code>','</code>.
*/
private String arraySeparator = ",";
-
+
/**
* The detail for array content.
*/
private boolean arrayContentDetail = true;
-
+
/**
* The array end <code>'}'</code>.
*/
private String arrayEnd = "}";
-
+
/**
* The value to use when fullDetail is <code>null</code>,
* the default value is <code>true</code>.
*/
private boolean defaultFullDetail = true;
-
+
/**
* The <code>null</code> text <code>'<null>'</code>.
*/
private String nullText = "<null>";
-
+
/**
* The summary size text start <code>'<size'</code>.
*/
private String sizeStartText = "<size=";
-
+
/**
* The summary size text start <code>'>'</code>.
*/
private String sizeEndText = ">";
-
+
/**
* The summary object text start <code>'<'</code>.
*/
private String summaryObjectStartText = "<";
-
+
/**
* The summary object text start <code>'>'</code>.
*/
@@ -314,9 +321,9 @@
/**
* <p>Append to the <code>toString</code> the superclass toString.</p>
* <p>NOTE: It assumes that the toString has been created from the same
ToStringStyle. </p>
- *
+ *
* <p>A <code>null</code> <code>superToString</code> is ignored.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @param superToString the <code>super.toString()</code>
* @since 2.0
@@ -328,9 +335,9 @@
/**
* <p>Append to the <code>toString</code> another toString.</p>
* <p>NOTE: It assumes that the toString has been created from the same
ToStringStyle. </p>
- *
+ *
* <p>A <code>null</code> <code>toString</code> is ignored.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @param toString the additional <code>toString</code>
* @since 2.0
@@ -352,7 +359,7 @@
/**
* <p>Append to the <code>toString</code> the start of data indicator.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @param object the <code>Object</code> to build a <code>toString</code>
for
*/
@@ -369,7 +376,7 @@
/**
* <p>Append to the <code>toString</code> the end of data indicator.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @param object the <code>Object</code> to build a
* <code>toString</code> for.
@@ -384,7 +391,7 @@
/**
* <p>Remove the last field separator from the buffer.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @since 2.0
*/
@@ -455,7 +462,7 @@
&& !(value instanceof Number || value instanceof Boolean || value
instanceof Character)) {
appendCyclicObject(buffer, fieldName, value);
return;
- }
+ }
register(value);
@@ -466,77 +473,77 @@
} else {
appendSummarySize(buffer, fieldName, ((Collection)
value).size());
}
-
+
} else if (value instanceof Map) {
if (detail) {
appendDetail(buffer, fieldName, (Map) value);
} else {
appendSummarySize(buffer, fieldName, ((Map) value).size());
}
-
+
} else if (value instanceof long[]) {
if (detail) {
appendDetail(buffer, fieldName, (long[]) value);
} else {
appendSummary(buffer, fieldName, (long[]) value);
}
-
+
} else if (value instanceof int[]) {
if (detail) {
appendDetail(buffer, fieldName, (int[]) value);
} else {
appendSummary(buffer, fieldName, (int[]) value);
}
-
+
} else if (value instanceof short[]) {
if (detail) {
appendDetail(buffer, fieldName, (short[]) value);
} else {
appendSummary(buffer, fieldName, (short[]) value);
}
-
+
} else if (value instanceof byte[]) {
if (detail) {
appendDetail(buffer, fieldName, (byte[]) value);
} else {
appendSummary(buffer, fieldName, (byte[]) value);
}
-
+
} else if (value instanceof char[]) {
if (detail) {
appendDetail(buffer, fieldName, (char[]) value);
} else {
appendSummary(buffer, fieldName, (char[]) value);
}
-
+
} else if (value instanceof double[]) {
if (detail) {
appendDetail(buffer, fieldName, (double[]) value);
} else {
appendSummary(buffer, fieldName, (double[]) value);
}
-
+
} else if (value instanceof float[]) {
if (detail) {
appendDetail(buffer, fieldName, (float[]) value);
} else {
appendSummary(buffer, fieldName, (float[]) value);
}
-
+
} else if (value instanceof boolean[]) {
if (detail) {
appendDetail(buffer, fieldName, (boolean[]) value);
} else {
appendSummary(buffer, fieldName, (boolean[]) value);
}
-
+
} else if (value.getClass().isArray()) {
if (detail) {
appendDetail(buffer, fieldName, (Object[]) value);
} else {
appendSummary(buffer, fieldName, (Object[]) value);
}
-
+
} else {
if (detail) {
appendDetail(buffer, fieldName, value);
@@ -548,17 +555,17 @@
unregister(value);
}
}
-
+
/**
* <p>Append to the <code>toString</code> an <code>Object</code>
* value that has been detected to participate in a cycle. This
* implementation will print the standard string value of the value.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
* @param value the value to add to the <code>toString</code>,
* not <code>null</code>
- *
+ *
* @since 2.2
*/
protected void appendCyclicObject(StringBuffer buffer, String fieldName,
Object value) {
@@ -1427,7 +1434,7 @@
/**
* <p>Append to the <code>toString</code> the class name.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @param object the <code>Object</code> whose name to output
*/
@@ -1444,7 +1451,7 @@
/**
* <p>Append the {...@link System#identityHashCode(java.lang.Object)}.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @param object the <code>Object</code> whose id to output
*/
@@ -1458,7 +1465,7 @@
/**
* <p>Append to the <code>toString</code> the content start.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
*/
protected void appendContentStart(StringBuffer buffer) {
@@ -1467,7 +1474,7 @@
/**
* <p>Append to the <code>toString</code> the content end.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
*/
protected void appendContentEnd(StringBuffer buffer) {
@@ -1478,7 +1485,7 @@
* <p>Append to the <code>toString</code> an indicator for
<code>null</code>.</p>
*
* <p>The default indicator is <code>'<null>'</code>.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
*/
@@ -1488,7 +1495,7 @@
/**
* <p>Append to the <code>toString</code> the field separator.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
*/
protected void appendFieldSeparator(StringBuffer buffer) {
@@ -1497,7 +1504,7 @@
/**
* <p>Append to the <code>toString</code> the field start.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name
*/
@@ -1510,7 +1517,7 @@
/**
* <p>Append to the <code>toString<code> the field end.</p>
- *
+ *
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
*/
@@ -1549,7 +1556,7 @@
* <code>null</code> indicating that it doesn't care about
* the detail level. In this case the default detail level is
* used.</p>
- *
+ *
* @param fullDetailRequest the detail level requested
* @return whether full detail is to be shown
*/
@@ -1907,9 +1914,9 @@
//---------------------------------------------------------------------
/**
- * <p>Gets whether the field separator should be added at the start
+ * <p>Gets whether the field separator should be added at the start
* of each buffer.</p>
- *
+ *
* @return the fieldSeparatorAtStart flag
* @since 2.0
*/
@@ -1918,9 +1925,9 @@
}
/**
- * <p>Sets whether the field separator should be added at the start
+ * <p>Sets whether the field separator should be added at the start
* of each buffer.</p>
- *
+ *
* @param fieldSeparatorAtStart the fieldSeparatorAtStart flag
* @since 2.0
*/
@@ -1931,9 +1938,9 @@
//---------------------------------------------------------------------
/**
- * <p>Gets whether the field separator should be added at the end
+ * <p>Gets whether the field separator should be added at the end
* of each buffer.</p>
- *
+ *
* @return fieldSeparatorAtEnd flag
* @since 2.0
*/
@@ -1942,9 +1949,9 @@
}
/**
- * <p>Sets whether the field separator should be added at the end
+ * <p>Sets whether the field separator should be added at the end
* of each buffer.</p>
- *
+ *
* @param fieldSeparatorAtEnd the fieldSeparatorAtEnd flag
* @since 2.0
*/
@@ -2118,7 +2125,7 @@
/**
* Required for serialization support.
- *
+ *
* @see java.io.Serializable
*/
private static final long serialVersionUID = 1L;
@@ -2178,7 +2185,7 @@
}
//----------------------------------------------------------------------------
-
+
/**
* <p><code>ToStringStyle</code> that prints out the short
* class name and no identity hashcode.</p>
Modified:
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/builder/ToStringBuilderTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/builder/ToStringBuilderTest.java?rev=907129&r1=907128&r2=907129&view=diff
==============================================================================
---
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/builder/ToStringBuilderTest.java
(original)
+++
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/builder/ToStringBuilderTest.java
Fri Feb 5 23:18:32 2010
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,7 +34,7 @@
private final Integer base = new Integer(5);
private final String baseStr = base.getClass().getName() + "@" +
Integer.toHexString(System.identityHashCode(base));
-
+
public ToStringBuilderTest(String name) {
super(name);
}
@@ -69,7 +69,7 @@
public void testSetDefaultEx() {
try {
ToStringBuilder.setDefaultStyle(null);
-
+
} catch (IllegalArgumentException ex) {
return;
}
@@ -79,7 +79,7 @@
public void testBlank() {
assertEquals(baseStr + "[]", new ToStringBuilder(base).toString());
}
-
+
/**
* Test wrapper for int primitive.
*/
@@ -114,9 +114,9 @@
private String toBaseString(Object o) {
return o.getClass().getName() + "@" +
Integer.toHexString(System.identityHashCode(o));
}
-
+
// Reflection Array tests
-
+
//
// Note on the following line of code repeated in the reflection array
tests.
//
@@ -124,12 +124,12 @@
//
// The expected value is not baseStr + "[<null>]" since array==null and is
typed as Object.
// The null array does not carry array type information.
- // If we added a primitive array type constructor and pile of associated
methods,
+ // If we added a primitive array type constructor and pile of associated
methods,
// then type declaring type information could be carried forward. IMHO,
null is null.
//
- // Gary Gregory - 2003-03-12 - [email protected]
+ // Gary Gregory - 2003-03-12 - [email protected]
//
-
+
public void assertReflectionArray(String expected, Object actual) {
if (actual == null) {
// Until ToStringBuilder supports null objects.
@@ -147,7 +147,7 @@
assertEquals(baseStr + "[{<null>,5,{3,6}}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionLongArray() {
@@ -156,7 +156,7 @@
assertEquals(baseStr + "[{1,2,-3,4}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionIntArray() {
@@ -165,7 +165,7 @@
assertEquals(baseStr + "[{1,2,-3,4}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionShortArray() {
@@ -174,7 +174,7 @@
assertEquals(baseStr + "[{1,2,-3,4}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionyteArray() {
@@ -183,7 +183,7 @@
assertEquals(baseStr + "[{1,2,-3,4}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionCharArray() {
@@ -192,7 +192,7 @@
assertEquals(baseStr + "[{A,2,_,D}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionDoubleArray() {
@@ -201,7 +201,7 @@
assertEquals(baseStr + "[{1.0,2.9876,-3.00001,4.3}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionFloatArray() {
@@ -210,7 +210,7 @@
assertEquals(baseStr + "[{1.0,2.9876,-3.00001,4.3}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionBooleanArray() {
@@ -219,9 +219,9 @@
assertEquals(baseStr + "[{true,false,false}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
-
+
// Reflection Array Array tests
public void testReflectionFloatArrayArray() {
@@ -230,7 +230,7 @@
assertEquals(baseStr + "[{{1.0,2.29686},<null>,{NaN}}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
@@ -240,7 +240,7 @@
assertEquals(baseStr + "[{{1,2},<null>,{5}}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionIntArrayArray() {
@@ -249,7 +249,7 @@
assertEquals(baseStr + "[{{1,2},<null>,{5}}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionhortArrayArray() {
@@ -258,7 +258,7 @@
assertEquals(baseStr + "[{{1,2},<null>,{5}}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionByteArrayArray() {
@@ -267,7 +267,7 @@
assertEquals(baseStr + "[{{1,2},<null>,{5}}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionCharArrayArray() {
@@ -276,7 +276,7 @@
assertEquals(baseStr + "[{{A,B},<null>,{p}}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionDoubleArrayArray() {
@@ -285,7 +285,7 @@
assertEquals(baseStr + "[{{1.0,2.29686},<null>,{NaN}}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionBooleanArrayArray() {
@@ -295,9 +295,9 @@
assertEquals(baseStr + "[{{true,false},<null>,{false}}]",
ToStringBuilder.reflectionToString(array));
array = null;
assertReflectionArray("<null>", array);
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
-
+
// Reflection hierarchy tests
public void testReflectionHierarchyArrayList() {
@@ -305,7 +305,7 @@
String baseStr = this.toBaseString(base);
assertEquals(baseStr +
"[elementData={<null>,<null>,<null>,<null>,<null>,<null>,<null>,<null>,<null>,<null>},size=0,modCount=0]",
ToStringBuilder.reflectionToString(base, null, true));
assertEquals(baseStr + "[size=0]",
ToStringBuilder.reflectionToString(base, null, false));
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionHierarchy() {
@@ -318,7 +318,7 @@
assertEquals(baseStr + "[a=a]",
ToStringBuilder.reflectionToString(baseA, null, false, null));
assertEquals(baseStr + "[a=a]",
ToStringBuilder.reflectionToString(baseA, null, false, Object.class));
assertEquals(baseStr + "[a=a]",
ToStringBuilder.reflectionToString(baseA, null, false,
ReflectionTestFixtureA.class));
-
+
ReflectionTestFixtureB baseB = new ReflectionTestFixtureB();
baseStr = this.toBaseString(baseB);
assertEquals(baseStr + "[b=b,a=a]",
ToStringBuilder.reflectionToString(baseB));
@@ -330,7 +330,7 @@
assertEquals(baseStr + "[b=b,a=a]",
ToStringBuilder.reflectionToString(baseB, null, false, Object.class));
assertEquals(baseStr + "[b=b,a=a]",
ToStringBuilder.reflectionToString(baseB, null, false,
ReflectionTestFixtureA.class));
assertEquals(baseStr + "[b=b]",
ToStringBuilder.reflectionToString(baseB, null, false,
ReflectionTestFixtureB.class));
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
static class ReflectionTestFixtureA {
@@ -347,7 +347,7 @@
Outer outer = new Outer();
assertEquals(toBaseString(outer) + "[inner=" +
toBaseString(outer.inner) + "[]]", outer.toString());
}
-
+
static class Outer {
Inner inner = new Inner();
class Inner {
@@ -359,7 +359,7 @@
return ToStringBuilder.reflectionToString(this);
}
}
-
+
// Reflection cycle tests
/**
@@ -371,7 +371,7 @@
assertEquals(
this.toBaseString(objects) + "[{" + this.toBaseString(objects) +
"}]",
ToStringBuilder.reflectionToString(objects));
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
/**
@@ -388,7 +388,7 @@
assertEquals(
this.toBaseString(objectsLevel2) + "[{{" +
this.toBaseString(objectsLevel2) + "}}]",
ToStringBuilder.reflectionToString(objectsLevel2));
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
public void testReflectionArrayArrayCycle() throws Exception {
@@ -410,7 +410,7 @@
+ basicToString
+ "}}]",
ToStringBuilder.reflectionToString(objects));
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
/**
@@ -464,7 +464,7 @@
return ToStringBuilder.reflectionToString(this);
}
}
-
+
private static class SelfInstanceTwoVarsReflectionTestFixture {
private SelfInstanceTwoVarsReflectionTestFixture typeIsSelf;
private String otherType = "The Other Type";
@@ -472,7 +472,7 @@
public SelfInstanceTwoVarsReflectionTestFixture() {
this.typeIsSelf = this;
}
-
+
public String getOtherType(){
return this.otherType;
}
@@ -481,50 +481,47 @@
return ToStringBuilder.reflectionToString(this);
}
}
-
-
+
+
/**
* Test an Object pointing to itself, the simplest test.
- *
+ *
* @throws Exception
*/
public void testSimpleReflectionObjectCycle() throws Exception {
SimpleReflectionTestFixture simple = new SimpleReflectionTestFixture();
simple.o = simple;
- assertTrue(ToStringStyle.getRegistry().isEmpty());
assertEquals(this.toBaseString(simple) + "[o=" +
this.toBaseString(simple) + "]", simple.toString());
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
/**
* Test a class that defines an ivar pointing to itself.
- *
+ *
* @throws Exception
*/
public void testSelfInstanceVarReflectionObjectCycle() throws Exception {
SelfInstanceVarReflectionTestFixture test = new
SelfInstanceVarReflectionTestFixture();
- assertTrue(ToStringStyle.getRegistry().isEmpty());
assertEquals(this.toBaseString(test) + "[typeIsSelf=" +
this.toBaseString(test) + "]", test.toString());
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
-
+
/**
- * Test a class that defines an ivar pointing to itself. This test was
+ * Test a class that defines an ivar pointing to itself. This test was
* created to show that handling cyclical object resulted in a missing
endFieldSeparator call.
- *
+ *
* @throws Exception
*/
public void testSelfInstanceTwoVarsReflectionObjectCycle() throws
Exception {
SelfInstanceTwoVarsReflectionTestFixture test = new
SelfInstanceTwoVarsReflectionTestFixture();
- assertTrue(ToStringStyle.getRegistry().isEmpty());
assertEquals(this.toBaseString(test) + "[typeIsSelf=" +
this.toBaseString(test) + ",otherType=" + test.getOtherType().toString() + "]",
test.toString());
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
-
+
/**
* Test Objects pointing to each other.
- *
+ *
* @throws Exception
*/
public void testReflectionObjectCycle() throws Exception {
@@ -535,13 +532,13 @@
assertEquals(
this.toBaseString(a) + "[b=" + this.toBaseString(b) + "[a=" +
this.toBaseString(a) + "]]",
a.toString());
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
-
+
/**
* Test a nasty combination of arrays and Objects pointing to each other.
* objects[0] -> SimpleReflectionTestFixture[ o -> objects ]
- *
+ *
* @throws Exception
*/
public void testReflectionArrayAndObjectCycle() throws Exception {
@@ -563,36 +560,36 @@
+ this.toBaseString(simple)
+ "}]",
ToStringBuilder.reflectionToString(simple));
- this.validateEmptyToStringStyleRegistry();
+ this.validateNullToStringStyleRegistry();
}
-
- void validateEmptyToStringStyleRegistry() {
- if (!ToStringStyle.getRegistry().isEmpty()) {
+
+ void validateNullToStringStyleRegistry() {
+ if (ToStringStyle.getRegistry() != null) {
System.out.println(ToStringStyle.getRegistry());
}
-
- assertTrue(ToStringStyle.getRegistry().isEmpty());
+
+ assertNull(ToStringStyle.getRegistry());
}
// End: Reflection cycle tests
public void testAppendSuper() {
assertEquals(baseStr + "[]", new
ToStringBuilder(base).appendSuper("inte...@8888[]").toString());
assertEquals(baseStr + "[<null>]", new
ToStringBuilder(base).appendSuper("inte...@8888[<null>]").toString());
-
+
assertEquals(baseStr + "[a=hello]", new
ToStringBuilder(base).appendSuper("inte...@8888[]").append("a",
"hello").toString());
assertEquals(baseStr + "[<null>,a=hello]", new
ToStringBuilder(base).appendSuper("inte...@8888[<null>]").append("a",
"hello").toString());
assertEquals(baseStr + "[a=hello]", new
ToStringBuilder(base).appendSuper(null).append("a", "hello").toString());
}
-
+
public void testAppendToString() {
assertEquals(baseStr + "[]", new
ToStringBuilder(base).appendToString("inte...@8888[]").toString());
assertEquals(baseStr + "[<null>]", new
ToStringBuilder(base).appendToString("inte...@8888[<null>]").toString());
-
+
assertEquals(baseStr + "[a=hello]", new
ToStringBuilder(base).appendToString("inte...@8888[]").append("a",
"hello").toString());
assertEquals(baseStr + "[<null>,a=hello]", new
ToStringBuilder(base).appendToString("inte...@8888[<null>]").append("a",
"hello").toString());
assertEquals(baseStr + "[a=hello]", new
ToStringBuilder(base).appendToString(null).append("a", "hello").toString());
}
-
+
public void testObject() {
Integer i3 = new Integer(3);
Integer i4 = new Integer(4);
@@ -694,7 +691,7 @@
assertEquals(baseStr + "[<null>]", new
ToStringBuilder(base).append(array).toString());
assertEquals(baseStr + "[<null>]", new
ToStringBuilder(base).append((Object) array).toString());
}
-
+
public void testByteArray() {
byte[] array = new byte[] {1, 2, -3, 4};
assertEquals(baseStr + "[{1,2,-3,4}]", new
ToStringBuilder(base).append(array).toString());
@@ -730,7 +727,7 @@
assertEquals(baseStr + "[<null>]", new
ToStringBuilder(base).append(array).toString());
assertEquals(baseStr + "[<null>]", new
ToStringBuilder(base).append((Object) array).toString());
}
-
+
public void testBooleanArray() {
boolean[] array = new boolean[] {true, false, false};
assertEquals(baseStr + "[{true,false,false}]", new
ToStringBuilder(base).append(array).toString());
@@ -817,20 +814,20 @@
ObjectCycle b = new ObjectCycle();
a.obj = b;
b.obj = a;
-
+
String expected = toBaseString(a) + "[" + toBaseString(b) + "[" +
toBaseString(a) + "]]";
assertEquals(expected, a.toString());
- validateEmptyToStringStyleRegistry();
+ validateNullToStringStyleRegistry();
}
-
+
static class ObjectCycle {
Object obj;
-
+
public String toString() {
return new ToStringBuilder(this).append(obj).toString();
}
}
-
+
public void testSimpleReflectionStatics() {
SimpleReflectionStaticFieldsFixture instance1 = new
SimpleReflectionStaticFieldsFixture();
assertEquals(
@@ -896,12 +893,12 @@
*
* <p>Transient fields are not output.</p>
*
- * <p>Superclass fields will be appended up to and including the specified
superclass.
+ * <p>Superclass fields will be appended up to and including the specified
superclass.
* A null superclass is treated as <code>java.lang.Object</code>.</p>
*
* <p>If the style is <code>null</code>, the default
* <code>ToStringStyle</code> is used.</p>
- *
+ *
* @param object the Object to be output
* @param style the style of the <code>toString</code> to create,
* may be <code>null</code>
@@ -922,7 +919,7 @@
ReflectionToStringBuilder test = new ReflectionToStringBuilder(val);
test.setUpToClass(Number.class);
}
-
+
/**
* Tests ReflectionToStringBuilder setUpToClass().
*/
@@ -936,7 +933,7 @@
// expected
}
}
-
+
/**
* Tests ReflectionToStringBuilder.toString() for statics.
*/