ggregory 2003/07/15 16:04:23
Modified: lang/src/java/org/apache/commons/lang/builder
ReflectionToStringBuilder.java
Log:
Give a Javadoc example for overridding the accept method.
Revision Changes Path
1.4 +15 -7
jakarta-commons/lang/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java
Index: ReflectionToStringBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReflectionToStringBuilder.java 14 Jul 2003 23:02:27 -0000 1.3
+++ ReflectionToStringBuilder.java 15 Jul 2003 23:04:23 -0000 1.4
@@ -11,7 +11,7 @@
* <p>Builds <code>toString()</code> values using reflection.</p>
*
* <p>This class uses reflection to determine the fields to append.
- * Because these fields are usually private, the class,
+ * Because these fields are usually private, the class
* uses <code>Field.setAccessible</code> to
* change the visibility of the fields. This will fail under a security manager,
* unless the appropriate permissions are set up correctly.</p>
@@ -20,13 +20,11 @@
* <pre>
* public String toString() {
* return ReflectionToStringBuilder.toString(this);
- * }
- * </pre>
+ * }</pre>
*
* <p>You can also use the builder to debug 3rd party objects:</p>
* <pre>
- * System.out.println("An object: " + ReflectionToStringBuilder.toString(anObject));
- * </pre>
+ * System.out.println("An object: " +
ReflectionToStringBuilder.toString(anObject));</pre>
*
* <p>A subclass can control field output by overriding the methods:
* <ul>
@@ -34,6 +32,16 @@
* <li>[EMAIL PROTECTED] #getValue(java.lang.reflect.Field)}</li>
* </ul>
* </p>
+ * <p>For example, this method does <i>not</i> include the <code>password</code>
field in the returned
+ * <code>String</code>:</p>
+ * <pre>
+ * public String toString() {
+ * return (new ReflectionToStringBuilder(this) {
+ * protected boolean accept(Field f) {
+ * return super.accept(f) && !f.getName().equals("password");
+ * }
+ * }).toString();
+ * }</pre>
*
* <p>The exact format of the <code>toString</code> is determined by
* the [EMAIL PROTECTED] ToStringStyle} passed into the constructor.</p>
@@ -382,7 +390,7 @@
}
/**
- * <p>Calls <code>java.lang.reflect.Field.get(Object)</code></p>
+ * <p>Calls <code>java.lang.reflect.Field.get(Object)}</code></p>
*
* @see java.lang.reflect.Field#get(Object)
* @throws IllegalArgumentException
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]