From: <iro...@us...> - 2008-11-10 22:22:36
|
Revision: 70 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=70&view=rev Author: iroberts Date: 2008-11-10 21:34:24 +0000 (Mon, 10 Nov 2008) Log Message: ----------- *) Rename AutoDetectType to AutoDetectPolicy *) Improve javadoc Modified Paths: -------------- trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoProperty.java trunk/Pojomatic/src/main/java/org/pojomatic/annotations/DefaultPojomaticPolicy.java trunk/Pojomatic/src/main/java/org/pojomatic/annotations/PojomaticPolicy.java trunk/Pojomatic/src/main/java/org/pojomatic/formatter/AccountNumberFormatter.java trunk/Pojomatic/src/main/java/org/pojomatic/formatter/DefaultPropertyFormatter.java trunk/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java trunk/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java Added Paths: ----------- trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectPolicy.java Removed Paths: ------------- trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectType.java Copied: trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectPolicy.java (from rev 69, trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectType.java) =================================================================== --- trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectPolicy.java (rev 0) +++ trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectPolicy.java 2008-11-10 21:34:24 UTC (rev 70) @@ -0,0 +1,25 @@ +package org.pojomatic.annotations; + +/** + * A policy for determining which class members are automatically detected as properties. This + * policy is set class-wide using {@link AutoProperty}. + */ +public enum AutoDetectPolicy { + /** + * Auto-detect fields of the class as properties + */ + FIELD, + + /** + * Auto-detect accessor methods of the class as properties using the JavaBean conventions + * (i.e. getX and isX). + */ + METHOD, + + /** + * Do not auto-detect properties for the class. This is be useful to specify + * a different {@link PojomaticPolicy} in {@link AutoProperty} without enabling + * property auto-detection. + */ + NONE; +} Property changes on: trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectPolicy.java ___________________________________________________________________ Added: svn:mergeinfo + Deleted: trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectType.java =================================================================== --- trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectType.java 2008-10-20 21:53:40 UTC (rev 69) +++ trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectType.java 2008-11-10 21:34:24 UTC (rev 70) @@ -1,20 +0,0 @@ -package org.pojomatic.annotations; - -public enum AutoDetectType { - /** - * Auto-detect fields of the class as properties - */ - FIELD, - - /** - * Auto-detect methods of the class as properties using the JavaBean conventions (i.e. getX). - */ - METHOD, - - /** - * Do not auto-detect properties for the class. This is be useful to specify - * a different {@link PojomaticPolicy} in {@link AutoProperty} without enabling - * property auto-detection. - */ - NONE; -} Modified: trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoProperty.java =================================================================== --- trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoProperty.java 2008-10-20 21:53:40 UTC (rev 69) +++ trunk/Pojomatic/src/main/java/org/pojomatic/annotations/AutoProperty.java 2008-11-10 21:34:24 UTC (rev 70) @@ -26,5 +26,5 @@ /** * Specifies whether to auto-detect properties by their fields, getters or not at all. */ - public AutoDetectType autoDetect() default AutoDetectType.FIELD; + public AutoDetectPolicy autoDetect() default AutoDetectPolicy.FIELD; } Modified: trunk/Pojomatic/src/main/java/org/pojomatic/annotations/DefaultPojomaticPolicy.java =================================================================== --- trunk/Pojomatic/src/main/java/org/pojomatic/annotations/DefaultPojomaticPolicy.java 2008-10-20 21:53:40 UTC (rev 69) +++ trunk/Pojomatic/src/main/java/org/pojomatic/annotations/DefaultPojomaticPolicy.java 2008-11-10 21:34:24 UTC (rev 70) @@ -8,13 +8,15 @@ import org.pojomatic.internal.PropertyRole; /** - * Defines which sets of {@link Pojomatic} operations that properties should be included. - * This are set class-wide using {@link AutoProperty} and for - * an individual property using {@link Property}. + * A policy for defining which sets of {@link Pojomatic} operations + * ({@code equals}, {@code hashCode} and {@code toString}) should use all properties by default. + * This is set class-wide using {@link AutoProperty}. + * @see PojomaticPolicy */ public enum DefaultPojomaticPolicy { /** + * Use all properties for both {@code hashCode} and {@code equals} by default. * Anything included in {@code public int hashCode()} should also be included in * {@code public boolean equals(Object)} to preserve the general * contract of {@link Object#hashCode()}. @@ -25,26 +27,27 @@ HASHCODE_EQUALS(PropertyRole.HASH_CODE, PropertyRole.EQUALS), /** - * {@code public boolean equals(Object)} + * Use all properties for {@code equals} only by default. * * @see Object#equals(Object) */ EQUALS(PropertyRole.EQUALS), /** - * {@code public String toString()} + * Use all properties for both {@code toString} only by default. * * @see Object#toString() */ TO_STRING(PropertyRole.TO_STRING), /** - * Shorthand for all of the above. + * Use all properties for {@code hashCode}, {@code equals} and {@code toString} by default. */ ALL(PropertyRole.EQUALS, PropertyRole.HASH_CODE, PropertyRole.TO_STRING), /** - * Shorthand for none of the above. + * Do not use any properties for any of {@code hashCode}, {@code equals} or {@code toString} + * by default. */ NONE(); Modified: trunk/Pojomatic/src/main/java/org/pojomatic/annotations/PojomaticPolicy.java =================================================================== --- trunk/Pojomatic/src/main/java/org/pojomatic/annotations/PojomaticPolicy.java 2008-10-20 21:53:40 UTC (rev 69) +++ trunk/Pojomatic/src/main/java/org/pojomatic/annotations/PojomaticPolicy.java 2008-11-10 21:34:24 UTC (rev 70) @@ -8,13 +8,15 @@ import org.pojomatic.internal.PropertyRole; /** - * Defines which sets of {@link Pojomatic} operations that properties should be included. - * This are set class-wide using {@link AutoProperty} and for - * an individual property using {@link Property}. + * A policy for defining which sets of {@link Pojomatic} operations + * ({@code equals}, {@code hashCode} and {@code toString}) should a property. + * This is set using {@link Property}. + * @see DefaultPojomaticPolicy */ public enum PojomaticPolicy { /** + * Use the property for both {@code hashCode} and {@code equals}. * Anything included in {@code public int hashCode()} should also be included in * {@code public boolean equals(Object)} to preserve the general * contract of {@link Object#hashCode()}. @@ -25,26 +27,26 @@ HASHCODE_EQUALS(PropertyRole.HASH_CODE, PropertyRole.EQUALS), /** - * {@code public boolean equals(Object)} + * Use the property for {@code equals} only. * * @see Object#equals(Object) */ EQUALS(PropertyRole.EQUALS), /** - * {@code public String toString()} + * Use the property for both {@code toString} only. * * @see Object#toString() */ TO_STRING(PropertyRole.TO_STRING), /** - * Shorthand for all of the above. + * Use the property for {@code hashCode}, {@code equals} and {@code toString}. */ ALL(PropertyRole.EQUALS, PropertyRole.HASH_CODE, PropertyRole.TO_STRING), /** - * Shorthand for none of the above. + * Do not use the property for any of {@code hashCode}, {@code equals} or {@code toString}. */ NONE(), Modified: trunk/Pojomatic/src/main/java/org/pojomatic/formatter/AccountNumberFormatter.java =================================================================== --- trunk/Pojomatic/src/main/java/org/pojomatic/formatter/AccountNumberFormatter.java 2008-10-20 21:53:40 UTC (rev 69) +++ trunk/Pojomatic/src/main/java/org/pojomatic/formatter/AccountNumberFormatter.java 2008-11-10 21:34:24 UTC (rev 70) @@ -6,9 +6,10 @@ import org.pojomatic.annotations.Property; /** - * Shows only the last 4 characters of a {@link Property}. Useful for credit card numbers, social - * security numbers, etc. This formatter cannot be used with properties of array types. - * <br><br> + * A property formatter which shows only the last 4 characters of the string representation of the + * {@link Property}, with all others replaced by an asterisk ('*'). + * Useful for credit card numbers, social security numbers, etc. + * <p> * For example, a 16 character {@code String} representing a credit card number would * be formatted as "************1234". */ Modified: trunk/Pojomatic/src/main/java/org/pojomatic/formatter/DefaultPropertyFormatter.java =================================================================== --- trunk/Pojomatic/src/main/java/org/pojomatic/formatter/DefaultPropertyFormatter.java 2008-10-20 21:53:40 UTC (rev 69) +++ trunk/Pojomatic/src/main/java/org/pojomatic/formatter/DefaultPropertyFormatter.java 2008-11-10 21:34:24 UTC (rev 70) @@ -3,6 +3,12 @@ import java.lang.reflect.AnnotatedElement; import java.util.Arrays; +/** + * The default property formatter used by Pojomatic. While the particulars of the formatting + * strategy are subject to change, the general principle is to provide a meaningful representation. + * In particular, arrays are formatted "deeply", rather than simply showing the default toString + * representation of Java arrays. + */ public class DefaultPropertyFormatter implements PropertyFormatter { public void initialize(AnnotatedElement element) { //Not applicable Modified: trunk/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java =================================================================== --- trunk/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java 2008-10-20 21:53:40 UTC (rev 69) +++ trunk/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java 2008-11-10 21:34:24 UTC (rev 70) @@ -9,7 +9,7 @@ import java.util.regex.Pattern; import org.pojomatic.PropertyElement; -import org.pojomatic.annotations.AutoDetectType; +import org.pojomatic.annotations.AutoDetectPolicy; import org.pojomatic.annotations.AutoProperty; import org.pojomatic.annotations.DefaultPojomaticPolicy; import org.pojomatic.annotations.PojomaticPolicy; @@ -42,7 +42,7 @@ /* add all fields that are explicitly annotated or auto-detected */ if (propertyPolicy != null || - (autoProperty != null && AutoDetectType.FIELD == autoProperty.autoDetect())) { + (autoProperty != null && AutoDetectPolicy.FIELD == autoProperty.autoDetect())) { for (PropertyRole role : PropertyFilter.getRoles(propertyPolicy, classPolicy)) { properties.get(role).add(new PropertyField(field)); } @@ -66,7 +66,7 @@ /* add all methods that are explicitly annotated or auto-detected */ if (propertyPolicy != null || - (autoProperty != null && AutoDetectType.METHOD == autoProperty.autoDetect())) { + (autoProperty != null && AutoDetectPolicy.METHOD == autoProperty.autoDetect())) { for (PropertyRole role : PropertyFilter.getRoles(propertyPolicy, classPolicy)) { properties.get(role).add(new PropertyAccessor(method)); } Modified: trunk/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java =================================================================== --- trunk/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2008-10-20 21:53:40 UTC (rev 69) +++ trunk/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2008-11-10 21:34:24 UTC (rev 70) @@ -10,7 +10,7 @@ import org.junit.Test; import org.pojomatic.PropertyElement; import org.pojomatic.TestUtils; -import org.pojomatic.annotations.AutoDetectType; +import org.pojomatic.annotations.AutoDetectPolicy; import org.pojomatic.annotations.AutoProperty; import org.pojomatic.annotations.DefaultPojomaticPolicy; import org.pojomatic.annotations.PojomaticPolicy; @@ -205,7 +205,7 @@ public double onlyForEquals() { return 0.0; } } - @AutoProperty(autoDetect=AutoDetectType.METHOD, policy=DefaultPojomaticPolicy.ALL) + @AutoProperty(autoDetect=AutoDetectPolicy.METHOD, policy=DefaultPojomaticPolicy.ALL) public static class AutoMethodPojo { /* Fields are not auto-detected */ int notDetected; @@ -254,7 +254,7 @@ @Override public int getFoo() { return 2; } } - @AutoProperty(autoDetect=AutoDetectType.METHOD) + @AutoProperty(autoDetect=AutoDetectPolicy.METHOD) private static class ChildExtendsAnnotatedPojo extends ParentPojo { @Override public int getFoo() { return 0; } @@ -262,12 +262,12 @@ public String getMyString() { return "foo"; } } - @AutoProperty(autoDetect=AutoDetectType.METHOD, policy=DefaultPojomaticPolicy.EQUALS) + @AutoProperty(autoDetect=AutoDetectPolicy.METHOD, policy=DefaultPojomaticPolicy.EQUALS) private static abstract class ParentAutoPojo { public abstract int getFoo(); } - @AutoProperty(autoDetect=AutoDetectType.FIELD, policy=DefaultPojomaticPolicy.TO_STRING) + @AutoProperty(autoDetect=AutoDetectPolicy.FIELD, policy=DefaultPojomaticPolicy.TO_STRING) private static class ChildAutoPojo extends ParentAutoPojo { public String other; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |