You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(12) |
Nov
(2) |
Dec
(15) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(7) |
Feb
(2) |
Mar
|
Apr
(22) |
May
|
Jun
|
Jul
(1) |
Aug
(29) |
Sep
(17) |
Oct
(4) |
Nov
|
Dec
(19) |
2010 |
Jan
|
Feb
(9) |
Mar
(2) |
Apr
(34) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(25) |
Nov
(22) |
Dec
(3) |
2014 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <iro...@us...> - 2009-09-25 22:48:48
|
Revision: 164 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=164&view=rev Author: iroberts Date: 2009-09-25 22:48:41 +0000 (Fri, 25 Sep 2009) Log Message: ----------- Houston, we have a problem. If an instance of a child class introducing no new properties is compared to a sibling which does introduce new properties, symmetry fails. Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java 2009-09-25 22:39:56 UTC (rev 163) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java 2009-09-25 22:48:41 UTC (rev 164) @@ -38,7 +38,9 @@ assertFalse(child.equals(PARENT)); assertFalse(PARENT_POJOMATOR.doEquals(PARENT, child)); assertFalse(childPojomator.doEquals(child, PARENT)); - // If we expicitely use a PARENT_POJOMATOR to compare child to parent, we'll miss the additional child property. + // If we expicitely use a PARENT_POJOMATOR to compare child to parent, we'll miss the additional + //child property. + //TODO - document this a as a danger of creating your own Pojomators. assertTrue(PARENT_POJOMATOR.doEquals(child, PARENT)); } @@ -52,4 +54,16 @@ assertTrue(PARENT_POJOMATOR.doEquals(child1, child2)); assertTrue(childPojomator.doEquals(child1, child2)); } + + @Test public void testTwoChildrenWithOneHavingNewProperties() { + class Child1 extends Parent { @SuppressWarnings("unused") @Property int y = 4; } + class Child2 extends Parent {} + Child1 child1 = new Child1(); + Child2 child2 = new Child2(); + Pojomator<Child1> child1Pojomator = new PojomatorImpl<Child1>(Child1.class); + Pojomator<Child2> child2Pojomator = new PojomatorImpl<Child2>(Child2.class); + + assertFalse(child1Pojomator.doEquals(child1, child2)); + assertFalse(child2Pojomator.doEquals(child2, child1)); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-25 22:40:04
|
Revision: 163 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=163&view=rev Author: iroberts Date: 2009-09-25 22:39:56 +0000 (Fri, 25 Sep 2009) Log Message: ----------- Better javadoc Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2009-09-25 22:17:23 UTC (rev 162) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2009-09-25 22:39:56 UTC (rev 163) @@ -26,6 +26,8 @@ final static int HASH_CODE_SEED = 1; final static int HASH_CODE_MULTIPLIER = 31; + //TODO: someplace in our docs, we need to describe how we walk the class hierarchy, and how we + //handle interfaces. /** * Creates an instance for {@code clazz}. @@ -68,27 +70,31 @@ /** * {@inheritDoc} * <p> - * In essance, two objects will be considered equal if they have the same set of properties with a - * {@link PropertyRole} of {@link PropertyRole#EQUALS EQUALS}, and for each property, the values are equal as - * described below. + * In essence, two objects will be considered equal if they have the same set of properties with a + * {@link PojomaticPolicy} other than {@link PojomaticPolicy#TO_STRING TO_STRING} or + * {@link PojomaticPolicy#NONE NONE}, and for each property, the values are equal as described + * below. Note that two properties cannot be considered the same if they come from different + * declaring classes. * <p> - * More precisely, if {@code other} is null, this method returns {@code false}. If {@code other} is a an instance of - * a proper subclass of the class of {@code instance}, then this method returns the result of calling - * {@code other.equals(instance)}. Otherwise, it is verified that the class of {@code other} either the same as or a - * subclass of the most specific class contributing a property with a {@code PropertyRole} of {@code EQUALS}; if not, - * then this method returns false. Otherwise, this method will return true provided that each property of - * {@code instance} which has a {@link PojomaticPolicy} other than {@link PojomaticPolicy#TO_STRING TO_STRING} or - * {@link PojomaticPolicy#NONE NONE} is equal to the corresponding property of {@code other} in the following sense: + * More precisely, if {@code other} is null, this method returns {@code false}. If {@code other} + * is a an instance of a proper subclass of the class of {@code instance}, then this method + * returns the result of calling {@code other.equals(instance)}. Otherwise, it is verified that + * the class of {@code other} either the same as or a subclass of the most specific class + * contributing a property with a {@code PojomaticPolicy} other than {@code TO_STRING} or + * {@code NONE}; if not, then this method + * returns false. Otherwise, this method will return true provided that each property of {@code + * instance} which has a {@code PojomaticPolicy} other than {@code TO_STRING} or + * {@code NONE} is equal to the corresponding property of {@code other} in the following sense: * <ul> - * <li>Both are {@code null}, or</li> - * <li>Both are reference-equals (==) to each other, or</li> - * <li>Both are primitive of the same type, and equal to each other, or</li> - * <li>Both are of array type, with matching primitive component types, and the corresponding - * {@code} equals method of {@link Arrays} returns true, or</li> - * <li>Both are of array type with non-primitive component types, and - * {@link Arrays#deepEquals(Object[], Object[])} returns true, or</li> - * <li>The property {@code p} in {@code instance} is an object not of array type, and - * {@code instanceP.equals(otherP)} returns true. + * <li>Both are {@code null}, or</li> + * <li>Both are reference-equals (==) to each other, or</li> + * <li>Both are primitive of the same type, and equal to each other, or</li> + * <li>Both are of array type, with matching primitive component types, and the corresponding + * {@code} equals method of {@link Arrays} returns true, or</li> + * <li>Both are of array type with non-primitive component types, and + * {@link Arrays#deepEquals(Object[], Object[])} returns true, or</li> + * <li>The property {@code p} in {@code instance} is an object not of array type, and {@code + * instanceP.equals(otherP)} returns true. * </ul> * * @throws NullPointerException if {@code instance} is null This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-25 22:17:31
|
Revision: 162 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=162&view=rev Author: iroberts Date: 2009-09-25 22:17:23 +0000 (Fri, 25 Sep 2009) Log Message: ----------- strip off carriage returns Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/PropertyElement.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/AutoProperty.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/DefaultPojomaticPolicy.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PojoFormat.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PojomaticPolicy.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/Property.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PropertyFormat.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/AbstractPropertyElement.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PropertyAccessor.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PropertyField.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,158 +1,158 @@ -package org.pojomatic; - -import org.pojomatic.diff.DifferenceFromNull; -import org.pojomatic.diff.Differences; -import org.pojomatic.diff.NoDifferences; -import org.pojomatic.internal.PojomatorImpl; -import org.pojomatic.internal.SelfPopulatingMap; - -/** - * Static methods for implementing the {@link java.lang.Object#equals(Object)}, - * {@link java.lang.Object#hashCode()} and {@link java.lang.Object#toString()} methods on a - * annotated POJO. The actual work for a given class is done by a {@link Pojomator} created for - * that class. This class is careful to create only a single {@code Pojomator} per POJO class. - * The overhead for looking up the {@code Pojomator} by POJO class is light, so a typical use in a - * POJO class would be - * <p style="background-color:#EEEEFF; margin: 1em"> - * <code> - * <font color="#646464">@Override</font> <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>int </b></font><font color="#000000">hashCode() {</font><br> - * <font color="#7f0055"><b>return </b></font><font color="#000000">Pojomatic.hashCode(</font><font color="#7f0055"><b>this</b></font><font color="#000000">);</font><br /> - * <font color="#000000">}</font><br> - * <br/> - * <font color="#646464">@Override</font> <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>boolean </b></font><font color="#000000">equals(Object other) {</font><br> - * <font color="#7f0055"><b>return </b></font><font color="#000000">Pojomatic.equals(</font><font color="#7f0055"><b>this</b></font><font color="#000000">, other);</font><br /> - * <font color="#000000">}</font><br> - * <br/> - * <font color="#646464">@Override</font> <font color="#7f0055"><b>public </b></font><font color="#000000">String toString() {</font><br> - * <font color="#7f0055"><b>return </b></font><font color="#000000">Pojomatic.toString(</font><font color="#7f0055"><b>this</b></font><font color="#000000">);</font><br /> - * <font color="#000000">}</font><br> - * <br/> - * </code> - * </p> - * Under the covers, these methods are referencing a {@link org.pojomatic.Pojomator Pojomator} instance - * which is created lazily and cached on a per-class basis. The performance penalty for this is - * negligible, but if profiling suggests that it is a bottleneck, one can do this by hand: - * <p style="background-color:#EEEEFF; margin: 1em"> - * <code> - * <font color="#ffffff"> </font><font color="#7f0055"><b>private final static </b></font><font color="#000000">Pojomator<Manual> POJOMATOR = Pojomatic.pojomator</font><font color="#000000">(</font><font color="#000000">Manual.</font><font color="#7f0055"><b>class</b></font><font color="#000000">)</font><font color="#000000">;</font><br /> - * <font color="#ffffff"></font><br /> - * <font color="#ffffff"> </font><font color="#646464">@Override </font><font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>boolean </b></font><font color="#000000">equals</font><font color="#000000">(</font><font color="#000000">Object other</font><font color="#000000">) {</font><br /> - * <font color="#ffffff"> </font><font color="#7f0055"><b>return </b></font><font color="#000000">POJOMATOR.doEquals</font><font color="#000000">(</font><font color="#000000">this, other</font><font color="#000000">)</font><font color="#000000">;</font><br /> - * <font color="#ffffff"> </font><font color="#000000">}</font><br /> - * <font color="#ffffff"></font><br /> - * <font color="#ffffff"> </font><font color="#646464">@Override </font><font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>int </b></font><font color="#000000">hashCode</font><font color="#000000">() {</font><br /> - * <font color="#ffffff"> </font><font color="#7f0055"><b>return </b></font><font color="#000000">POJOMATOR.doHashCode</font><font color="#000000">(</font><font color="#7f0055"><b>this</b></font><font color="#000000">)</font><font color="#000000">;</font><br /> - * <font color="#ffffff"> </font><font color="#000000">}</font><br /> - * <font color="#ffffff"></font><br /> - * <font color="#ffffff"> </font><font color="#646464">@Override </font><font color="#7f0055"><b>public </b></font><font color="#000000">String toString</font><font color="#000000">() {</font><br /> - * <font color="#ffffff"> </font><font color="#7f0055"><b>return </b></font><font color="#000000">POJOMATOR.doToString</font><font color="#000000">(</font><font color="#7f0055"><b>this</b></font><font color="#000000">)</font><font color="#000000">;</font><br /> - * <font color="#ffffff"> </font><font color="#000000">}</font> - * </code> - * </p> - * - * @see Pojomator - */ -public class Pojomatic { - - private static SelfPopulatingMap<Class<?>, Pojomator<?>> POJOMATORS = - new SelfPopulatingMap<Class<?>, Pojomator<?>>() { - @Override - @SuppressWarnings("unchecked") - // compiler does not know that the type parameter to Pojomator is the same as the type - // parameter to Class - protected Pojomator<?> create(Class<?> key) { - return new PojomatorImpl(key); - } - }; - - private Pojomatic() {} - - /** - * Compute the {@code toString} representation for a POJO. - * @param <T> the type of the POJO - * @param pojo the POJO - must not be null - * @return the {@code toString} representation of {@code pojo}. - * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use - * with Pojomatic - * @see Pojomator#doToString(Object) - */ - public static <T> String toString(T pojo) throws IllegalArgumentException { - return pojomator(getClass(pojo)).doToString(pojo); - } - - /** - * Compute the {@code hashCode} for a POJO. - * @param <T> the type of the POJO - * @param pojo the POJO - must not be null - * @return the {@code hashCode} for {@code pojo}. - * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use - * with Pojomatic - * @see Pojomator#doHashCode(Object) - */ - public static <T> int hashCode(T pojo) throws IllegalArgumentException { - return pojomator(getClass(pojo)).doHashCode(pojo); - } - - /** - * Compute whether {@code pojo} and {@code other} are equal to each other in the sense of - * {@code Object}'s {@code equals} method. - * @param <T> the type of the POJO - * @param pojo the POJO - must not be null - * @param other the object to compare to for equality - * @return whether {@code pojo} and {@code other} are equal to each other in the sense of - * {@code Object}'s {@code equals} method. - * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use - * with Pojomatic - * @see Pojomator#doEquals(Object, Object) - */ - public static <T> boolean equals(T pojo, Object other) throws IllegalArgumentException { - return pojomator(getClass(pojo)).doEquals(pojo, other); - } - - - /** - * Compute the differences between {@code pojo} and {@code other} among the properties - * examined by {@link #equals(Object, Object)} for type {@code T}. - * - * @param <T> the static type of the first object to compare - * @param <S> the static type of the first object to compare - * @param pojo the instance to diff against - * @param other the instance to diff - * @return the list of differences (possibly empty) between {@code instance} and {@code other} - * among the properties examined by {@link #equals(Object, Object)} for type {@code T}. - * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use - * with Pojomatic - */ - public static <T, S extends T> Differences diff(T pojo, S other) - throws NullPointerException, IllegalArgumentException { - if (pojo == null) { - if (other != null) { - return new DifferenceFromNull(other); - } - else { //both null - return NoDifferences.getInstance(); - } - } - - return pojomator(getClass(pojo)).doDiff(pojo, other); - } - - /** - * Get the {@code Pojomator} for {@code pojoClass}. The same instance will be returned every time - * for a given value of {@code pojoClass}. - * @param <T> the type represented by {@code pojoClass} - * @param pojoClass the class to create a {@code Pojomator} for. - * @return a {@code Pojomator<T>} - * @throws IllegalArgumentException if {@code pojoClass} has no properties annotated for use - * with Pojomatic - */ - @SuppressWarnings("unchecked") // compiler does not know that the type parameter to Pojomator is T - public static <T> Pojomator<T> pojomator(Class<T> pojoClass) throws IllegalArgumentException { - return (Pojomator<T>) POJOMATORS.get(pojoClass); - } - - @SuppressWarnings("unchecked") // Since Object.getClass returns Class<?> - private static <T> Class<T> getClass(T pojo) { - return (Class<T>) pojo.getClass(); - } -} +package org.pojomatic; + +import org.pojomatic.diff.DifferenceFromNull; +import org.pojomatic.diff.Differences; +import org.pojomatic.diff.NoDifferences; +import org.pojomatic.internal.PojomatorImpl; +import org.pojomatic.internal.SelfPopulatingMap; + +/** + * Static methods for implementing the {@link java.lang.Object#equals(Object)}, + * {@link java.lang.Object#hashCode()} and {@link java.lang.Object#toString()} methods on a + * annotated POJO. The actual work for a given class is done by a {@link Pojomator} created for + * that class. This class is careful to create only a single {@code Pojomator} per POJO class. + * The overhead for looking up the {@code Pojomator} by POJO class is light, so a typical use in a + * POJO class would be + * <p style="background-color:#EEEEFF; margin: 1em"> + * <code> + * <font color="#646464">@Override</font> <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>int </b></font><font color="#000000">hashCode() {</font><br> + * <font color="#7f0055"><b>return </b></font><font color="#000000">Pojomatic.hashCode(</font><font color="#7f0055"><b>this</b></font><font color="#000000">);</font><br /> + * <font color="#000000">}</font><br> + * <br/> + * <font color="#646464">@Override</font> <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>boolean </b></font><font color="#000000">equals(Object other) {</font><br> + * <font color="#7f0055"><b>return </b></font><font color="#000000">Pojomatic.equals(</font><font color="#7f0055"><b>this</b></font><font color="#000000">, other);</font><br /> + * <font color="#000000">}</font><br> + * <br/> + * <font color="#646464">@Override</font> <font color="#7f0055"><b>public </b></font><font color="#000000">String toString() {</font><br> + * <font color="#7f0055"><b>return </b></font><font color="#000000">Pojomatic.toString(</font><font color="#7f0055"><b>this</b></font><font color="#000000">);</font><br /> + * <font color="#000000">}</font><br> + * <br/> + * </code> + * </p> + * Under the covers, these methods are referencing a {@link org.pojomatic.Pojomator Pojomator} instance + * which is created lazily and cached on a per-class basis. The performance penalty for this is + * negligible, but if profiling suggests that it is a bottleneck, one can do this by hand: + * <p style="background-color:#EEEEFF; margin: 1em"> + * <code> + * <font color="#ffffff"> </font><font color="#7f0055"><b>private final static </b></font><font color="#000000">Pojomator<Manual> POJOMATOR = Pojomatic.pojomator</font><font color="#000000">(</font><font color="#000000">Manual.</font><font color="#7f0055"><b>class</b></font><font color="#000000">)</font><font color="#000000">;</font><br /> + * <font color="#ffffff"></font><br /> + * <font color="#ffffff"> </font><font color="#646464">@Override </font><font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>boolean </b></font><font color="#000000">equals</font><font color="#000000">(</font><font color="#000000">Object other</font><font color="#000000">) {</font><br /> + * <font color="#ffffff"> </font><font color="#7f0055"><b>return </b></font><font color="#000000">POJOMATOR.doEquals</font><font color="#000000">(</font><font color="#000000">this, other</font><font color="#000000">)</font><font color="#000000">;</font><br /> + * <font color="#ffffff"> </font><font color="#000000">}</font><br /> + * <font color="#ffffff"></font><br /> + * <font color="#ffffff"> </font><font color="#646464">@Override </font><font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>int </b></font><font color="#000000">hashCode</font><font color="#000000">() {</font><br /> + * <font color="#ffffff"> </font><font color="#7f0055"><b>return </b></font><font color="#000000">POJOMATOR.doHashCode</font><font color="#000000">(</font><font color="#7f0055"><b>this</b></font><font color="#000000">)</font><font color="#000000">;</font><br /> + * <font color="#ffffff"> </font><font color="#000000">}</font><br /> + * <font color="#ffffff"></font><br /> + * <font color="#ffffff"> </font><font color="#646464">@Override </font><font color="#7f0055"><b>public </b></font><font color="#000000">String toString</font><font color="#000000">() {</font><br /> + * <font color="#ffffff"> </font><font color="#7f0055"><b>return </b></font><font color="#000000">POJOMATOR.doToString</font><font color="#000000">(</font><font color="#7f0055"><b>this</b></font><font color="#000000">)</font><font color="#000000">;</font><br /> + * <font color="#ffffff"> </font><font color="#000000">}</font> + * </code> + * </p> + * + * @see Pojomator + */ +public class Pojomatic { + + private static SelfPopulatingMap<Class<?>, Pojomator<?>> POJOMATORS = + new SelfPopulatingMap<Class<?>, Pojomator<?>>() { + @Override + @SuppressWarnings("unchecked") + // compiler does not know that the type parameter to Pojomator is the same as the type + // parameter to Class + protected Pojomator<?> create(Class<?> key) { + return new PojomatorImpl(key); + } + }; + + private Pojomatic() {} + + /** + * Compute the {@code toString} representation for a POJO. + * @param <T> the type of the POJO + * @param pojo the POJO - must not be null + * @return the {@code toString} representation of {@code pojo}. + * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use + * with Pojomatic + * @see Pojomator#doToString(Object) + */ + public static <T> String toString(T pojo) throws IllegalArgumentException { + return pojomator(getClass(pojo)).doToString(pojo); + } + + /** + * Compute the {@code hashCode} for a POJO. + * @param <T> the type of the POJO + * @param pojo the POJO - must not be null + * @return the {@code hashCode} for {@code pojo}. + * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use + * with Pojomatic + * @see Pojomator#doHashCode(Object) + */ + public static <T> int hashCode(T pojo) throws IllegalArgumentException { + return pojomator(getClass(pojo)).doHashCode(pojo); + } + + /** + * Compute whether {@code pojo} and {@code other} are equal to each other in the sense of + * {@code Object}'s {@code equals} method. + * @param <T> the type of the POJO + * @param pojo the POJO - must not be null + * @param other the object to compare to for equality + * @return whether {@code pojo} and {@code other} are equal to each other in the sense of + * {@code Object}'s {@code equals} method. + * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use + * with Pojomatic + * @see Pojomator#doEquals(Object, Object) + */ + public static <T> boolean equals(T pojo, Object other) throws IllegalArgumentException { + return pojomator(getClass(pojo)).doEquals(pojo, other); + } + + + /** + * Compute the differences between {@code pojo} and {@code other} among the properties + * examined by {@link #equals(Object, Object)} for type {@code T}. + * + * @param <T> the static type of the first object to compare + * @param <S> the static type of the first object to compare + * @param pojo the instance to diff against + * @param other the instance to diff + * @return the list of differences (possibly empty) between {@code instance} and {@code other} + * among the properties examined by {@link #equals(Object, Object)} for type {@code T}. + * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use + * with Pojomatic + */ + public static <T, S extends T> Differences diff(T pojo, S other) + throws NullPointerException, IllegalArgumentException { + if (pojo == null) { + if (other != null) { + return new DifferenceFromNull(other); + } + else { //both null + return NoDifferences.getInstance(); + } + } + + return pojomator(getClass(pojo)).doDiff(pojo, other); + } + + /** + * Get the {@code Pojomator} for {@code pojoClass}. The same instance will be returned every time + * for a given value of {@code pojoClass}. + * @param <T> the type represented by {@code pojoClass} + * @param pojoClass the class to create a {@code Pojomator} for. + * @return a {@code Pojomator<T>} + * @throws IllegalArgumentException if {@code pojoClass} has no properties annotated for use + * with Pojomatic + */ + @SuppressWarnings("unchecked") // compiler does not know that the type parameter to Pojomator is T + public static <T> Pojomator<T> pojomator(Class<T> pojoClass) throws IllegalArgumentException { + return (Pojomator<T>) POJOMATORS.get(pojoClass); + } + + @SuppressWarnings("unchecked") // Since Object.getClass returns Class<?> + private static <T> Class<T> getClass(T pojo) { + return (Class<T>) pojo.getClass(); + } +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/PropertyElement.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/PropertyElement.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/PropertyElement.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,37 +1,37 @@ -package org.pojomatic; - -import java.lang.reflect.AnnotatedElement; - -/** - * A "property" on a class. In this context, all a property is is a means of obtaining a value from - * an instance. - */ -public interface PropertyElement { - - /** - * Get the name of this property. - * @return the name of this property. - */ - String getName(); - - /** - * Get the value held by this property from the given instance. - * - * @param instance the instance to get the value from - * @return the value held by the instance - */ - Object getValue(Object instance); - - /** - * Get the original annotated element that this property is derived from. - * @return the original annotated element that this property is derived from. - */ - AnnotatedElement getElement(); - - /** - * Get the class object representing the class or interface declaring this property. - * @return the declaring class or interface of this property. - */ - Class<?> getDeclaringClass(); - -} +package org.pojomatic; + +import java.lang.reflect.AnnotatedElement; + +/** + * A "property" on a class. In this context, all a property is is a means of obtaining a value from + * an instance. + */ +public interface PropertyElement { + + /** + * Get the name of this property. + * @return the name of this property. + */ + String getName(); + + /** + * Get the value held by this property from the given instance. + * + * @param instance the instance to get the value from + * @return the value held by the instance + */ + Object getValue(Object instance); + + /** + * Get the original annotated element that this property is derived from. + * @return the original annotated element that this property is derived from. + */ + AnnotatedElement getElement(); + + /** + * Get the class object representing the class or interface declaring this property. + * @return the declaring class or interface of this property. + */ + Class<?> getDeclaringClass(); + +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/AutoProperty.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/AutoProperty.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/AutoProperty.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,30 +1,30 @@ -package org.pojomatic.annotations; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import org.pojomatic.Pojomatic; - -/** - * Assigns the defaults for {@link Pojomatic} at the class level and provides a way to - * configure the automatic detection of properties. - * Note that this can is overridden (case by case) by the {@link Property}} annotation. - */ -@Target(TYPE) -@Retention(RUNTIME) -@Documented -public @interface AutoProperty { - /** - * Include properties in everything by default (unless otherwise stated by {@link Property}). - */ - public DefaultPojomaticPolicy policy() default DefaultPojomaticPolicy.ALL; - - /** - * Specifies whether to auto-detect properties by their fields, getters or not at all. - */ - public AutoDetectPolicy autoDetect() default AutoDetectPolicy.FIELD; -} +package org.pojomatic.annotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.pojomatic.Pojomatic; + +/** + * Assigns the defaults for {@link Pojomatic} at the class level and provides a way to + * configure the automatic detection of properties. + * Note that this can is overridden (case by case) by the {@link Property}} annotation. + */ +@Target(TYPE) +@Retention(RUNTIME) +@Documented +public @interface AutoProperty { + /** + * Include properties in everything by default (unless otherwise stated by {@link Property}). + */ + public DefaultPojomaticPolicy policy() default DefaultPojomaticPolicy.ALL; + + /** + * Specifies whether to auto-detect properties by their fields, getters or not at all. + */ + public AutoDetectPolicy autoDetect() default AutoDetectPolicy.FIELD; +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/DefaultPojomaticPolicy.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/DefaultPojomaticPolicy.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/DefaultPojomaticPolicy.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,78 +1,78 @@ -package org.pojomatic.annotations; - -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; - -import org.pojomatic.Pojomatic; -import org.pojomatic.internal.PropertyRole; - -/** - * 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()}. - * - * @see Object#hashCode() - * @see Object#equals(Object) - */ - HASHCODE_EQUALS(PropertyRole.HASH_CODE, PropertyRole.EQUALS), - - /** - * Use all properties for {@code equals} only by default. - * - * @see Object#equals(Object) - */ - EQUALS(PropertyRole.EQUALS), - - /** - * Use all properties for both {@code equals} and {@code toString} by default. - * - * @see Object#equals(Object) - * @see Object#toString() - */ - EQUALS_TO_STRING(PropertyRole.EQUALS, PropertyRole.TO_STRING), - - /** - * Use all properties for both {@code toString} only by default. - * - * @see Object#toString() - */ - TO_STRING(PropertyRole.TO_STRING), - - /** - * Use all properties for {@code hashCode}, {@code equals} and {@code toString} by default. - */ - ALL(PropertyRole.EQUALS, PropertyRole.HASH_CODE, PropertyRole.TO_STRING), - - /** - * Do not use any properties for any of {@code hashCode}, {@code equals} or {@code toString} - * by default. - */ - NONE(); - - /** - * @return the roles this specified by this policy. - */ - public Set<PropertyRole> getRoles() { - return roles; - } - - private DefaultPojomaticPolicy(PropertyRole... roles) { - Set<PropertyRole> roleSet = EnumSet.noneOf(PropertyRole.class); - for (PropertyRole role: roles) { - roleSet.add(role); - } - this.roles = Collections.unmodifiableSet(roleSet); - } - - private final Set<PropertyRole> roles; -} +package org.pojomatic.annotations; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.Set; + +import org.pojomatic.Pojomatic; +import org.pojomatic.internal.PropertyRole; + +/** + * 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()}. + * + * @see Object#hashCode() + * @see Object#equals(Object) + */ + HASHCODE_EQUALS(PropertyRole.HASH_CODE, PropertyRole.EQUALS), + + /** + * Use all properties for {@code equals} only by default. + * + * @see Object#equals(Object) + */ + EQUALS(PropertyRole.EQUALS), + + /** + * Use all properties for both {@code equals} and {@code toString} by default. + * + * @see Object#equals(Object) + * @see Object#toString() + */ + EQUALS_TO_STRING(PropertyRole.EQUALS, PropertyRole.TO_STRING), + + /** + * Use all properties for both {@code toString} only by default. + * + * @see Object#toString() + */ + TO_STRING(PropertyRole.TO_STRING), + + /** + * Use all properties for {@code hashCode}, {@code equals} and {@code toString} by default. + */ + ALL(PropertyRole.EQUALS, PropertyRole.HASH_CODE, PropertyRole.TO_STRING), + + /** + * Do not use any properties for any of {@code hashCode}, {@code equals} or {@code toString} + * by default. + */ + NONE(); + + /** + * @return the roles this specified by this policy. + */ + public Set<PropertyRole> getRoles() { + return roles; + } + + private DefaultPojomaticPolicy(PropertyRole... roles) { + Set<PropertyRole> roleSet = EnumSet.noneOf(PropertyRole.class); + for (PropertyRole role: roles) { + roleSet.add(role); + } + this.roles = Collections.unmodifiableSet(roleSet); + } + + private final Set<PropertyRole> roles; +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PojoFormat.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PojoFormat.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PojoFormat.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,25 +1,25 @@ -package org.pojomatic.annotations; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import org.pojomatic.formatter.PojoFormatter; - -/** - * Specifies formatting information to be used for creating {@code String} representations of POJOs. - * @see PojoFormatter - */ -@Target(TYPE) -@Retention(RUNTIME) -@Documented -public @interface PojoFormat { - - /** - * The formatter to use for creating a {@code String} representation. - */ - public Class<? extends PojoFormatter> value(); -} +package org.pojomatic.annotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.pojomatic.formatter.PojoFormatter; + +/** + * Specifies formatting information to be used for creating {@code String} representations of POJOs. + * @see PojoFormatter + */ +@Target(TYPE) +@Retention(RUNTIME) +@Documented +public @interface PojoFormat { + + /** + * The formatter to use for creating a {@code String} representation. + */ + public Class<? extends PojoFormatter> value(); +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PojomaticPolicy.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PojomaticPolicy.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PojomaticPolicy.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,89 +1,89 @@ -package org.pojomatic.annotations; - -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; - -import org.pojomatic.Pojomatic; -import org.pojomatic.internal.PropertyRole; - -/** - * A policy for defining which sets of {@link Pojomatic} operations - * ({@code equals}, {@code hashCode} and {@code toString}) should use 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()}. - * - * @see Object#hashCode() - * @see Object#equals(Object) - */ - HASHCODE_EQUALS(PropertyRole.HASH_CODE, PropertyRole.EQUALS), - - /** - * Use the property for both {@code equals} and {@code toString}. - * - * @see Object#equals(Object) - * @see Object#toString() - */ - EQUALS_TO_STRING(PropertyRole.EQUALS, PropertyRole.TO_STRING), - - - /** - * Use the property for {@code equals} only. - * - * @see Object#equals(Object) - */ - EQUALS(PropertyRole.EQUALS), - - /** - * Use the property for both {@code toString} only. - * - * @see Object#toString() - */ - TO_STRING(PropertyRole.TO_STRING), - - /** - * Use the property for {@code hashCode}, {@code equals} and {@code toString}. - */ - ALL(PropertyRole.EQUALS, PropertyRole.HASH_CODE, PropertyRole.TO_STRING), - - /** - * Do not use the property for any of {@code hashCode}, {@code equals} or {@code toString}. - */ - NONE(), - - /** - * Use the default policy specified via the {@code @AutoProperty} annotation, or - * {@code ALL} if none was specified. - */ - DEFAULT { - @Override public Set<PropertyRole> getRoles() { - return null; - } - }; - - - /** - * @return the roles this specified by this policy. Will be {@code null} for {@code DEFAULT}. - */ - public Set<PropertyRole> getRoles() { - return roles; - } - - private PojomaticPolicy(PropertyRole... roles) { - Set<PropertyRole> roleSet = EnumSet.noneOf(PropertyRole.class); - for (PropertyRole role: roles) { - roleSet.add(role); - } - this.roles = Collections.unmodifiableSet(roleSet); - } - - private final Set<PropertyRole> roles; -} +package org.pojomatic.annotations; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.Set; + +import org.pojomatic.Pojomatic; +import org.pojomatic.internal.PropertyRole; + +/** + * A policy for defining which sets of {@link Pojomatic} operations + * ({@code equals}, {@code hashCode} and {@code toString}) should use 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()}. + * + * @see Object#hashCode() + * @see Object#equals(Object) + */ + HASHCODE_EQUALS(PropertyRole.HASH_CODE, PropertyRole.EQUALS), + + /** + * Use the property for both {@code equals} and {@code toString}. + * + * @see Object#equals(Object) + * @see Object#toString() + */ + EQUALS_TO_STRING(PropertyRole.EQUALS, PropertyRole.TO_STRING), + + + /** + * Use the property for {@code equals} only. + * + * @see Object#equals(Object) + */ + EQUALS(PropertyRole.EQUALS), + + /** + * Use the property for both {@code toString} only. + * + * @see Object#toString() + */ + TO_STRING(PropertyRole.TO_STRING), + + /** + * Use the property for {@code hashCode}, {@code equals} and {@code toString}. + */ + ALL(PropertyRole.EQUALS, PropertyRole.HASH_CODE, PropertyRole.TO_STRING), + + /** + * Do not use the property for any of {@code hashCode}, {@code equals} or {@code toString}. + */ + NONE(), + + /** + * Use the default policy specified via the {@code @AutoProperty} annotation, or + * {@code ALL} if none was specified. + */ + DEFAULT { + @Override public Set<PropertyRole> getRoles() { + return null; + } + }; + + + /** + * @return the roles this specified by this policy. Will be {@code null} for {@code DEFAULT}. + */ + public Set<PropertyRole> getRoles() { + return roles; + } + + private PojomaticPolicy(PropertyRole... roles) { + Set<PropertyRole> roleSet = EnumSet.noneOf(PropertyRole.class); + for (PropertyRole role: roles) { + roleSet.add(role); + } + this.roles = Collections.unmodifiableSet(roleSet); + } + + private final Set<PropertyRole> roles; +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/Property.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/Property.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/Property.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,38 +1,38 @@ -package org.pojomatic.annotations; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import org.pojomatic.Pojomatic; - -/** - * Marks a property of a class to be used by {@link Pojomatic} - * @see PojomaticPolicy - */ -@Target({FIELD, METHOD}) -@Retention(RUNTIME) -@Documented -public @interface Property { - - /** - * Which sets of {@link Pojomatic} operations ({@code equals}, {@code hashCode} and - * {@code toString}) should use a property. - */ - public PojomaticPolicy policy() default PojomaticPolicy.DEFAULT; - - /** - * The name used to identify the property in the standard {@code toString} representation. If - * empty, the following algorithm is used to determine the name. For a propertiy referenced by - * field, the name of the field is used. For a property referenced by a method whose name is of - * the form {@code getSomeField}, the name {@code someField} will be used. For a boolean property - * referenced by a method whose name is of the form {@code isSomeField}, the name - * {@code someField} will be used. For any other property referenced by a method, the name of - * the method is used. - */ - public String name() default ""; -} +package org.pojomatic.annotations; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.pojomatic.Pojomatic; + +/** + * Marks a property of a class to be used by {@link Pojomatic} + * @see PojomaticPolicy + */ +@Target({FIELD, METHOD}) +@Retention(RUNTIME) +@Documented +public @interface Property { + + /** + * Which sets of {@link Pojomatic} operations ({@code equals}, {@code hashCode} and + * {@code toString}) should use a property. + */ + public PojomaticPolicy policy() default PojomaticPolicy.DEFAULT; + + /** + * The name used to identify the property in the standard {@code toString} representation. If + * empty, the following algorithm is used to determine the name. For a propertiy referenced by + * field, the name of the field is used. For a property referenced by a method whose name is of + * the form {@code getSomeField}, the name {@code someField} will be used. For a boolean property + * referenced by a method whose name is of the form {@code isSomeField}, the name + * {@code someField} will be used. For any other property referenced by a method, the name of + * the method is used. + */ + public String name() default ""; +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PropertyFormat.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PropertyFormat.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/PropertyFormat.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,29 +1,29 @@ -package org.pojomatic.annotations; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import org.pojomatic.formatter.PropertyFormatter; - -/** - * Specifies formatting information to be used for creating {@code String} representations of - * properties. Note that using a {@code PropertyFormat} annotation on a property does not influence - * whether that property will be included in the {@code toString} implementation. That is - * determined solely by any {@link Property} and {@link AutoProperty} annotations on the POJO. - * @see PropertyFormatter - */ -@Target({FIELD, METHOD}) -@Retention(RUNTIME) -@Documented -public @interface PropertyFormat { - - /** - * The formatter to use for creating a {@code String} representation. - */ - public Class<? extends PropertyFormatter> value(); -} +package org.pojomatic.annotations; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.pojomatic.formatter.PropertyFormatter; + +/** + * Specifies formatting information to be used for creating {@code String} representations of + * properties. Note that using a {@code PropertyFormat} annotation on a property does not influence + * whether that property will be included in the {@code toString} implementation. That is + * determined solely by any {@link Property} and {@link AutoProperty} annotations on the POJO. + * @see PropertyFormatter + */ +@Target({FIELD, METHOD}) +@Retention(RUNTIME) +@Documented +public @interface PropertyFormat { + + /** + * The formatter to use for creating a {@code String} representation. + */ + public Class<? extends PropertyFormatter> value(); +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/AbstractPropertyElement.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/AbstractPropertyElement.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/AbstractPropertyElement.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,79 +1,79 @@ -package org.pojomatic.internal; - -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Member; - -import org.pojomatic.PropertyElement; - -public abstract class AbstractPropertyElement<E extends AccessibleObject & Member> -implements PropertyElement { - protected final E element; - private final String name; - - protected AbstractPropertyElement(E element, String name) { - element.setAccessible(true); - this.element = element; - this.name = name; - } - - public String getName() { - return name; - } - - public Object getValue(Object instance) { - if (instance == null) { - throw new NullPointerException("Instance is null: cannot get property value"); - } - else { - try { - return accessValue(instance); - } - catch (IllegalArgumentException e) { - throw new RuntimeException(e); - } - catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - } - - protected abstract Object accessValue(Object instance) - throws IllegalAccessException, IllegalArgumentException; - - /* (non-Javadoc) - * @see org.pojomatic.PropertyElement#getElement() - */ - public AnnotatedElement getElement() { - return this.element; - } - - public Class<?> getDeclaringClass() { - return element.getDeclaringClass(); - } - - @Override - public int hashCode() { - return element.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final AbstractPropertyElement<?> other = (AbstractPropertyElement<?>) obj; - return element.equals(other.element); - } - - @Override - public String toString() { - return element.toString(); - } -} +package org.pojomatic.internal; + +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Member; + +import org.pojomatic.PropertyElement; + +public abstract class AbstractPropertyElement<E extends AccessibleObject & Member> +implements PropertyElement { + protected final E element; + private final String name; + + protected AbstractPropertyElement(E element, String name) { + element.setAccessible(true); + this.element = element; + this.name = name; + } + + public String getName() { + return name; + } + + public Object getValue(Object instance) { + if (instance == null) { + throw new NullPointerException("Instance is null: cannot get property value"); + } + else { + try { + return accessValue(instance); + } + catch (IllegalArgumentException e) { + throw new RuntimeException(e); + } + catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + protected abstract Object accessValue(Object instance) + throws IllegalAccessException, IllegalArgumentException; + + /* (non-Javadoc) + * @see org.pojomatic.PropertyElement#getElement() + */ + public AnnotatedElement getElement() { + return this.element; + } + + public Class<?> getDeclaringClass() { + return element.getDeclaringClass(); + } + + @Override + public int hashCode() { + return element.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final AbstractPropertyElement<?> other = (AbstractPropertyElement<?>) obj; + return element.equals(other.element); + } + + @Override + public String toString() { + return element.toString(); + } +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PropertyAccessor.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PropertyAccessor.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PropertyAccessor.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,47 +1,47 @@ -package org.pojomatic.internal; - -import java.beans.Introspector; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -public class PropertyAccessor extends AbstractPropertyElement<Method> { - private final static String GET = "get", IS = "is"; - - public PropertyAccessor(Method method, String name) { - super(method, name.length() == 0 ? getName(method) : name); - } - - private static String getName(Method method) { - String methodName = method.getName(); - if (isPrefixedWith(methodName, GET)) { - return Introspector.decapitalize(methodName.substring(GET.length())); - } - else if (isBoolean(method.getReturnType()) && isPrefixedWith(methodName, IS)) { - return Introspector.decapitalize(methodName.substring(IS.length())); - } - else { - return methodName; - } - } - - private static boolean isBoolean(Class<?> clazz) { - return Boolean.class.equals(clazz) || Boolean.TYPE.equals(clazz); - } - - private static boolean isPrefixedWith(String name, String prefix) { - return name.length() > prefix.length() - && name.startsWith(prefix) - && Character.isUpperCase(name.charAt(prefix.length())); - } - - @Override - protected Object accessValue(Object instance) - throws IllegalArgumentException, IllegalAccessException { - try { - return element.invoke(instance, (Object[])null); - } - catch (InvocationTargetException e) { - throw new RuntimeException(e.getCause()); - } - } -} +package org.pojomatic.internal; + +import java.beans.Introspector; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class PropertyAccessor extends AbstractPropertyElement<Method> { + private final static String GET = "get", IS = "is"; + + public PropertyAccessor(Method method, String name) { + super(method, name.length() == 0 ? getName(method) : name); + } + + private static String getName(Method method) { + String methodName = method.getName(); + if (isPrefixedWith(methodName, GET)) { + return Introspector.decapitalize(methodName.substring(GET.length())); + } + else if (isBoolean(method.getReturnType()) && isPrefixedWith(methodName, IS)) { + return Introspector.decapitalize(methodName.substring(IS.length())); + } + else { + return methodName; + } + } + + private static boolean isBoolean(Class<?> clazz) { + return Boolean.class.equals(clazz) || Boolean.TYPE.equals(clazz); + } + + private static boolean isPrefixedWith(String name, String prefix) { + return name.length() > prefix.length() + && name.startsWith(prefix) + && Character.isUpperCase(name.charAt(prefix.length())); + } + + @Override + protected Object accessValue(Object instance) + throws IllegalArgumentException, IllegalAccessException { + try { + return element.invoke(instance, (Object[])null); + } + catch (InvocationTargetException e) { + throw new RuntimeException(e.getCause()); + } + } +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PropertyField.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PropertyField.java 2009-09-25 22:13:12 UTC (rev 161) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PropertyField.java 2009-09-25 22:17:23 UTC (rev 162) @@ -1,15 +1,15 @@ -package org.pojomatic.internal; - -import java.lang.reflect.Field; - -public class PropertyField extends AbstractPropertyElement<Field> { - public PropertyField(Field propertyField, String name) { - super(propertyField, name.length() == 0 ? propertyField.getName() : name); - } - - @Override - protected Object accessValue(Object instance) - throws IllegalArgumentException, IllegalAccessException { - return element.get(instance); - } -} +package org.pojomatic.internal; + +import java.lang.reflect.Field; + +public class PropertyField extends AbstractPropertyElement<Field> { + public PropertyField(Field propertyField, String name) { + super(propertyField, name.length() == 0 ? propertyField.getName() : name); + } + + @Override + protected Object accessValue(Object instance) + throws IllegalArgumentException, IllegalAccessException { + return element.get(instance); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-25 22:13:25
|
Revision: 161 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=161&view=rev Author: iroberts Date: 2009-09-25 22:13:12 +0000 (Fri, 25 Sep 2009) Log Message: ----------- add a test to verify that ClassProperties doesn't grab inherited methods twice Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/a/C1.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/a/C3.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/b/C2.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/b/C4.java Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2009-09-25 22:12:22 UTC (rev 160) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2009-09-25 22:13:12 UTC (rev 161) @@ -12,6 +12,9 @@ import org.pojomatic.annotations.DefaultPojomaticPolicy; import org.pojomatic.annotations.PojomaticPolicy; import org.pojomatic.annotations.Property; +import org.pojomatic.internal.a.C1; +import org.pojomatic.internal.b.C2; +import org.pojomatic.internal.b.C4; public class ClassPropertiesTest { @@ -208,6 +211,22 @@ } @Test + public void testOverriddenMethods() throws Exception { + ClassProperties classProperties = new ClassProperties(C4.class); + assertEquals( + asSet( + TestUtils.method(C1.class, "packagePrivate"), + TestUtils.method(C1.class, "packagePrivateOverriddenProtected"), + TestUtils.method(C1.class, "packagePrivateOverriddenPublic"), + TestUtils.method(C1.class, "protectedMethod"), + TestUtils.method(C1.class, "publicMethod"), + TestUtils.method(C2.class, "packagePrivate"), + TestUtils.method(C2.class, "packagePrivateOverriddenProtected"), + TestUtils.method(C2.class, "packagePrivateOverriddenPublic")), + asSet(classProperties.getEqualsProperties())); + } + + @Test public void testAnnotatedStaticField() { try { new ClassProperties(StaticField.class); Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/a/C1.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/a/C1.java 2009-09-25 22:12:22 UTC (rev 160) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/a/C1.java 2009-09-25 22:13:12 UTC (rev 161) @@ -1,9 +1,11 @@ package org.pojomatic.internal.a; +import org.pojomatic.annotations.Property; + public class C1 { - int packagePrivate() { return 1; } - int packagePrivateOverriddenProtected() { return 1; } - int packagePrivateOverriddenPublic() { return 1; } - protected int protectedMethod() { return 1; } - public int publicMethod() { return 1; } + @Property int packagePrivate() { return 1; } + @Property int packagePrivateOverriddenProtected() { return 1; } + @Property int packagePrivateOverriddenPublic() { return 1; } + @Property protected int protectedMethod() { return 1; } + @Property public int publicMethod() { return 1; } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/a/C3.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/a/C3.java 2009-09-25 22:12:22 UTC (rev 160) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/a/C3.java 2009-09-25 22:13:12 UTC (rev 161) @@ -1,12 +1,13 @@ package org.pojomatic.internal.a; +import org.pojomatic.annotations.Property; import org.pojomatic.internal.b.C2; @SuppressWarnings("all") public class C3 extends C2 { - int packagePrivate() { return 3; } - protected int packagePrivateOverriddenProtected() { return 3; } - public int packagePrivateOverriddenPublic() { return 3; } - protected int protectedMethod() { return 3; } - public int publicMethod() { return 3; } + @Property int packagePrivate() { return 3; } + @Property protected int packagePrivateOverriddenProtected() { return 3; } + @Property public int packagePrivateOverriddenPublic() { return 3; } + @Property protected int protectedMethod() { return 3; } + @Property public int publicMethod() { return 3; } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/b/C2.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/b/C2.java 2009-09-25 22:12:22 UTC (rev 160) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/b/C2.java 2009-09-25 22:13:12 UTC (rev 161) @@ -1,12 +1,13 @@ package org.pojomatic.internal.b; +import org.pojomatic.annotations.Property; import org.pojomatic.internal.a.C1; @SuppressWarnings("all") public class C2 extends C1 { - int packagePrivate() { return 1; } - protected int packagePrivateOverriddenProtected() { return 2; } - public int packagePrivateOverriddenPublic() { return 2; } - protected int protectedMethod() { return 2; } - public int publicMethod() { return 2; } + @Property int packagePrivate() { return 1; } + @Property protected int packagePrivateOverriddenProtected() { return 2; } + @Property public int packagePrivateOverriddenPublic() { return 2; } + @Property protected int protectedMethod() { return 2; } + @Property public int publicMethod() { return 2; } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/b/C4.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/b/C4.java 2009-09-25 22:12:22 UTC (rev 160) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/b/C4.java 2009-09-25 22:13:12 UTC (rev 161) @@ -1,12 +1,13 @@ package org.pojomatic.internal.b; +import org.pojomatic.annotations.Property; import org.pojomatic.internal.a.C3; @SuppressWarnings("all") public class C4 extends C3 { - int packagePrivate() { return 4; } - protected int packagePrivateOverriddenProtected() { return 4; } - public int packagePrivateOverriddenPublic() { return 4; } - protected int protectedMethod() { return 4; } - public int publicMethod() { return 4; } + @Property int packagePrivate() { return 4; } + @Property protected int packagePrivateOverriddenProtected() { return 4; } + @Property public int packagePrivateOverriddenPublic() { return 4; } + @Property protected int protectedMethod() { return 4; } + @Property public int publicMethod() { return 4; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-25 22:12:30
|
Revision: 160 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=160&view=rev Author: iroberts Date: 2009-09-25 22:12:22 +0000 (Fri, 25 Sep 2009) Log Message: ----------- add javadoc Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java 2009-09-25 21:29:50 UTC (rev 159) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java 2009-09-25 22:12:22 UTC (rev 160) @@ -10,6 +10,20 @@ */ class OverridableMethods { + /** + * Check to see if roles should be added to a method, and add them if so. Only roles not already + * on the method will be added. If {@code method} already has an + * {@link PropertyRole#EQUALS EQUALS} role, and it is requested to add the + * {@link PropertyRole#HASH_CODE HASH_CODE} role, an {@link IllegalArgumentException} will be + * thrown. + * + * @param method the method to check + * @param newRoles the roles to add + * @return the roles which were actually added. + * @throws IllegalArgumentException if {@code method} already has an + * {@link PropertyRole#EQUALS EQUALS} role, and it is requested to add the + * {@link PropertyRole#HASH_CODE HASH_CODE} role + */ Set<PropertyRole> checkAndMaybeAddRolesToMethod(Method method, Set<PropertyRole> newRoles) { Set<PropertyRole> existingRoles = findExistingRoles(method); if (existingRoles.contains(PropertyRole.EQUALS) @@ -61,6 +75,8 @@ * A bean to track the package and name of a package-private method */ private static class PackageMethod { + //TODO: Consider tracking the return type as well, to deal with byte-code-generated overloads + // that have different return types, as well as return type narrowing in a subclass. PackageMethod(Method method) { name = method.getName(); pakage = method.getDeclaringClass().getPackage(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-25 21:30:18
|
Revision: 159 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=159&view=rev Author: iroberts Date: 2009-09-25 21:29:50 +0000 (Fri, 25 Sep 2009) Log Message: ----------- clean up eclipse warnings Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2009-09-19 17:02:30 UTC (rev 158) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2009-09-25 21:29:50 UTC (rev 159) @@ -54,8 +54,9 @@ @Test public void testAnnotatedMethods() throws Exception { class MethodPojo { - @Property public int getInt() { return 0; } + @SuppressWarnings("unused") @Property public int getInt() { return 0; } @Property @SuppressWarnings("unused") private String privateString() { return null; } + @SuppressWarnings("unused") @Property(policy=PojomaticPolicy.EQUALS) public double onlyForEquals() { return 0.0; } } @@ -96,13 +97,16 @@ @Test(expected=IllegalArgumentException.class) public void testAnnotatedMethodReturningVoid() { - class MethodReturnsVoidPojo { @Property public void noReturn() {} } + class MethodReturnsVoidPojo { @SuppressWarnings("unused") @Property public void noReturn() {} } new ClassProperties(MethodReturnsVoidPojo.class); } @Test(expected=IllegalArgumentException.class) public void testAnnotatedMethodTakingArgs() { - class MethodTakesArgsPojo { @Property public int takesArgs(String death) { return death.length(); } } + class MethodTakesArgsPojo { + @SuppressWarnings("unused") @Property public int takesArgs(String death) { + return death.length(); } + } new ClassProperties(MethodTakesArgsPojo.class); } @@ -143,7 +147,7 @@ @AutoProperty(autoDetect=AutoDetectPolicy.METHOD) class ChildAutoMethodPojo extends ParentPojo { @Override public int getFoo() { return 2; } - public int getBar() { return 2; } + @SuppressWarnings("unused") public int getBar() { return 2; } } ClassProperties childClassProperties = new ClassProperties(ChildAutoMethodPojo.class); @@ -154,13 +158,13 @@ assertEquals(expected, asSet(childClassProperties.getHashCodeProperties())); assertEquals(expected, asSet(childClassProperties.getToStringProperties())); } - + @Test public void testAutoInheritanceAnnotatedParent() throws Exception { @AutoProperty(autoDetect=AutoDetectPolicy.METHOD) class ChildExtendsAnnotatedPojo extends ParentPojo { @Override public int getFoo() { return 0; } - public String getMyString() { return "foo"; } + @SuppressWarnings("unused") public String getMyString() { return "foo"; } } Set<PropertyElement> expectedParent = asSet(TestUtils.method(ParentPojo.class, "getFoo")); @@ -181,9 +185,9 @@ @Test public void testAutoInheritanceAutoParentAnnotatedChild() throws Exception { class ChildExtendsAutoPojo extends ParentAutoPojo { - @Property public String other; + @SuppressWarnings("unused") @Property public String other; @Override public int getFoo() { return 2; } - public String getBar() { return ""; } + @SuppressWarnings("unused") public String getBar() { return ""; } } Set<PropertyElement> expectedParent = asSet(TestUtils.method(ParentAutoPojo.class, "getFoo")); @@ -202,7 +206,7 @@ assertEquals(expectedChild, asSet(childClassProperties.getHashCodeProperties())); assertEquals(expectedChild, asSet(childClassProperties.getToStringProperties())); } - + @Test public void testAnnotatedStaticField() { try { @@ -211,7 +215,7 @@ } catch (IllegalArgumentException e) { assertEquals( - "Static field " + StaticField.class.getName() + ".a is annotated with @Property", + "Static field " + StaticField.class.getName() + ".a is annotated with @Property", e.getMessage()); } } @@ -224,11 +228,11 @@ } catch (IllegalArgumentException e) { assertEquals( - "Static method " + StaticMethod.class.getName() + ".a() is annotated with @Property", + "Static method " + StaticMethod.class.getName() + ".a() is annotated with @Property", e.getMessage()); } } - + @Test public void testInterface() throws Exception { ClassProperties classProperties = new ClassProperties(Interface.class); PropertyElement getFoo = TestUtils.method(Interface.class, "getFoo"); Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java 2009-09-19 17:02:30 UTC (rev 158) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java 2009-09-25 21:29:50 UTC (rev 159) @@ -8,7 +8,7 @@ public class EqualsInheritanceTest { private static class Parent { - @Property int x = 3; + @SuppressWarnings("unused") @Property int x = 3; @Override public boolean equals(Object obj) { @@ -30,7 +30,7 @@ } @Test public void testChildWithNewProperty() { - class Child extends Parent { @Property int y = 4; } + class Child extends Parent { @SuppressWarnings("unused") @Property int y = 4; } Child child = new Child(); Pojomator<Child> childPojomator = new PojomatorImpl<Child>(Child.class); Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2009-09-19 17:02:30 UTC (rev 158) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2009-09-25 21:29:50 UTC (rev 159) @@ -86,7 +86,7 @@ @Test public void testObjectArrayPropertyEquals() { class StringArrayProperty { public StringArrayProperty(String... strings) { this.strings = strings; } - @Property String[] strings; + @SuppressWarnings("unused") @Property String[] strings; } Pojomator<StringArrayProperty> STRING_ARRAY_PROPERTY_POJOMATOR = makePojomatorImpl(StringArrayProperty.class); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-19 17:02:40
|
Revision: 158 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=158&view=rev Author: iroberts Date: 2009-09-19 17:02:30 +0000 (Sat, 19 Sep 2009) Log Message: ----------- Update doEquals documentation Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2009-09-19 16:12:20 UTC (rev 157) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2009-09-19 17:02:30 UTC (rev 158) @@ -67,24 +67,28 @@ /** * {@inheritDoc} - *<p> - * For this to return true, the following must hold: + * <p> + * In essance, two objects will be considered equal if they have the same set of properties with a + * {@link PropertyRole} of {@link PropertyRole#EQUALS EQUALS}, and for each property, the values are equal as + * described below. + * <p> + * More precisely, if {@code other} is null, this method returns {@code false}. If {@code other} is a an instance of + * a proper subclass of the class of {@code instance}, then this method returns the result of calling + * {@code other.equals(instance)}. Otherwise, it is verified that the class of {@code other} either the same as or a + * subclass of the most specific class contributing a property with a {@code PropertyRole} of {@code EQUALS}; if not, + * then this method returns false. Otherwise, this method will return true provided that each property of + * {@code instance} which has a {@link PojomaticPolicy} other than {@link PojomaticPolicy#TO_STRING TO_STRING} or + * {@link PojomaticPolicy#NONE NONE} is equal to the corresponding property of {@code other} in the following sense: * <ul> - * <li>{@code other} must be non-null, and an instance of {@code T}</li> - * <li>Each property of {@code instance} which has a {@link PojomaticPolicy} other than - * {@link PojomaticPolicy#TO_STRING TO_STRING} or {@link PojomaticPolicy#NONE NONE} must be equal - * to the corresponding property of {@code other} in the following sense: - * <ul> - * <li>Both are {@code null}, or</li> - * <li>Both are reference-equals (==) to each other, or</li> - * <li>Both are primitive of the same type, and equal to each other, or</li> - * <li>Both are of array type, with matching primitive component types, and the corresponding - * {@code} equals method of {@link Arrays} returns true, or</li> - * <li>Both are of array type with non-primitive component types, and - * {@link Arrays#deepEquals(Object[], Object[])} returns true, or</li> - * <li>The property {@code p} in {@code instance} is an object not of array type, and - * {@code instanceP.equals(otherP)} returns true. - * </ul> + * <li>Both are {@code null}, or</li> + * <li>Both are reference-equals (==) to each other, or</li> + * <li>Both are primitive of the same type, and equal to each other, or</li> + * <li>Both are of array type, with matching primitive component types, and the corresponding + * {@code} equals method of {@link Arrays} returns true, or</li> + * <li>Both are of array type with non-primitive component types, and + * {@link Arrays#deepEquals(Object[], Object[])} returns true, or</li> + * <li>The property {@code p} in {@code instance} is an object not of array type, and + * {@code instanceP.equals(otherP)} returns true. * </ul> * * @throws NullPointerException if {@code instance} is null This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-19 16:12:29
|
Revision: 157 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=157&view=rev Author: iroberts Date: 2009-09-19 16:12:20 +0000 (Sat, 19 Sep 2009) Log Message: ----------- doEquals now works properly with inheritance: *) If other is a subclass, defer to other's equals implementation *) Otherwise, other must either be of the same class as this, or a subclass of the most specific class contributing a property with role of equals. Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java Added Paths: ----------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java 2009-09-19 16:09:13 UTC (rev 156) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java 2009-09-19 16:12:20 UTC (rev 157) @@ -22,12 +22,12 @@ * {@link PojomatorImpl#doEquals(Object, Object)}, and {@link PojomatorImpl#doToString(Object)}. */ public class ClassProperties { - - private static final Pattern ACCESSOR_PATTERN = Pattern.compile("(get|is)\\P{Ll}.*"); private final Map<PropertyRole, Collection<PropertyElement>> properties = makeProperties(); + private final Class<?> equalsParentClass; + /** * Creates an instance for the given {@code pojoClass}. * @@ -38,13 +38,49 @@ public ClassProperties(Class<?> pojoClass) throws IllegalArgumentException { if (pojoClass.isInterface()) { extractClassProperties(pojoClass, new OverridableMethods()); + equalsParentClass = pojoClass; } else { walkHierarchy(pojoClass, new OverridableMethods()); + equalsParentClass = findMostSpecificClassContributingToEquals(); } verifyPropertiesNotEmpty(pojoClass); } + /** + * Gets the properties to use for {@link PojomatorImpl#doEquals(Object, Object)}. + * @return the properties to use for {@link PojomatorImpl#doEquals(Object, Object)}. + */ + public Collection<PropertyElement> getEqualsProperties() { + return properties.get(PropertyRole.EQUALS); + } + + /** + * Gets the properties to use for {@link PojomatorImpl#doHashCode(Object)}. + * @return the properties to use for {@link PojomatorImpl#doHashCode(Object)}. + */ + public Collection<PropertyElement> getHashCodeProperties() { + return properties.get(PropertyRole.HASH_CODE); + } + + /** + * Gets the properties to use for {@link PojomatorImpl#doToString(Object)}. + * @return the properties to use for {@link PojomatorImpl#doToString(Object)}. + */ + public Collection<PropertyElement> getToStringProperties() { + return properties.get(PropertyRole.TO_STRING); + } + + /** + * Get the class which any class must inherit from in order for its instances to be candidates for being considered + * equal by {@link PojomatorImpl#doEquals(Object, Object)}. + * @return the class which any class must inherit from in order for its instances to be candidates for being + * considered equal by {@link PojomatorImpl#doEquals(Object, Object)}. + */ + public Class<?> getEqualsParentClass() { + return equalsParentClass; + } + private void walkHierarchy(Class<?> clazz, OverridableMethods overridableMethods) { if (clazz != Object.class) { walkHierarchy(clazz.getSuperclass(), overridableMethods); @@ -141,6 +177,16 @@ "Class " + pojoClass.getName() + " has no Pojomatic properties"); } + private Class<?> findMostSpecificClassContributingToEquals() { + Class<?> clazz = Object.class; + for (PropertyElement propertyElement : properties.get(PropertyRole.EQUALS)) { + if (clazz.isAssignableFrom(propertyElement.getDeclaringClass())) { + clazz = propertyElement.getDeclaringClass(); + } + } + return clazz; + } + private String getPropertyName(Property property) { return property == null ? "" : property.name(); } @@ -163,30 +209,6 @@ return Modifier.isStatic(member.getModifiers()); } - /** - * Gets the properties to use for {@link PojomatorImpl#doEquals(Object, Object)}. - * @return the properties to use for {@link PojomatorImpl#doEquals(Object, Object)}. - */ - public Collection<PropertyElement> getEqualsProperties() { - return properties.get(PropertyRole.EQUALS); - } - - /** - * Gets the properties to use for {@link PojomatorImpl#doHashCode(Object)}. - * @return the properties to use for {@link PojomatorImpl#doHashCode(Object)}. - */ - public Collection<PropertyElement> getHashCodeProperties() { - return properties.get(PropertyRole.HASH_CODE); - } - - /** - * Gets the properties to use for {@link PojomatorImpl#doToString(Object)}. - * @return the properties to use for {@link PojomatorImpl#doToString(Object)}. - */ - public Collection<PropertyElement> getToStringProperties() { - return properties.get(PropertyRole.TO_STRING); - } - private static Map<PropertyRole, Collection<PropertyElement>> makeProperties() { Map<PropertyRole, Collection<PropertyElement>> properties = new EnumMap<PropertyRole, Collection<PropertyElement>>(PropertyRole.class); Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2009-09-19 16:09:13 UTC (rev 156) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2009-09-19 16:12:20 UTC (rev 157) @@ -96,9 +96,17 @@ if (instance == other) { return true; } - if (! clazz.isInstance(other)) { + if (other == null) { return false; } + if (!instance.getClass().equals(other.getClass())) { + if (instance.getClass().isAssignableFrom(other.getClass())) { + return other.equals(instance); + } + if (!classProperties.getEqualsParentClass().isAssignableFrom(other.getClass())) { + return false; + } + } for (PropertyElement prop: classProperties.getEqualsProperties()) { if (!areValuesEqual(prop.getValue(instance), prop.getValue(other))) { Added: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java 2009-09-19 16:12:20 UTC (rev 157) @@ -0,0 +1,55 @@ +package org.pojomatic.internal; + +import org.junit.Test; +import static org.junit.Assert.*; +import org.pojomatic.annotations.Property; +import org.pojomatic.Pojomator; +import org.pojomatic.Pojomatic; + +public class EqualsInheritanceTest { + private static class Parent { + @Property int x = 3; + + @Override + public boolean equals(Object obj) { + return Pojomatic.equals(this, obj); + } + } + + private static Pojomator<Parent> PARENT_POJOMATOR = new PojomatorImpl<Parent>(Parent.class); + private static Parent PARENT = new Parent(); + + @Test public void testChildWithNoNewProperties() { + class Child extends Parent {} + Child child = new Child(); + Pojomator<Child> childPojomator = new PojomatorImpl<Child>(Child.class); + + assertTrue(PARENT_POJOMATOR.doEquals(PARENT, child)); + assertTrue(PARENT_POJOMATOR.doEquals(child, PARENT)); + assertTrue(childPojomator.doEquals(child, PARENT)); + } + + @Test public void testChildWithNewProperty() { + class Child extends Parent { @Property int y = 4; } + Child child = new Child(); + Pojomator<Child> childPojomator = new PojomatorImpl<Child>(Child.class); + + assertFalse(PARENT.equals(child)); + assertFalse(child.equals(PARENT)); + assertFalse(PARENT_POJOMATOR.doEquals(PARENT, child)); + assertFalse(childPojomator.doEquals(child, PARENT)); + // If we expicitely use a PARENT_POJOMATOR to compare child to parent, we'll miss the additional child property. + assertTrue(PARENT_POJOMATOR.doEquals(child, PARENT)); + } + + @Test public void testTwoChildrenWithNoNewProperties() { + class Child1 extends Parent {} + class Child2 extends Parent {} + Child1 child1 = new Child1(); + Child2 child2 = new Child2(); + Pojomator<Child1> childPojomator = new PojomatorImpl<Child1>(Child1.class); + + assertTrue(PARENT_POJOMATOR.doEquals(child1, child2)); + assertTrue(childPojomator.doEquals(child1, child2)); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-19 16:09:28
|
Revision: 156 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=156&view=rev Author: iroberts Date: 2009-09-19 16:09:13 +0000 (Sat, 19 Sep 2009) Log Message: ----------- Test interface pojomators Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2009-09-19 16:03:54 UTC (rev 155) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2009-09-19 16:09:13 UTC (rev 156) @@ -10,10 +10,7 @@ import org.junit.Test; import org.pojomatic.Pojomator; -import org.pojomatic.annotations.AutoProperty; -import org.pojomatic.annotations.PojoFormat; -import org.pojomatic.annotations.Property; -import org.pojomatic.annotations.PropertyFormat; +import org.pojomatic.annotations.*; import org.pojomatic.diff.Difference; import org.pojomatic.diff.DifferenceFromNull; import org.pojomatic.diff.DifferenceToNull; @@ -316,6 +313,29 @@ assertTrue(pojomator.doToString(new PrivateClass()).contains("number")); } + @Test public void testInterface() { + Pojomator<Interface> pojomator = makePojomatorImpl(Interface.class); + class Impl1 implements Interface { + public int getInt() { return 2; } + public String getString() { return "hello"; } + } + + class Impl2 implements Interface { + private final String string; + + Impl2(String string) { this.string = string; } + public int getInt() { return 2; } + public String getString() { return string; } + } + + + assertEquals("Interface{int: {2}, string: {hello}}", pojomator.doToString(new Impl1())); + assertEquals(( + HASH_CODE_MULTIPLIER + 2)*HASH_CODE_MULTIPLIER + "hello".hashCode(), pojomator.doHashCode(new Impl1())); + assertTrue(pojomator.doEquals(new Impl1(), new Impl2("hello"))); + assertFalse(pojomator.doEquals(new Impl1(), new Impl2("goodbye"))); + } + @PojoFormat(SimplePojoFormatter.class) public static class FormattedObject { public FormattedObject(Object s) { @@ -395,6 +415,12 @@ private int number; } + @AutoProperty(autoDetect = AutoDetectPolicy.METHOD) + private static interface Interface { + public int getInt(); + public String getString(); + } + private static <T> Pojomator<T> makePojomatorImpl(Class<T> clazz) { return new PojomatorImpl<T>(clazz); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-19 16:04:01
|
Revision: 155 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=155&view=rev Author: iroberts Date: 2009-09-19 16:03:54 +0000 (Sat, 19 Sep 2009) Log Message: ----------- Add the declaring class of the property to PropertyElement Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/PropertyElement.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/AbstractPropertyElement.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PropertyElementTest.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/PropertyElement.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/PropertyElement.java 2009-09-19 16:00:18 UTC (rev 154) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/PropertyElement.java 2009-09-19 16:03:54 UTC (rev 155) @@ -28,4 +28,10 @@ */ AnnotatedElement getElement(); + /** + * Get the class object representing the class or interface declaring this property. + * @return the declaring class or interface of this property. + */ + Class<?> getDeclaringClass(); + } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/AbstractPropertyElement.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/AbstractPropertyElement.java 2009-09-19 16:00:18 UTC (rev 154) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/AbstractPropertyElement.java 2009-09-19 16:03:54 UTC (rev 155) @@ -48,6 +48,10 @@ return this.element; } + public Class<?> getDeclaringClass() { + return element.getDeclaringClass(); + } + @Override public int hashCode() { return element.hashCode(); Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PropertyElementTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PropertyElementTest.java 2009-09-19 16:00:18 UTC (rev 154) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PropertyElementTest.java 2009-09-19 16:03:54 UTC (rev 155) @@ -41,6 +41,12 @@ } @Test + public void testGetDeclaringClass() throws Exception { + assertEquals(PropertyElementTest.class, new PropertyAccessor(getTestMethod(), "").getDeclaringClass()); + assertEquals(PropertyElementTest.class, new PropertyField(getTestField(), "").getDeclaringClass()); + } + + @Test public void testEquals() throws Exception { PropertyAccessor testMethodProperty = new PropertyAccessor(getTestMethod(), ""); assertEquals(testMethodProperty, testMethodProperty); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-19 16:00:24
|
Revision: 154 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=154&view=rev Author: iroberts Date: 2009-09-19 16:00:18 +0000 (Sat, 19 Sep 2009) Log Message: ----------- Add test for hashCode of field property Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PropertyElementTest.java Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PropertyElementTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PropertyElementTest.java 2009-09-14 06:45:33 UTC (rev 153) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PropertyElementTest.java 2009-09-19 16:00:18 UTC (rev 154) @@ -58,11 +58,16 @@ } @Test - public void testHashCode() throws Exception { - assertEquals(getTestMethod().hashCode(), new PropertyAccessor(getTestMethod(), "").hashCode()); + public void testMethodHashCode() throws Exception { + assertEquals(getTestMethod().hashCode(), new PropertyAccessor(getTestMethod(), "salt").hashCode()); } @Test + public void testFieldHashCode() throws Exception { + assertEquals(getTestField().hashCode(), new PropertyField(getTestField(), "salt").hashCode()); + } + + @Test public void testGetNameForField() throws Exception { assertEquals("testField", new PropertyField(getTestField(), "").getName()); assertEquals("foo", new PropertyField(getTestField(), "foo").getName()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-14 06:45:41
|
Revision: 153 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=153&view=rev Author: iroberts Date: 2009-09-14 06:45:33 +0000 (Mon, 14 Sep 2009) Log Message: ----------- Remove pointlessly generic factory method in favor of direct constructor Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/Bean.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java 2009-09-14 04:08:01 UTC (rev 152) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java 2009-09-14 06:45:33 UTC (rev 153) @@ -22,20 +22,8 @@ * {@link PojomatorImpl#doEquals(Object, Object)}, and {@link PojomatorImpl#doToString(Object)}. */ public class ClassProperties { - /** - * Creates a new instance. - * - * @param <T> the type of {@code pojoClass} - * @param pojoClass the class to inspect - * @return a new instance - * @throws IllegalArgumentException if {@code pojoClass} has no properties annotated for use - * with Pojomatic. - */ - public static <T> ClassProperties createInstance(Class<T> pojoClass) throws IllegalArgumentException { - return new ClassProperties(pojoClass); - } - + private static final Pattern ACCESSOR_PATTERN = Pattern.compile("(get|is)\\P{Ll}.*"); private final Map<PropertyRole, Collection<PropertyElement>> properties = makeProperties(); @@ -47,7 +35,7 @@ * @throws IllegalArgumentException if {@code pojoClass} has no properties annotated for use * with Pojomatic. */ - private ClassProperties(Class<?> pojoClass) throws IllegalArgumentException { + public ClassProperties(Class<?> pojoClass) throws IllegalArgumentException { if (pojoClass.isInterface()) { extractClassProperties(pojoClass, new OverridableMethods()); } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2009-09-14 04:08:01 UTC (rev 152) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2009-09-14 06:45:33 UTC (rev 153) @@ -36,7 +36,7 @@ */ public PojomatorImpl(Class<T> clazz) throws IllegalArgumentException { this.clazz = clazz; - classProperties = ClassProperties.createInstance(clazz); + classProperties = new ClassProperties(clazz); pojoFormatterClass = findPojoFormatterClass(clazz); for (PropertyElement prop: classProperties.getToStringProperties()) { PropertyFormatter propertyFormatter = findPropertyFormatter(prop.getElement()); Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2009-09-14 04:08:01 UTC (rev 152) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2009-09-14 06:45:33 UTC (rev 153) @@ -23,7 +23,7 @@ final PropertyElement forEqualsAndToString = TestUtils.field(FieldPojo.class, "forEqualsAndToString"); - ClassProperties classProperties = ClassProperties.createInstance(FieldPojo.class); + ClassProperties classProperties = new ClassProperties(FieldPojo.class); assertEquals( asSet(privateStringField, publicIntField, forEqualsAndToString), @@ -42,7 +42,7 @@ final PropertyElement stringField = TestUtils.field(AutoFieldPojo.class, "string"); final PropertyElement allInDoubleField = TestUtils.field(AutoFieldPojo.class, "allInDouble"); - ClassProperties classProperties = ClassProperties.createInstance(AutoFieldPojo.class); + ClassProperties classProperties = new ClassProperties(AutoFieldPojo.class); assertEquals(asSet(allInDoubleField), asSet(classProperties.getEqualsProperties())); assertEquals(asSet(allInDoubleField), asSet(classProperties.getHashCodeProperties())); @@ -63,7 +63,7 @@ final PropertyElement privateStringMethod = TestUtils.method(MethodPojo.class, "privateString"); final PropertyElement onlyForEqualsMethod = TestUtils.method(MethodPojo.class, "onlyForEquals"); - ClassProperties classProperties = ClassProperties.createInstance(MethodPojo.class); + ClassProperties classProperties = new ClassProperties(MethodPojo.class); assertEquals( asSet(getIntMethod, privateStringMethod, onlyForEqualsMethod), @@ -87,7 +87,7 @@ new HashSet<PropertyElement>(commonProperties); equalsHashCodeProperties.add(TestUtils.method(AutoMethodPojo.class, "getHashCodeAndEquals")); - ClassProperties classProperties = ClassProperties.createInstance(AutoMethodPojo.class); + ClassProperties classProperties = new ClassProperties(AutoMethodPojo.class); assertEquals(equalsHashCodeProperties, asSet(classProperties.getEqualsProperties())); assertEquals(equalsHashCodeProperties, asSet(classProperties.getHashCodeProperties())); @@ -97,24 +97,24 @@ @Test(expected=IllegalArgumentException.class) public void testAnnotatedMethodReturningVoid() { class MethodReturnsVoidPojo { @Property public void noReturn() {} } - ClassProperties.createInstance(MethodReturnsVoidPojo.class); + new ClassProperties(MethodReturnsVoidPojo.class); } @Test(expected=IllegalArgumentException.class) public void testAnnotatedMethodTakingArgs() { class MethodTakesArgsPojo { @Property public int takesArgs(String death) { return death.length(); } } - ClassProperties.createInstance(MethodTakesArgsPojo.class); + new ClassProperties(MethodTakesArgsPojo.class); } @Test public void testAnnotatedInheritance() throws Exception { Set<PropertyElement> expectedParent = asSet(TestUtils.method(ParentPojo.class, "getFoo")); - ClassProperties parentClassProperties = ClassProperties.createInstance(ParentPojo.class); + ClassProperties parentClassProperties = new ClassProperties(ParentPojo.class); assertEquals(expectedParent, asSet(parentClassProperties.getEqualsProperties())); assertEquals(expectedParent, asSet(parentClassProperties.getHashCodeProperties())); assertEquals(expectedParent, asSet(parentClassProperties.getToStringProperties())); - ClassProperties childClassProperties = ClassProperties.createInstance(ChildPojo.class); + ClassProperties childClassProperties = new ClassProperties(ChildPojo.class); Set<PropertyElement> expectedChild = asSet( TestUtils.method(ParentPojo.class, "getFoo"), TestUtils.field(ChildPojo.class, "other")); assertEquals(expectedChild, asSet(childClassProperties.getEqualsProperties())); @@ -125,12 +125,12 @@ @Test public void testAutoInheritanceBothAuto() throws Exception { Set<PropertyElement> expectedParent = asSet(TestUtils.method(ParentAutoPojo.class, "getFoo")); - ClassProperties parentClassProperties = ClassProperties.createInstance(ParentAutoPojo.class); + ClassProperties parentClassProperties = new ClassProperties(ParentAutoPojo.class); assertEquals(expectedParent, asSet(parentClassProperties.getEqualsProperties())); assertEquals(Collections.EMPTY_SET, asSet(parentClassProperties.getHashCodeProperties())); assertEquals(Collections.EMPTY_SET, asSet(parentClassProperties.getToStringProperties())); - ClassProperties childClassProperties = ClassProperties.createInstance(ChildAutoFieldPojo.class); + ClassProperties childClassProperties = new ClassProperties(ChildAutoFieldPojo.class); Set<PropertyElement> expectedChild = asSet( TestUtils.field(ChildAutoFieldPojo.class, "other")); assertEquals(expectedParent, asSet(childClassProperties.getEqualsProperties())); @@ -146,7 +146,7 @@ public int getBar() { return 2; } } - ClassProperties childClassProperties = ClassProperties.createInstance(ChildAutoMethodPojo.class); + ClassProperties childClassProperties = new ClassProperties(ChildAutoMethodPojo.class); Set<PropertyElement> expected = asSet( TestUtils.method(ParentPojo.class, "getFoo"), TestUtils.method(ChildAutoMethodPojo.class, "getBar")); @@ -164,12 +164,12 @@ } Set<PropertyElement> expectedParent = asSet(TestUtils.method(ParentPojo.class, "getFoo")); - ClassProperties parentClassProperties = ClassProperties.createInstance(ParentPojo.class); + ClassProperties parentClassProperties = new ClassProperties(ParentPojo.class); assertEquals(expectedParent, asSet(parentClassProperties.getEqualsProperties())); assertEquals(expectedParent, asSet(parentClassProperties.getHashCodeProperties())); assertEquals(expectedParent, asSet(parentClassProperties.getToStringProperties())); - ClassProperties childClassProperties = ClassProperties.createInstance(ChildExtendsAnnotatedPojo.class); + ClassProperties childClassProperties = new ClassProperties(ChildExtendsAnnotatedPojo.class); Set<PropertyElement> expectedChild = asSet( TestUtils.method(ParentPojo.class, "getFoo"), TestUtils.method(ChildExtendsAnnotatedPojo.class, "getMyString")); @@ -187,12 +187,12 @@ } Set<PropertyElement> expectedParent = asSet(TestUtils.method(ParentAutoPojo.class, "getFoo")); - ClassProperties parentClassProperties = ClassProperties.createInstance(ParentAutoPojo.class); + ClassProperties parentClassProperties = new ClassProperties(ParentAutoPojo.class); assertEquals(expectedParent, asSet(parentClassProperties.getEqualsProperties())); assertEquals(Collections.EMPTY_SET, asSet(parentClassProperties.getHashCodeProperties())); assertEquals(Collections.EMPTY_SET, asSet(parentClassProperties.getToStringProperties())); - ClassProperties childClassProperties = ClassProperties.createInstance(ChildExtendsAutoPojo.class); + ClassProperties childClassProperties = new ClassProperties(ChildExtendsAutoPojo.class); Set<PropertyElement> expectedChildEquals = asSet( TestUtils.method(ParentAutoPojo.class, "getFoo"), TestUtils.field(ChildExtendsAutoPojo.class, "other")); @@ -206,7 +206,7 @@ @Test public void testAnnotatedStaticField() { try { - ClassProperties.createInstance(StaticField.class); + new ClassProperties(StaticField.class); fail("Exception expected"); } catch (IllegalArgumentException e) { @@ -219,7 +219,7 @@ @Test public void testAnnotatedStaticMethod() { try { - ClassProperties.createInstance(StaticMethod.class); + new ClassProperties(StaticMethod.class); fail("Exception expected"); } catch (IllegalArgumentException e) { @@ -230,7 +230,7 @@ } @Test public void testInterface() throws Exception { - ClassProperties classProperties = ClassProperties.createInstance(Interface.class); + ClassProperties classProperties = new ClassProperties(Interface.class); PropertyElement getFoo = TestUtils.method(Interface.class, "getFoo"); PropertyElement baz = TestUtils.method(Interface.class, "baz"); assertEquals(asSet(getFoo), asSet(classProperties.getHashCodeProperties())); Modified: trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/Bean.java =================================================================== --- trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/Bean.java 2009-09-14 04:08:01 UTC (rev 152) +++ trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/Bean.java 2009-09-14 06:45:33 UTC (rev 153) @@ -25,7 +25,7 @@ } private static void setUpPojomaticHandrolled() { - ClassProperties classProperties = ClassProperties.createInstance(Bean.class); + ClassProperties classProperties = new ClassProperties(Bean.class); for (PropertyElement prop: classProperties.getHashCodeProperties()) { if ("integer".equals(prop.getName())) { getInteger = prop; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-14 04:08:07
|
Revision: 152 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=152&view=rev Author: iroberts Date: 2009-09-14 04:08:01 +0000 (Mon, 14 Sep 2009) Log Message: ----------- Some classes which are only referenced in one test method can be pulled into the method itself. Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2009-09-07 21:35:12 UTC (rev 151) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2009-09-14 04:08:01 UTC (rev 152) @@ -2,10 +2,7 @@ import static org.junit.Assert.*; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import org.junit.Test; import org.pojomatic.PropertyElement; @@ -56,6 +53,12 @@ @Test public void testAnnotatedMethods() throws Exception { + class MethodPojo { + @Property public int getInt() { return 0; } + @Property @SuppressWarnings("unused") private String privateString() { return null; } + @Property(policy=PojomaticPolicy.EQUALS) public double onlyForEquals() { return 0.0; } + } + final PropertyElement getIntMethod = TestUtils.method(MethodPojo.class, "getInt"); final PropertyElement privateStringMethod = TestUtils.method(MethodPojo.class, "privateString"); final PropertyElement onlyForEqualsMethod = TestUtils.method(MethodPojo.class, "onlyForEquals"); @@ -93,12 +96,14 @@ @Test(expected=IllegalArgumentException.class) public void testAnnotatedMethodReturningVoid() { - ClassProperties.createInstance(MethodReturnsVoidPojo.class); + class MethodReturnsVoidPojo { @Property public void noReturn() {} } + ClassProperties.createInstance(MethodReturnsVoidPojo.class); } @Test(expected=IllegalArgumentException.class) public void testAnnotatedMethodTakingArgs() { - ClassProperties.createInstance(MethodTakesArgsPojo.class); + class MethodTakesArgsPojo { @Property public int takesArgs(String death) { return death.length(); } } + ClassProperties.createInstance(MethodTakesArgsPojo.class); } @Test @@ -135,6 +140,12 @@ @Test public void testAutoInheritanceWithOverride() throws Exception { + @AutoProperty(autoDetect=AutoDetectPolicy.METHOD) + class ChildAutoMethodPojo extends ParentPojo { + @Override public int getFoo() { return 2; } + public int getBar() { return 2; } + } + ClassProperties childClassProperties = ClassProperties.createInstance(ChildAutoMethodPojo.class); Set<PropertyElement> expected = asSet( TestUtils.method(ParentPojo.class, "getFoo"), @@ -146,6 +157,12 @@ @Test public void testAutoInheritanceAnnotatedParent() throws Exception { + @AutoProperty(autoDetect=AutoDetectPolicy.METHOD) + class ChildExtendsAnnotatedPojo extends ParentPojo { + @Override public int getFoo() { return 0; } + public String getMyString() { return "foo"; } + } + Set<PropertyElement> expectedParent = asSet(TestUtils.method(ParentPojo.class, "getFoo")); ClassProperties parentClassProperties = ClassProperties.createInstance(ParentPojo.class); assertEquals(expectedParent, asSet(parentClassProperties.getEqualsProperties())); @@ -163,6 +180,12 @@ @Test public void testAutoInheritanceAutoParentAnnotatedChild() throws Exception { + class ChildExtendsAutoPojo extends ParentAutoPojo { + @Property public String other; + @Override public int getFoo() { return 2; } + public String getBar() { return ""; } + } + Set<PropertyElement> expectedParent = asSet(TestUtils.method(ParentAutoPojo.class, "getFoo")); ClassProperties parentClassProperties = ClassProperties.createInstance(ParentAutoPojo.class); assertEquals(expectedParent, asSet(parentClassProperties.getEqualsProperties())); @@ -213,9 +236,11 @@ assertEquals(asSet(getFoo), asSet(classProperties.getHashCodeProperties())); assertEquals(asSet(getFoo), asSet(classProperties.getToStringProperties())); assertEquals(asSet(getFoo, baz), asSet(classProperties.getEqualsProperties())); - } - + + //Not all classes can be made internal. In particular, autodetect=FIELD classes cannot, because of the synthetic + //$this, and classes requiring static elements cannot. + public static class FieldPojo { @SuppressWarnings("unused") @Property @@ -250,18 +275,6 @@ public static String staticField; } - public static class MethodPojo { - @Property - public int getInt() { return 0; } - - @Property - @SuppressWarnings("unused") - private String privateString() { return null; } - - @Property(policy=PojomaticPolicy.EQUALS) - public double onlyForEquals() { return 0.0; } - } - @AutoProperty(autoDetect=AutoDetectPolicy.METHOD, policy=DefaultPojomaticPolicy.ALL) public static class AutoMethodPojo { /* Fields are not auto-detected */ @@ -293,16 +306,6 @@ public static String getStatic() { return null; } } - public static class MethodReturnsVoidPojo { - @Property - public void noReturn() {} - } - - public static class MethodTakesArgsPojo { - @Property - public int takesArgs(String death) { return death.length(); } - } - private static abstract class ParentPojo { @Property public abstract int getFoo(); @@ -315,20 +318,6 @@ @Override public int getFoo() { return 2; } } - @AutoProperty(autoDetect=AutoDetectPolicy.METHOD) - public static class ChildAutoMethodPojo extends ParentPojo { - @Override public int getFoo() { return 2; } - public int getBar() { return 2; } - } - - @AutoProperty(autoDetect=AutoDetectPolicy.METHOD) - public static class ChildExtendsAnnotatedPojo extends ParentPojo { - @Override - public int getFoo() { return 0; } - - public String getMyString() { return "foo"; } - } - @AutoProperty(autoDetect=AutoDetectPolicy.METHOD, policy=DefaultPojomaticPolicy.EQUALS) private static abstract class ParentAutoPojo { public abstract int getFoo(); @@ -347,16 +336,7 @@ int bar(); @Property(policy=PojomaticPolicy.EQUALS) int baz(); } - - public static class ChildExtendsAutoPojo extends ParentAutoPojo { - @Property - public String other; - @Override public int getFoo() { return 2; } - - public String getBar() { return ""; } - } - public static class StaticField { @Property public static int a; } @@ -364,13 +344,9 @@ public static class StaticMethod { @Property public static int a() { return 1; } } - + private static Set<PropertyElement> asSet(PropertyElement... elements) { - HashSet<PropertyElement> result = new HashSet<PropertyElement>(); - for (PropertyElement element : elements) { - result.add(element); - } - return result; + return new HashSet<PropertyElement>(Arrays.asList(elements)); } private static Set<PropertyElement> asSet(Collection<PropertyElement> elements) { Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2009-09-07 21:35:12 UTC (rev 151) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2009-09-14 04:08:01 UTC (rev 152) @@ -32,9 +32,6 @@ private static Pojomator<IntProperty> INT_PROPERTY_POJOMATOR = makePojomatorImpl(IntProperty.class); - private static Pojomator<StringArrayProperty> STRING_ARRAY_PROPERTY_POJOMATOR = - makePojomatorImpl(StringArrayProperty.class); - private static final Pojomator<AccessCheckedProperties> ACCESS_CHECKED_PROPERTIES_POJOMATOR = makePojomatorImpl(AccessCheckedProperties.class); @@ -90,6 +87,13 @@ } @Test public void testObjectArrayPropertyEquals() { + class StringArrayProperty { + public StringArrayProperty(String... strings) { this.strings = strings; } + @Property String[] strings; + } + + Pojomator<StringArrayProperty> STRING_ARRAY_PROPERTY_POJOMATOR = makePojomatorImpl(StringArrayProperty.class); + String s1 = "hello"; String s2 = copyString(s1); assertTrue(STRING_ARRAY_PROPERTY_POJOMATOR.doEquals( @@ -360,14 +364,6 @@ @Property int i; } - public static class StringArrayProperty { - public StringArrayProperty(String... strings) { - this.strings = strings; - } - - @Property String[] strings; - } - public static class ExceptionThrowingProperty { @Property public int bomb() { throw new RuntimeException(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-07 21:35:18
|
Revision: 151 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=151&view=rev Author: iroberts Date: 2009-09-07 21:35:12 +0000 (Mon, 07 Sep 2009) Log Message: ----------- Fix javadoc Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2009-09-07 21:24:12 UTC (rev 150) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2009-09-07 21:35:12 UTC (rev 151) @@ -295,10 +295,10 @@ /** - * @param instance - * @param other - * @return true if the values of properties referenced by {@code prop} in {@code instance} and - * {@code other} are equal to each other. + * Compare two values for equality + * @param instanceValue the first value to compare + * @param otherValue the second value to compare + * @return true if {@code instanceValue} and {@code otherValue} are equal to each other. */ private static boolean areValuesEqual(Object instanceValue, Object otherValue) { if (instanceValue == null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-07 21:24:18
|
Revision: 150 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=150&view=rev Author: iroberts Date: 2009-09-07 21:24:12 +0000 (Mon, 07 Sep 2009) Log Message: ----------- comparative benchmarks, first take. While a submodule of PojomaticAll, it is not part of that pom's build. Added Paths: ----------- trunk/PojomaticAll/pojomatic-benchmark/ trunk/PojomaticAll/pojomatic-benchmark/pom.xml trunk/PojomaticAll/pojomatic-benchmark/src/ trunk/PojomaticAll/pojomatic-benchmark/src/main/ trunk/PojomaticAll/pojomatic-benchmark/src/main/java/ trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/ trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/ trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/Bean.java trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/BeanSpeedTest.java Property changes on: trunk/PojomaticAll/pojomatic-benchmark ___________________________________________________________________ Added: svn:ignore + pojomatic-benchmark.iml target Added: trunk/PojomaticAll/pojomatic-benchmark/pom.xml =================================================================== --- trunk/PojomaticAll/pojomatic-benchmark/pom.xml (rev 0) +++ trunk/PojomaticAll/pojomatic-benchmark/pom.xml 2009-09-07 21:24:12 UTC (rev 150) @@ -0,0 +1,23 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>pojomatic-all</artifactId> + <groupId>org.pojomatic</groupId> + <version>trunk-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>org.pojomatic</groupId> + <artifactId>pojomatic-benchmark</artifactId> + <packaging>jar</packaging> + <version>trunk-SNAPSHOT</version> + <name>pojomatic-benchmark</name> + <url>http://maven.apache.org</url> + <dependencies> + <dependency> + <groupId>org.pojomatic</groupId> + <artifactId>pojomatic</artifactId> + <version>trunk-SNAPSHOT</version> + </dependency> + </dependencies> +</project> Added: trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/Bean.java =================================================================== --- trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/Bean.java (rev 0) +++ trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/Bean.java 2009-09-07 21:24:12 UTC (rev 150) @@ -0,0 +1,312 @@ +package org.pojomatic; + +import java.util.Arrays; +import java.util.List; + +import org.pojomatic.Pojomatic; +import org.pojomatic.Pojomator; +import org.pojomatic.PropertyElement; +import org.pojomatic.annotations.AutoDetectPolicy; +import org.pojomatic.annotations.AutoProperty; +import org.pojomatic.internal.ClassProperties; + +@AutoProperty(autoDetect=AutoDetectPolicy.METHOD) +public class Bean { + private String string; + private int i; + private Integer integer; + private int[] ints; + private List<String> strings; + + private static PropertyElement getInteger, getString, getI, getInts, getStrings; + + static { + setUpPojomaticHandrolled(); + } + + private static void setUpPojomaticHandrolled() { + ClassProperties classProperties = ClassProperties.createInstance(Bean.class); + for (PropertyElement prop: classProperties.getHashCodeProperties()) { + if ("integer".equals(prop.getName())) { + getInteger = prop; + } + else if ("string".equals(prop.getName())) { + getString = prop; + } + else if ("i".equals(prop.getName())) { + getI = prop; + } + else if ("ints".equals(prop.getName())) { + getInts = prop; + } + else if ("strings".equals(prop.getName())) { + getStrings = prop; + } + else { + throw new RuntimeException("unexpected property: " + prop); + } + } + System.out.println(classProperties.getHashCodeProperties()); + } + + public String getString() { + return string; + } + public void setString(String string) { + this.string = string; + } + public int getI() { + return i; + } + public void setI(int i) { + this.i = i; + } + public Integer getInteger() { + return integer; + } + public void setInteger(Integer integer) { + this.integer = integer; + } + public int[] getInts() { + return ints; + } + public void setInts(int[] ints) { + this.ints = ints; + } + public List<String> getStrings() { + return strings; + } + public void setStrings(List<String> strings) { + this.strings = strings; + } + + public boolean pmequals(Object other) { + return Pojomatic.equals(this, other); + } + + public int pmHashCode() { + return Pojomatic.hashCode(this); + } + + private Pojomator<Bean> POJOMATOR = Pojomatic.pojomator(Bean.class); + + public boolean pmFastequals(Object other) { + return POJOMATOR.doEquals(this, other); + } + + public int pmFastHashCode() { + return POJOMATOR.doHashCode(this); + } + + public int handRolledPmHashCode() { + int hashCode = 1; + hashCode = 31 * hashCode + hashCodeOfValue(getInteger.getValue(this)); + hashCode = 31 * hashCode + hashCodeOfValue(getString.getValue(this)); + hashCode = 31 * hashCode + hashCodeOfValue(getI.getValue(this)); + hashCode = 31 * hashCode + hashCodeOfValue(getInts.getValue(this)); + hashCode = 31 * hashCode + hashCodeOfValue(getStrings.getValue(this)); + return hashCode; + } + + public boolean handRolledPmEquals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof Bean)) { + return false; + } + + return areValuesEqual(getInteger.getValue(this), getInteger.getValue(other)) + && areValuesEqual(getString.getValue(this), getString.getValue(other)) + && areValuesEqual(getI.getValue(this), getI.getValue(other)) + && areValuesEqual(getInts.getValue(this), getInts.getValue(other)) + && areValuesEqual(getStrings.getValue(this), getStrings.getValue(other)); + } + +private static boolean areValuesEqual(Object instanceValue, Object otherValue) { + if (instanceValue == null) { + if (otherValue != null) { + return false; + } + } + else { // instanceValue is not null + if (otherValue == null) { + return false; + } + if (!instanceValue.getClass().isArray()) { + if (!instanceValue.equals(otherValue)) { + return false; + } + } + else { + if (!otherValue.getClass().isArray()) { + return false; + } + Class<?> instanceComponentClass = instanceValue.getClass().getComponentType(); + Class<?> otherComponentClass = otherValue.getClass().getComponentType(); + + if (!instanceComponentClass.isPrimitive()) { + if (otherComponentClass.isPrimitive()) { + return false; + } + if (!Arrays.deepEquals((Object[]) instanceValue, (Object[]) otherValue)) { + return false; + } + } + else { // instanceComponentClass is primative + if (otherComponentClass != instanceComponentClass) { + return false; + } + + if (Boolean.TYPE == instanceComponentClass) { + if(!Arrays.equals((boolean[]) instanceValue, (boolean[]) otherValue)) { + return false; + } + } + else if (Byte.TYPE == instanceComponentClass) { + if (! Arrays.equals((byte[]) instanceValue, (byte[]) otherValue)) { + return false; + } + } + else if (Character.TYPE == instanceComponentClass) { + if(!Arrays.equals((char[]) instanceValue, (char[]) otherValue)) { + return false; + } + } + else if (Short.TYPE == instanceComponentClass) { + if(!Arrays.equals((short[]) instanceValue, (short[]) otherValue)) { + return false; + } + } + else if (Integer.TYPE == instanceComponentClass) { + if(!Arrays.equals((int[]) instanceValue, (int[]) otherValue)) { + return false; + } + } + else if (Long.TYPE == instanceComponentClass) { + if(!Arrays.equals((long[]) instanceValue, (long[]) otherValue)) { + return false; + } + } + else if (Float.TYPE == instanceComponentClass) { + if(!Arrays.equals((float[]) instanceValue, (float[]) otherValue)) { + return false; + } + } + else if (Double.TYPE == instanceComponentClass) { + if(!Arrays.equals((double[]) instanceValue, (double[]) otherValue)) { + return false; + } + } + else { + // should NEVER happen + throw new IllegalStateException( + "unknown primative type " + instanceComponentClass.getName()); + } + } + } + } + return true; +} + + private static int hashCodeOfValue(Object value) { + if (value == null) { + return 0; + } + else { + if (value.getClass().isArray()) { + Class<?> instanceComponentClass = value.getClass().getComponentType(); + if (! instanceComponentClass.isPrimitive()) { + return Arrays.hashCode((Object[]) value); + } + else { + if (Boolean.TYPE == instanceComponentClass) { + return Arrays.hashCode((boolean[]) value); + } + else if (Byte.TYPE == instanceComponentClass) { + return Arrays.hashCode((byte[]) value); + } + else if (Character.TYPE == instanceComponentClass) { + return Arrays.hashCode((char[]) value); + } + else if (Short.TYPE == instanceComponentClass) { + return Arrays.hashCode((short[]) value); + } + else if (Integer.TYPE == instanceComponentClass) { + return Arrays.hashCode((int[]) value); + } + else if (Long.TYPE == instanceComponentClass) { + return Arrays.hashCode((long[]) value); + } + else if (Float.TYPE == instanceComponentClass) { + return Arrays.hashCode((float[]) value); + } + else if (Double.TYPE == instanceComponentClass) { + return Arrays.hashCode((double[]) value); + } + else { + // should NEVER happen + throw new IllegalStateException( + "unknown primative type " + instanceComponentClass.getName()); + } + } + } + else { + return value.hashCode(); + } + } + } + + + @Override public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + i; + result = prime * result + ((integer == null) + ? 0 + : integer.hashCode()); + result = prime * result + Arrays.hashCode(ints); + result = prime * result + ((string == null) + ? 0 + : string.hashCode()); + result = prime * result + ((strings == null) + ? 0 + : strings.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final Bean other = (Bean) obj; + if (i != other.i) + return false; + if (integer == null) { + if (other.integer != null) + return false; + } + else if (!integer.equals(other.integer)) + return false; + if (!Arrays.equals(ints, other.ints)) + return false; + if (string == null) { + if (other.string != null) + return false; + } + else if (!string.equals(other.string)) + return false; + if (strings == null) { + if (other.strings != null) + return false; + } + else if (!strings.equals(other.strings)) + return false; + return true; + } + + +} Added: trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/BeanSpeedTest.java =================================================================== --- trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/BeanSpeedTest.java (rev 0) +++ trunk/PojomaticAll/pojomatic-benchmark/src/main/java/org/pojomatic/BeanSpeedTest.java 2009-09-07 21:24:12 UTC (rev 150) @@ -0,0 +1,125 @@ +package org.pojomatic; + +import java.util.Random; + +public class BeanSpeedTest { + private final static Random rand = new Random(); + + public static void main(String[] args) { + Bean[] beans = makeBeans(800); + BaseChecker[] checkers = new BaseChecker[] { + new StandardChecker(), + new PmChecker(), + new PmFastChecker(), + new PmHandRolledChecker(), + }; + + while(true) { + for (BaseChecker checker: checkers) { + long equalsStart = System.nanoTime(); + checker.checkEquals(beans); + long equalsElapsed = System.nanoTime() - equalsStart; + + long hashStart = System.nanoTime(); + checker.checkHashCode(beans); + long hashElapsed = System.nanoTime() - hashStart; + + long size = beans.length * beans.length; + System.out.println(equalsElapsed / size + + " - " + hashElapsed / size + + " - " + checker.getClass().getSimpleName()); + } + System.out.println(); + } + } + + private static Bean[] makeBeans(int beanCount) { + Bean[] beans = new Bean[beanCount]; + for (int i = 0; i < beanCount; i++) { + beans[i] = randomBean(); + } + return beans; + } + + private static Bean randomBean() { + Bean bean = new Bean(); + bean.setI(rand.nextInt()); + bean.setInteger(rand.nextInt()); + int[] ints = new int[0/*rand.nextInt(10)*/]; + for (int i = 0; i < ints.length; i++) { + ints[i] = rand.nextInt(); + } + bean.setInts(null); //ints); + bean.setString(String.valueOf(rand.nextDouble())); + String[] strings = new String[0]; //rand.nextInt(5)]; + for (int i = 0; i < strings.length; i++) { + strings[i] = String.valueOf(rand.nextInt()); + } + bean.setStrings(null); //Arrays.asList(strings)); + return bean; + } + + public static abstract class BaseChecker { + public void checkEquals(Bean[] beans) { + for (int i = 0; i < beans.length; i++) { + for (int j = 0; j < beans.length; j++) { + if (equals(beans[i], beans[j]) != (i == j)) { + System.out.println("error at " + i + ", " + j); + } + } + } + } + + public void checkHashCode(Bean[] beans) { + for (int i = 0; i < beans.length; i++) { + for (int j = 0; j < beans.length; j++) { + if ((hashCode(beans[i]) == hashCode(beans[j])) != (i == j)) { + System.out.println("error at " + i + ", " + j); + } + } + } + } + + protected abstract long hashCode(Bean bean); + + protected abstract boolean equals(Bean bean1, Bean bean2); + } + + public static class StandardChecker extends BaseChecker { + @Override protected boolean equals(Bean bean1, Bean bean2) { + return bean1.equals(bean2); + } + + @Override protected long hashCode(Bean bean) { + return bean.hashCode(); + } + } + + public static class PmChecker extends BaseChecker { + @Override protected boolean equals(Bean bean1, Bean bean2) { + return bean1.pmequals(bean2); + } + @Override protected long hashCode(Bean bean) { + return bean.pmHashCode(); + } + } + + public static class PmFastChecker extends BaseChecker { + @Override protected boolean equals(Bean bean1, Bean bean2) { + return bean1.pmFastequals(bean2); + } + @Override protected long hashCode(Bean bean) { + return bean.pmFastHashCode(); + } + } + + public static class PmHandRolledChecker extends BaseChecker { + @Override protected boolean equals(Bean bean1, Bean bean2) { + return bean1.handRolledPmEquals(bean2); + } + @Override protected long hashCode(Bean bean) { + return bean.handRolledPmHashCode(); + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-05 16:31:56
|
Revision: 149 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=149&view=rev Author: iroberts Date: 2009-09-05 16:31:50 +0000 (Sat, 05 Sep 2009) Log Message: ----------- OverridableMethods now tracks which property roles each method has, and will raise a fuss if a method which previously had equals and no hashCode has the hashCode role added. Part of fixing bug 2845939. This still needs documentation Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/OverridableMethodsTest.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java 2009-09-05 16:27:05 UTC (rev 148) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java 2009-09-05 16:31:50 UTC (rev 149) @@ -49,28 +49,26 @@ */ private ClassProperties(Class<?> pojoClass) throws IllegalArgumentException { if (pojoClass.isInterface()) { - extractClassProperties(pojoClass, makeOverridableMethods()); + extractClassProperties(pojoClass, new OverridableMethods()); } else { - walkHierarchy(pojoClass, makeOverridableMethods()); + walkHierarchy(pojoClass, new OverridableMethods()); } verifyPropertiesNotEmpty(pojoClass); } - - private void walkHierarchy( - Class<?> clazz, Map<PropertyRole, OverridableMethods> overridableMethods) { + + private void walkHierarchy(Class<?> clazz, OverridableMethods overridableMethods) { if (clazz != Object.class) { walkHierarchy(clazz.getSuperclass(), overridableMethods); extractClassProperties(clazz, overridableMethods); } } - private void extractClassProperties( - Class<?> clazz, Map<PropertyRole, OverridableMethods> overridableMethods) { + private void extractClassProperties(Class<?> clazz, OverridableMethods overridableMethods) { AutoProperty autoProperty = clazz.getAnnotation(AutoProperty.class); final DefaultPojomaticPolicy classPolicy = (autoProperty != null) ? autoProperty.policy() : null; - final AutoDetectPolicy autoDetectPolicy = + final AutoDetectPolicy autoDetectPolicy = (autoProperty != null) ? autoProperty.autoDetect() : null; extractFields(clazz, classPolicy, autoDetectPolicy); @@ -78,10 +76,10 @@ } private void extractMethods( - Class<?> clazz, + Class<?> clazz, final DefaultPojomaticPolicy classPolicy, final AutoDetectPolicy autoDetectPolicy, - final Map<PropertyRole, OverridableMethods> overridableMethods) { + final OverridableMethods overridableMethods) { for (Method method : clazz.getDeclaredMethods()) { Property property = method.getAnnotation(Property.class); if (isStatic(method)) { @@ -111,10 +109,9 @@ /* add all methods that are explicitly annotated or auto-detected, and not overriding already * added methods */ if (propertyPolicy != null || AutoDetectPolicy.METHOD == autoDetectPolicy) { - for (PropertyRole role : PropertyFilter.getRoles(propertyPolicy, classPolicy)) { - if(overridableMethods.get(role).checkAndMaybeAddMethod(method)) { - properties.get(role).add(new PropertyAccessor(method, getPropertyName(property))); - } + for (PropertyRole role : overridableMethods.checkAndMaybeAddRolesToMethod( + method, PropertyFilter.getRoles(propertyPolicy, classPolicy))) { + properties.get(role).add(new PropertyAccessor(method, getPropertyName(property))); } } } @@ -210,15 +207,4 @@ } return properties; } - - private Map<PropertyRole, OverridableMethods> makeOverridableMethods() { - Map<PropertyRole, OverridableMethods> overrideableMethods = - new EnumMap<PropertyRole, OverridableMethods>(PropertyRole.class); - for (PropertyRole role : PropertyRole.values()) { - overrideableMethods.put(role, new OverridableMethods()); - } - return overrideableMethods; - - } - } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java 2009-09-05 16:27:05 UTC (rev 148) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java 2009-09-05 16:31:50 UTC (rev 149) @@ -2,38 +2,65 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.HashSet; -import java.util.Set; +import java.util.*; /** * A mutable set of methods which can be overridden. All methods are assumed to take no arguments * and either public, protected or package private. */ class OverridableMethods { - /** - * Check a method to see if it is not an override; if not, add it to the collection of methods - * - * @param method the method to check and maybe add. It is assumed the method is not private. - * @return {@code true} if the method is not an override - */ - boolean checkAndMaybeAddMethod(Method method) { + + Set<PropertyRole> checkAndMaybeAddRolesToMethod(Method method, Set<PropertyRole> newRoles) { + Set<PropertyRole> existingRoles = findExistingRoles(method); + if (existingRoles.contains(PropertyRole.EQUALS) + && !existingRoles.contains(PropertyRole.HASH_CODE) + && newRoles.contains(PropertyRole.HASH_CODE)) { + throw new IllegalArgumentException( + "Method " + method.getDeclaringClass().getName() + "." + method.getName() + + " is requested to be included in hashCode computations, but already overrides a method" + + " which is requested for equals computations, but not hashCode computations."); + } + Set<PropertyRole> addedRoles = EnumSet.noneOf(PropertyRole.class); + for (PropertyRole role : newRoles) { + if (!existingRoles.contains(role)) { + addedRoles.add(role); + existingRoles.add(role); + } + } + return addedRoles; + } + + private Set<PropertyRole> findExistingRoles(Method method) { + Set<PropertyRole> existingRoles; if (isPackagePrivate(method)) { // This can only override another package private method - return packageMethods.add(new PackageMethod(method)); + PackageMethod key = new PackageMethod(method); + existingRoles = packageMethods.get(key); + if (existingRoles == null) { + existingRoles = EnumSet.noneOf(PropertyRole.class); + packageMethods.put(key, existingRoles); + } } else { // If there is a public method already declared, then this is an override. Otherwise, // we need to track it as a public override going forward, even if it is overriding a // superclass method which was declared package private. - return publicOrProtectedMethods.add(method.getName()) - && !packageMethods.contains(new PackageMethod(method)); + existingRoles = publicOrProtectedMethods.get(method.getName()); + if (existingRoles == null) { + existingRoles = packageMethods.get(new PackageMethod(method)); + } + if (existingRoles == null) { + existingRoles = EnumSet.noneOf(PropertyRole.class); + publicOrProtectedMethods.put(method.getName(), existingRoles); + } } + return existingRoles; } /** * A bean to track the package and name of a package-private method */ - private class PackageMethod { + private static class PackageMethod { PackageMethod(Method method) { name = method.getName(); pakage = method.getDeclaringClass().getPackage(); @@ -62,9 +89,12 @@ } } - private Set<String> publicOrProtectedMethods = new HashSet<String>(); - private Set<PackageMethod> packageMethods = new HashSet<PackageMethod>(); + private final Map<String, Set<PropertyRole>> publicOrProtectedMethods = + new HashMap<String, Set<PropertyRole>>(); + private final Map<PackageMethod, Set<PropertyRole>> packageMethods = + new HashMap<PackageMethod, Set<PropertyRole>>(); + private static boolean isPackagePrivate(Method method) { return !(Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())); Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/OverridableMethodsTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/OverridableMethodsTest.java 2009-09-05 16:27:05 UTC (rev 148) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/OverridableMethodsTest.java 2009-09-05 16:31:50 UTC (rev 149) @@ -3,6 +3,7 @@ import static org.junit.Assert.*; import java.lang.reflect.Method; +import java.util.EnumSet; import org.junit.Test; import org.pojomatic.internal.a.C1; @@ -10,8 +11,11 @@ import org.pojomatic.internal.b.C2; import org.pojomatic.internal.b.C4; - public class OverridableMethodsTest { + private static final EnumSet<PropertyRole> EQUALS_HASH_CODE = + EnumSet.of(PropertyRole.EQUALS, PropertyRole.HASH_CODE); + private static final EnumSet<PropertyRole> EQUALS = EnumSet.of(PropertyRole.EQUALS); + private static final EnumSet<PropertyRole> ALL = EnumSet.allOf(PropertyRole.class); @Test public void testPackagePrivate() throws Exception { checkMethod("packagePrivate", true, true, false, false); @@ -32,15 +36,86 @@ @Test public void testPublic() throws Exception { checkMethod("publicMethod", true, false, false, false); } - + + @Test + public void testEqualsThenEquals() throws Exception { + OverridableMethods overridableMethods = new OverridableMethods(); + assertEquals( + EQUALS, overridableMethods.checkAndMaybeAddRolesToMethod( + method(C1.class, "publicMethod"), EQUALS)); + assertEquals( + EnumSet.noneOf(PropertyRole.class), overridableMethods.checkAndMaybeAddRolesToMethod( + method(C2.class, "publicMethod"), EQUALS)); + } + + @Test + public void testEqualsThenToString() throws Exception { + OverridableMethods overridableMethods = new OverridableMethods(); + assertEquals( + EQUALS, overridableMethods.checkAndMaybeAddRolesToMethod( + method(C1.class, "publicMethod"), EQUALS)); + assertEquals( + EnumSet.of(PropertyRole.TO_STRING), overridableMethods.checkAndMaybeAddRolesToMethod( + method(C2.class, "publicMethod"), EnumSet.of(PropertyRole.TO_STRING))); + } + + @Test + public void testEqualsThenToEqualsString() throws Exception { + OverridableMethods overridableMethods = new OverridableMethods(); + assertEquals( + EQUALS, overridableMethods.checkAndMaybeAddRolesToMethod( + method(C1.class, "publicMethod"), EQUALS)); + assertEquals( + EnumSet.of(PropertyRole.TO_STRING), overridableMethods.checkAndMaybeAddRolesToMethod( + method(C2.class, "publicMethod"), EnumSet.of(PropertyRole.TO_STRING, PropertyRole.EQUALS))); + } + + @Test + public void testEqualsHashCodeThenEqualsHashCode() throws Exception { + OverridableMethods overridableMethods = new OverridableMethods(); + assertEquals( + EQUALS_HASH_CODE, overridableMethods.checkAndMaybeAddRolesToMethod( + method(C1.class, "publicMethod"), EQUALS_HASH_CODE)); + assertEquals( + EnumSet.noneOf(PropertyRole.class), overridableMethods.checkAndMaybeAddRolesToMethod( + method(C2.class, "publicMethod"), EQUALS_HASH_CODE)); + } + + @Test + public void testEqualsThenEqualsHashCode() throws Exception { + OverridableMethods overridableMethods = new OverridableMethods(); + assertEquals( + EQUALS, overridableMethods.checkAndMaybeAddRolesToMethod( + method(C1.class, "publicMethod"), EQUALS)); + try { + overridableMethods.checkAndMaybeAddRolesToMethod( + method(C2.class, "publicMethod"), EQUALS_HASH_CODE); + fail("Exception expected"); + } + catch (IllegalArgumentException e) { + assertEquals( + "Method org.pojomatic.internal.b.C2.publicMethod is requested to be included in hashCode" + + " computations, but already overrides a method which is requested for" + + " equals computations, but not hashCode computations.", e.getMessage()); + } + } + private void checkMethod( - String methodName, boolean c1Add, boolean c2Add, boolean c3Add, boolean c4Add) - throws Exception { + String methodName, boolean c1Add, boolean c2Add, boolean c3Add, boolean c4Add) + throws Exception { OverridableMethods overridableMethods = new OverridableMethods(); - assertEquals(c1Add, overridableMethods.checkAndMaybeAddMethod(method(C1.class, methodName))); - assertEquals(c2Add, overridableMethods.checkAndMaybeAddMethod(method(C2.class, methodName))); - assertEquals(c3Add, overridableMethods.checkAndMaybeAddMethod(method(C3.class, methodName))); - assertEquals(c4Add, overridableMethods.checkAndMaybeAddMethod(method(C4.class, methodName))); + assertEquals( + c1Add, !overridableMethods.checkAndMaybeAddRolesToMethod( + method(C1.class, methodName), ALL).isEmpty()); + assertEquals( + c2Add, !overridableMethods.checkAndMaybeAddRolesToMethod( + method(C2.class, methodName), ALL).isEmpty()); + assertEquals( + c3Add, !overridableMethods.checkAndMaybeAddRolesToMethod( + method(C3.class, methodName), ALL).isEmpty()); + assertEquals( + c4Add, !overridableMethods.checkAndMaybeAddRolesToMethod( + method(C4.class, methodName), ALL).isEmpty()); } private static Method method(Class<?> clazz, String name) throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-09-05 16:27:13
|
Revision: 148 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=148&view=rev Author: iroberts Date: 2009-09-05 16:27:05 +0000 (Sat, 05 Sep 2009) Log Message: ----------- switch tag to trunk-SNAPSHOT; upgrade cobertura to 2.3 Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/pom.xml trunk/PojomaticAll/PojomaticTestUtils/pom.xml trunk/PojomaticAll/pom.xml Modified: trunk/PojomaticAll/Pojomatic/pom.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/pom.xml 2009-08-30 17:02:28 UTC (rev 147) +++ trunk/PojomaticAll/Pojomatic/pom.xml 2009-09-05 16:27:05 UTC (rev 148) @@ -2,7 +2,7 @@ <parent> <artifactId>pojomatic-all</artifactId> <groupId>org.pojomatic</groupId> - <version>TestUtils-SNAPSHOT</version> + <version>trunk-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> Modified: trunk/PojomaticAll/PojomaticTestUtils/pom.xml =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/pom.xml 2009-08-30 17:02:28 UTC (rev 147) +++ trunk/PojomaticAll/PojomaticTestUtils/pom.xml 2009-09-05 16:27:05 UTC (rev 148) @@ -3,7 +3,7 @@ <parent> <artifactId>pojomatic-all</artifactId> <groupId>org.pojomatic</groupId> - <version>TestUtils-SNAPSHOT</version> + <version>trunk-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> Modified: trunk/PojomaticAll/pom.xml =================================================================== --- trunk/PojomaticAll/pom.xml 2009-08-30 17:02:28 UTC (rev 147) +++ trunk/PojomaticAll/pom.xml 2009-09-05 16:27:05 UTC (rev 148) @@ -3,7 +3,7 @@ <groupId>org.pojomatic</groupId> <artifactId>pojomatic-all</artifactId> <packaging>pom</packaging> - <version>TestUtils-SNAPSHOT</version> + <version>trunk-SNAPSHOT</version> <name>PojomaticAll</name> <description> Parent and aggregator for all artifacts related to the Pojomatic project. @@ -171,7 +171,7 @@ <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> - <version>2.2</version> + <version>2.3</version> </plugin> </plugins> </reporting> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2009-08-30 17:02:37
|
Revision: 147 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=147&view=rev Author: iroberts Date: 2009-08-30 17:02:28 +0000 (Sun, 30 Aug 2009) Log Message: ----------- Formatting Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java 2009-08-28 06:15:41 UTC (rev 146) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/OverridableMethods.java 2009-08-30 17:02:28 UTC (rev 147) @@ -6,12 +6,13 @@ import java.util.Set; /** - * A mutable set of methods which can be overridden. All methods are assumed to take no arguments + * A mutable set of methods which can be overridden. All methods are assumed to take no arguments * and either public, protected or package private. */ class OverridableMethods { /** * Check a method to see if it is not an override; if not, add it to the collection of methods + * * @param method the method to check and maybe add. It is assumed the method is not private. * @return {@code true} if the method is not an override */ @@ -24,11 +25,11 @@ // If there is a public method already declared, then this is an override. Otherwise, // we need to track it as a public override going forward, even if it is overriding a // superclass method which was declared package private. - return publicOrProtectedMethods.add(method.getName()) - && !packageMethods.contains(new PackageMethod(method)); + return publicOrProtectedMethods.add(method.getName()) + && !packageMethods.contains(new PackageMethod(method)); } } - + /** * A bean to track the package and name of a package-private method */ @@ -37,18 +38,22 @@ name = method.getName(); pakage = method.getDeclaringClass().getPackage(); } - + String name; Package pakage; - @Override public int hashCode() { + + @Override + public int hashCode() { return name.hashCode() * 31 + pakage.hashCode(); } - - @Override public boolean equals(Object obj) { - if (this == obj) + + @Override + public boolean equals(Object obj) { + if (this == obj) { return true; + } if (obj instanceof PackageMethod) { - PackageMethod other = (PackageMethod)obj; + PackageMethod other = (PackageMethod) obj; return name.equals(other.name) && pakage.equals(other.pakage); } else { @@ -56,13 +61,13 @@ } } } - + private Set<String> publicOrProtectedMethods = new HashSet<String>(); private Set<PackageMethod> packageMethods = new HashSet<PackageMethod>(); - + private static boolean isPackagePrivate(Method method) { - return !(Modifier.isPublic(method.getModifiers()) - || Modifier.isProtected(method.getModifiers())); + return !(Modifier.isPublic(method.getModifiers()) + || Modifier.isProtected(method.getModifiers())); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2009-08-28 06:15:48
|
Revision: 146 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=146&view=rev Author: chriswhansen Date: 2009-08-28 06:15:41 +0000 (Fri, 28 Aug 2009) Log Message: ----------- Created initial site docs for PojomaticAll. Added Paths: ----------- trunk/PojomaticAll/src/ trunk/PojomaticAll/src/site/ trunk/PojomaticAll/src/site/apt/ trunk/PojomaticAll/src/site/apt/index.apt Added: trunk/PojomaticAll/src/site/apt/index.apt =================================================================== --- trunk/PojomaticAll/src/site/apt/index.apt (rev 0) +++ trunk/PojomaticAll/src/site/apt/index.apt 2009-08-28 06:15:41 UTC (rev 146) @@ -0,0 +1,16 @@ + ------ + PojomaticAll + ------ + ------ + ------ + +{{{pojomatic/index.html}Pojomatic}} + + Pojomatic provides configurable implementations of the <<<equals(Object)>>>, <<<toString()>>> + and <<<hashCode()>>> methods inherited from <<<java.lang.Object>>>. + + For examples and a quick start guide, see the {{{pojomatic/index.html}pojomatic site}}. You can download Pojomatic from the {{{http://repo1.maven.org/maven2/org/pojomatic/}Maven central repository}} or {{{http://sourceforge.net/projects/pojomatic/files/}SourceForge}}. For more information, see the {{{http://sourceforge.net/projects/pojomatic/}SourceForge project page}}. + +{{{pojomatic-test-utils/index.html}Pojomatic Test Utils}} + + Pojomatic Test Utils provides utilities which are useful in testing classes which use Pojomatic. For example, it includes functionality to report the differences between two instances if they are not equal. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2009-08-28 04:18:12
|
Revision: 145 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=145&view=rev Author: chriswhansen Date: 2009-08-28 04:18:05 +0000 (Fri, 28 Aug 2009) Log Message: ----------- Merge TestUtils branch to trunk. svn merge -r 132:144 https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/branches/TestUtils . Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/pom.xml Added Paths: ----------- trunk/PojomaticAll/PojomaticTestUtils/ trunk/PojomaticAll/PojomaticTestUtils/.classpath trunk/PojomaticAll/PojomaticTestUtils/.project trunk/PojomaticAll/PojomaticTestUtils/.settings/ trunk/PojomaticAll/PojomaticTestUtils/.settings/org.eclipse.jdt.core.prefs trunk/PojomaticAll/PojomaticTestUtils/.settings/org.maven.ide.eclipse.prefs trunk/PojomaticAll/PojomaticTestUtils/pom.xml trunk/PojomaticAll/PojomaticTestUtils/src/ trunk/PojomaticAll/PojomaticTestUtils/src/main/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java trunk/PojomaticAll/PojomaticTestUtils/src/pmd.xml trunk/PojomaticAll/PojomaticTestUtils/src/test/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertUtilsTest.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/Container.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java trunk/PojomaticAll/pom.xml Removed Paths: ------------- trunk/PojomaticAll/PojomaticTestUtils/.classpath trunk/PojomaticAll/PojomaticTestUtils/.project trunk/PojomaticAll/PojomaticTestUtils/.settings/ trunk/PojomaticAll/PojomaticTestUtils/.settings/org.eclipse.jdt.core.prefs trunk/PojomaticAll/PojomaticTestUtils/.settings/org.maven.ide.eclipse.prefs trunk/PojomaticAll/PojomaticTestUtils/pom.xml trunk/PojomaticAll/PojomaticTestUtils/src/ trunk/PojomaticAll/PojomaticTestUtils/src/main/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java trunk/PojomaticAll/PojomaticTestUtils/src/pmd.xml trunk/PojomaticAll/PojomaticTestUtils/src/test/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertUtilsTest.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/Container.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java Property Changed: ---------------- trunk/PojomaticAll/ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectPolicy.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/DefaultPojomaticPolicy.java Property changes on: trunk/PojomaticAll ___________________________________________________________________ Added: svn:ignore + target Added: svn:mergeinfo + /branches/TestUtils:133-144 Modified: trunk/PojomaticAll/Pojomatic/pom.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/pom.xml 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/Pojomatic/pom.xml 2009-08-28 04:18:05 UTC (rev 145) @@ -1,142 +1,27 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>pojomatic-all</artifactId> + <groupId>org.pojomatic</groupId> + <version>TestUtils-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> <modelVersion>4.0.0</modelVersion> - <groupId>org.pojomatic</groupId> <artifactId>pojomatic</artifactId> <packaging>jar</packaging> - <version>trunk-SNAPSHOT</version> <name>Pojomatic</name> <description> Automatically provides configurable implementations of the equals(Object), toString() and hashCode() methods inherited from java.lang.Object </description> - <url>http://www.pojomatic.org</url> - <inceptionYear>2008</inceptionYear> <scm> - <connection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/Pojomatic</connection> - <developerConnection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/Pojomatic</developerConnection> - <url>https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/Pojomatic</url> + <connection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/pojomatic-all/pojomatic</connection> + <developerConnection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/pojomatic-all/pojomatic</developerConnection> + <url>https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/pojomatic-all/pojomatic</url> </scm> - <developers> - <developer> - <name>Ian Robertson</name> - <roles> - <role>Lead Developer</role> - </roles> - <email>ian...@gm...</email> - <id>ian.b.robertson</id> - <organization>Overstock.com</organization> - <organizationUrl>http://www.overstock.com</organizationUrl> - <url>http://www.artima.com/weblogs/index.jsp?blogger=ianr</url> - </developer> - <developer> - <name>Chris Hansen</name> - <roles> - <role>Lead Developer</role> - </roles> - <email>han...@gm...</email> - <id>hansen.chris.w</id> - <organization>Overstock.com</organization> - <organizationUrl>http://www.overstock.com</organizationUrl> - <url>http://polyglot-window.blogspot.com/</url> - </developer> - </developers> - <licenses> - <license> - <name>Apache License 2.0</name> - <url>http://www.apache.org/licenses/LICENSE-2.0</url> - <distribution>repo</distribution> - </license> - </licenses> - <issueManagement> - <system>Sourceforge</system> - <url>https://sourceforge.net/tracker/?func=browse&group_id=239113</url> - </issueManagement> - <distributionManagement> - <repository> - <id>pojomatic-releases</id> - <name>Pojomatic Release Repository</name> - <url>sftp://web.sourceforge.net/home/groups/p/po/pojomatic/releases</url> - </repository> - <snapshotRepository> - <id>pojomatic-snapshots</id> - <name>Pojomatic snapshot Repository</name> - <url>sftp://web.sourceforge.net/home/groups/p/po/pojomatic/snapshots</url> - </snapshotRepository> - <site> - <id>pojomatic-site</id> - <name>Pojomatic</name> - <!-- before deploying, you'll need to run ssh <username>,poj...@sh... create --> - <url>scp://shell.sourceforge.net/home/groups/p/po/pojomatic/htdocs</url> - </site> - </distributionManagement> - <mailingLists> - <mailingList> - <archive>http://sourceforge.net/mailarchive/forum.php?forum_name=pojomatic-users</archive> - <name>pojomatic-users</name> - <post>poj...@li...</post> - <subscribe>http://lists.sourceforge.net/mailman/listinfo/pojomatic-users</subscribe> - <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/pojomatic-users</unsubscribe> - </mailingList> - </mailingLists> - <build> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.0.2</version> - <configuration> - <source>1.5</source> - <target>1.5</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.4.2</version> - <configuration> - <excludes> - <exclude>**/TestUtils.java</exclude> - <exclude>examples/*.java</exclude> - </excludes> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-release-plugin</artifactId> - <version>2.0-beta-9</version> - </plugin> - </plugins> - </build> - <reporting> <plugins> <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <version>2.4</version> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-site-plugin</artifactId> - <version>2.0-beta-5</version> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>findbugs-maven-plugin</artifactId> - <version>1.1.1</version> - <configuration> - <excludeFilterFile>${basedir}/FindBugsFilter.xml</excludeFilterFile> - </configuration> - </plugin> - <plugin> - <artifactId>maven-surefire-report-plugin</artifactId> - <version>2.4.2</version> - </plugin> - <plugin> - <artifactId>maven-jxr-plugin</artifactId> - <version>2.1</version> - </plugin> - <plugin> <artifactId>maven-pmd-plugin</artifactId> <configuration> <targetJdk>1.5</targetJdk> @@ -146,19 +31,6 @@ <includeTests>true</includeTests> </configuration> </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>cobertura-maven-plugin</artifactId> - <version>2.2</version> - </plugin> </plugins> </reporting> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - <scope>test</scope> - </dependency> - </dependencies> </project> Property changes on: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/AutoDetectPolicy.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/DefaultPojomaticPolicy.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/PojomaticAll/PojomaticTestUtils ___________________________________________________________________ Added: svn:ignore + target Deleted: trunk/PojomaticAll/PojomaticTestUtils/.classpath =================================================================== --- branches/TestUtils/PojomaticTestUtils/.classpath 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/.classpath 2009-08-28 04:18:05 UTC (rev 145) @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" output="target/classes" path="src/main/java"/> - <classpathentry kind="src" output="target/test-classes" path="src/test/java"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> - <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> - <classpathentry kind="output" path="target/classes"/> -</classpath> Copied: trunk/PojomaticAll/PojomaticTestUtils/.classpath (from rev 144, branches/TestUtils/PojomaticTestUtils/.classpath) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/.classpath (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/.classpath 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" output="target/classes" path="src/main/java"/> + <classpathentry kind="src" output="target/test-classes" path="src/test/java"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> Deleted: trunk/PojomaticAll/PojomaticTestUtils/.project =================================================================== --- branches/TestUtils/PojomaticTestUtils/.project 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/.project 2009-08-28 04:18:05 UTC (rev 145) @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>PojomaticTestUtils</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.iam.jdt.core.mavenIncrementalBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.maven.ide.eclipse.maven2Builder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.maven.ide.eclipse.maven2Nature</nature> - <nature>org.eclipse.iam.jdt.core.mavenNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> Copied: trunk/PojomaticAll/PojomaticTestUtils/.project (from rev 144, branches/TestUtils/PojomaticTestUtils/.project) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/.project (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/.project 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>PojomaticTestUtils</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.iam.jdt.core.mavenIncrementalBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.maven.ide.eclipse.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.maven.ide.eclipse.maven2Nature</nature> + <nature>org.eclipse.iam.jdt.core.mavenNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> Deleted: trunk/PojomaticAll/PojomaticTestUtils/.settings/org.eclipse.jdt.core.prefs =================================================================== --- branches/TestUtils/PojomaticTestUtils/.settings/org.eclipse.jdt.core.prefs 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/.settings/org.eclipse.jdt.core.prefs 2009-08-28 04:18:05 UTC (rev 145) @@ -1,12 +0,0 @@ -#Thu Aug 06 23:32:41 MDT 2009 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 Copied: trunk/PojomaticAll/PojomaticTestUtils/.settings/org.eclipse.jdt.core.prefs (from rev 144, branches/TestUtils/PojomaticTestUtils/.settings/org.eclipse.jdt.core.prefs) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/.settings/org.eclipse.jdt.core.prefs (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/.settings/org.eclipse.jdt.core.prefs 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,12 @@ +#Thu Aug 06 23:32:41 MDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 Deleted: trunk/PojomaticAll/PojomaticTestUtils/.settings/org.maven.ide.eclipse.prefs =================================================================== --- branches/TestUtils/PojomaticTestUtils/.settings/org.maven.ide.eclipse.prefs 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/.settings/org.maven.ide.eclipse.prefs 2009-08-28 04:18:05 UTC (rev 145) @@ -1,9 +0,0 @@ -#Thu Aug 06 23:37:24 MDT 2009 -activeProfiles= -eclipse.preferences.version=1 -fullBuildGoals=process-test-resources -includeModules=false -resolveWorkspaceProjects=true -resourceFilterGoals=process-resources resources\:testResources -skipCompilerPlugin=true -version=1 Copied: trunk/PojomaticAll/PojomaticTestUtils/.settings/org.maven.ide.eclipse.prefs (from rev 144, branches/TestUtils/PojomaticTestUtils/.settings/org.maven.ide.eclipse.prefs) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/.settings/org.maven.ide.eclipse.prefs (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/.settings/org.maven.ide.eclipse.prefs 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,9 @@ +#Thu Aug 06 23:37:24 MDT 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 Deleted: trunk/PojomaticAll/PojomaticTestUtils/pom.xml =================================================================== --- branches/TestUtils/PojomaticTestUtils/pom.xml 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/pom.xml 2009-08-28 04:18:05 UTC (rev 145) @@ -1,41 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <artifactId>pojomatic-all</artifactId> - <groupId>org.pojomatic</groupId> - <version>TestUtils-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - <artifactId>pojomatic-test-utils</artifactId> - <packaging>jar</packaging> - <name>PojomaticTestUtils</name> - <description> - Utilities to help with writing tests for, or using, classes which use Pojomatic. - For example, this library includes classes with JUnit and TestNG style - assertEquals methods which include differences (via Pojomatic.diff(Object, Object)) - in the error message if the assertion fails. - </description> - - <dependencies> - <dependency> - <groupId>org.pojomatic</groupId> - <artifactId>pojomatic</artifactId> - </dependency> - </dependencies> - - <reporting> - <plugins> - <plugin> - <artifactId>maven-pmd-plugin</artifactId> - <configuration> - <targetJdk>1.5</targetJdk> - <rulesets> - <ruleset>${project.basedir}/src/pmd.xml</ruleset> - </rulesets> - <includeTests>true</includeTests> - </configuration> - </plugin> - </plugins> - </reporting> -</project> Copied: trunk/PojomaticAll/PojomaticTestUtils/pom.xml (from rev 144, branches/TestUtils/PojomaticTestUtils/pom.xml) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/pom.xml (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/pom.xml 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,41 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>pojomatic-all</artifactId> + <groupId>org.pojomatic</groupId> + <version>TestUtils-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>pojomatic-test-utils</artifactId> + <packaging>jar</packaging> + <name>PojomaticTestUtils</name> + <description> + Utilities to help with writing tests for, or using, classes which use Pojomatic. + For example, this library includes classes with JUnit and TestNG style + assertEquals methods which include differences (via Pojomatic.diff(Object, Object)) + in the error message if the assertion fails. + </description> + + <dependencies> + <dependency> + <groupId>org.pojomatic</groupId> + <artifactId>pojomatic</artifactId> + </dependency> + </dependencies> + + <reporting> + <plugins> + <plugin> + <artifactId>maven-pmd-plugin</artifactId> + <configuration> + <targetJdk>1.5</targetJdk> + <rulesets> + <ruleset>${project.basedir}/src/pmd.xml</ruleset> + </rulesets> + <includeTests>true</includeTests> + </configuration> + </plugin> + </plugins> + </reporting> +</project> Deleted: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java 2009-08-28 04:18:05 UTC (rev 145) @@ -1,42 +0,0 @@ -package org.pojomatic.junit; - -import org.pojomatic.Pojomatic; -import org.pojomatic.test.AssertUtils; - -/** - * Pojomatic-related JUnit-style assertion methods useful for writing tests. - * @see org.junit.Assert - */ -public class PojomaticAssert { - - /** - * Asserts that two possibly {@code null} objects are equal according to - * {@link Object#equals(Object)}. If not, the differences, - * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. - * - * @param expected the expected object - * @param actual the object which should be tested to equal the expected object - * @throws AssertionError if the objects are not equal, with details of the differences - * included in the message - * @see #assertEqualsWithDiff(Object, Object, String) - */ - public static void assertEqualsWithDiff(Object expected, Object actual) { - assertEqualsWithDiff(expected, actual, null); - } - - /** - * Asserts that two possibly {@code null} objects are equal according to - * {@link Object#equals(Object)}. If not, the differences, - * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. - * - * @param expected the expected object - * @param actual the object which should be tested to equal the expected object - * @throws AssertionError if the objects are not equal, with details of the differences - * included in the message - */ - public static void assertEqualsWithDiff(Object expected, Object actual, String message) { - AssertUtils.assertEquals(message, expected, actual); - } - - private PojomaticAssert() {} -} Copied: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java (from rev 144, branches/TestUtils/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,42 @@ +package org.pojomatic.junit; + +import org.pojomatic.Pojomatic; +import org.pojomatic.test.AssertUtils; + +/** + * Pojomatic-related JUnit-style assertion methods useful for writing tests. + * @see org.junit.Assert + */ +public class PojomaticAssert { + + /** + * Asserts that two possibly {@code null} objects are equal according to + * {@link Object#equals(Object)}. If not, the differences, + * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. + * + * @param expected the expected object + * @param actual the object which should be tested to equal the expected object + * @throws AssertionError if the objects are not equal, with details of the differences + * included in the message + * @see #assertEqualsWithDiff(Object, Object, String) + */ + public static void assertEqualsWithDiff(Object expected, Object actual) { + assertEqualsWithDiff(expected, actual, null); + } + + /** + * Asserts that two possibly {@code null} objects are equal according to + * {@link Object#equals(Object)}. If not, the differences, + * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. + * + * @param expected the expected object + * @param actual the object which should be tested to equal the expected object + * @throws AssertionError if the objects are not equal, with details of the differences + * included in the message + */ + public static void assertEqualsWithDiff(Object expected, Object actual, String message) { + AssertUtils.assertEquals(message, expected, actual); + } + + private PojomaticAssert() {} +} Deleted: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2009-08-28 04:18:05 UTC (rev 145) @@ -1,55 +0,0 @@ -package org.pojomatic.test; - -import org.pojomatic.Pojomatic; -import org.pojomatic.diff.Differences; - -/** - * This class is not meant to be a part of the public API. - */ -public class AssertUtils { - - /** - * Determines if two possibly {@code null} objects are equal. - * - * @return {@code true} if both objects are null, - * or {@code first} is non-null and {@code first.equals(second)}, - * {@code false} otherwise - * @see Object#equals(Object) - */ - public static boolean equal(Object first, Object second) { - if (first == null && second == null) { - return true; - } - if (first != null && first.equals(second)) { - return true; - } - return false; - } - - /** - * Asserts that the objects are equal via {@link #equal(Object, Object)}. - * - * @param message the message to add if the assertion fails - * @param first will be displayed first if the assertion fails - * @param second will be displayed second if the assertion fails - * @throws AssertionError if the objects are not equal. {@link AssertionError#getMessage()} will - * include information about the differences - */ - public static void assertEquals(String message, Object first, Object second) { - if (!equal(first, second)) { - throw new AssertionError(buildMessage(message, Pojomatic.diff(first, second))); - } - } - - private static String buildMessage(String message, Differences differences) { - String formatted = ""; - if (message != null) { - formatted = message + " "; - } - - return formatted + differences.toString(); - } - - private AssertUtils() {} - -} Copied: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java (from rev 144, branches/TestUtils/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,55 @@ +package org.pojomatic.test; + +import org.pojomatic.Pojomatic; +import org.pojomatic.diff.Differences; + +/** + * This class is not meant to be a part of the public API. + */ +public class AssertUtils { + + /** + * Determines if two possibly {@code null} objects are equal. + * + * @return {@code true} if both objects are null, + * or {@code first} is non-null and {@code first.equals(second)}, + * {@code false} otherwise + * @see Object#equals(Object) + */ + public static boolean equal(Object first, Object second) { + if (first == null && second == null) { + return true; + } + if (first != null && first.equals(second)) { + return true; + } + return false; + } + + /** + * Asserts that the objects are equal via {@link #equal(Object, Object)}. + * + * @param message the message to add if the assertion fails + * @param first will be displayed first if the assertion fails + * @param second will be displayed second if the assertion fails + * @throws AssertionError if the objects are not equal. {@link AssertionError#getMessage()} will + * include information about the differences + */ + public static void assertEquals(String message, Object first, Object second) { + if (!equal(first, second)) { + throw new AssertionError(buildMessage(message, Pojomatic.diff(first, second))); + } + } + + private static String buildMessage(String message, Differences differences) { + String formatted = ""; + if (message != null) { + formatted = message + " "; + } + + return formatted + differences.toString(); + } + + private AssertUtils() {} + +} Deleted: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java 2009-08-28 04:18:05 UTC (rev 145) @@ -1,44 +0,0 @@ -package org.pojomatic.testng; - -import org.pojomatic.Pojomatic; -import org.pojomatic.test.AssertUtils; - -/** - * Pojomatic-related TestNG-style assertion methods useful for writing tests. - * @see org.testng.Assert - */ -public class PojomaticAssert { - - /** - * Asserts that two possibly {@code null} objects are equal according to - * {@link Object#equals(Object)}. If not, the differences, - * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. - * - * @param expected the expected object - * @param actual the object which should be tested to equal the expected object - * @throws AssertionError if the objects are not equal, with details of the differences - * included in the message - * @see #assertEqualsWithDiff(Object, Object, String) - */ - public static void assertEqualsWithDiff(Object actual, Object expected) { - assertEqualsWithDiff(actual, expected, null); - } - - /** - * Asserts that two possibly {@code null} objects are equal according to - * {@link Object#equals(Object)}. If not, the differences, - * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. - * - * @param expected the expected object - * @param actual the object which should be tested to equal the expected object - * @param message an optional message provided along with the diff if the objects are not equal - * @throws AssertionError if the objects are not equal, with details of the differences - * included in the message - */ - public static void assertEqualsWithDiff(Object actual, Object expected, String message) { - //the arguments are passed as follows according to display order for a potential error message - AssertUtils.assertEquals(message, expected, actual); - } - - private PojomaticAssert() {} -} Copied: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java (from rev 144, branches/TestUtils/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,44 @@ +package org.pojomatic.testng; + +import org.pojomatic.Pojomatic; +import org.pojomatic.test.AssertUtils; + +/** + * Pojomatic-related TestNG-style assertion methods useful for writing tests. + * @see org.testng.Assert + */ +public class PojomaticAssert { + + /** + * Asserts that two possibly {@code null} objects are equal according to + * {@link Object#equals(Object)}. If not, the differences, + * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. + * + * @param expected the expected object + * @param actual the object which should be tested to equal the expected object + * @throws AssertionError if the objects are not equal, with details of the differences + * included in the message + * @see #assertEqualsWithDiff(Object, Object, String) + */ + public static void assertEqualsWithDiff(Object actual, Object expected) { + assertEqualsWithDiff(actual, expected, null); + } + + /** + * Asserts that two possibly {@code null} objects are equal according to + * {@link Object#equals(Object)}. If not, the differences, + * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. + * + * @param expected the expected object + * @param actual the object which should be tested to equal the expected object + * @param message an optional message provided along with the diff if the objects are not equal + * @throws AssertionError if the objects are not equal, with details of the differences + * included in the message + */ + public static void assertEqualsWithDiff(Object actual, Object expected, String message) { + //the arguments are passed as follows according to display order for a potential error message + AssertUtils.assertEquals(message, expected, actual); + } + + private PojomaticAssert() {} +} Deleted: trunk/PojomaticAll/PojomaticTestUtils/src/pmd.xml =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/pmd.xml 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/src/pmd.xml 2009-08-28 04:18:05 UTC (rev 145) @@ -1,31 +0,0 @@ -<?xml version="1.0"?> -<ruleset name="Custom ruleset" - xmlns="http://pmd.sf.net/ruleset/1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" - xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> - - <description> - This ruleset checks my code for bad stuff - </description> - - <rule ref="rulesets/basic.xml"> - <exclude name="EmptyCatchBlock"/> - <exclude name="EmptyWhileStmt"/> - </rule> - <rule ref="rulesets/basic.xml/EmptyCatchBlock"> - <properties> - <property name="allowCommentedBlocks" value="true"/> - </properties> - </rule> - - <rule ref="rulesets/strings.xml"> - <exclude name="AvoidDuplicateLiterals"/> - </rule> - <rule ref="rulesets/unusedcode.xml"/> - <rule ref="rulesets/imports.xml"> - <exclude name="UnusedImports"/> - </rule> - <rule ref="rulesets/braces.xml"/> -</ruleset> - Copied: trunk/PojomaticAll/PojomaticTestUtils/src/pmd.xml (from rev 144, branches/TestUtils/PojomaticTestUtils/src/pmd.xml) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/pmd.xml (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/pmd.xml 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<ruleset name="Custom ruleset" + xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <description> + This ruleset checks my code for bad stuff + </description> + + <rule ref="rulesets/basic.xml"> + <exclude name="EmptyCatchBlock"/> + <exclude name="EmptyWhileStmt"/> + </rule> + <rule ref="rulesets/basic.xml/EmptyCatchBlock"> + <properties> + <property name="allowCommentedBlocks" value="true"/> + </properties> + </rule> + + <rule ref="rulesets/strings.xml"> + <exclude name="AvoidDuplicateLiterals"/> + </rule> + <rule ref="rulesets/unusedcode.xml"/> + <rule ref="rulesets/imports.xml"> + <exclude name="UnusedImports"/> + </rule> + <rule ref="rulesets/braces.xml"/> +</ruleset> + Deleted: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java 2009-08-28 04:18:05 UTC (rev 145) @@ -1,12 +0,0 @@ -package org.pojomatic.junit; - -import org.pojomatic.test.AssertTest; - -public class PojomaticAssertTest extends AssertTest { - - @Override - protected void performAssertEquals(Object first, Object second) { - PojomaticAssert.assertEqualsWithDiff(first, second); - } - -} Copied: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java (from rev 144, branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,12 @@ +package org.pojomatic.junit; + +import org.pojomatic.test.AssertTest; + +public class PojomaticAssertTest extends AssertTest { + + @Override + protected void performAssertEquals(Object first, Object second) { + PojomaticAssert.assertEqualsWithDiff(first, second); + } + +} Deleted: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java 2009-08-28 04:18:05 UTC (rev 145) @@ -1,92 +0,0 @@ -package org.pojomatic.test; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.pojomatic.Pojomatic; -import org.pojomatic.junit.PojomaticAssert; - -/** - * Tests assertion methods such as assertEquals(Object, Object) for correctness of assertions. - */ -public abstract class AssertTest { - - /** - * Only the unit under test should throw {@link AssertionError}, so no assertions are allowed - * within the implementation of this method. - * - * @param first the object which should appear first if the assertion fails. Note that this - * could be either "expected" or "actual". - * @param second the object which should appear second if the assertion fails. Note that this - * could be either "expected" or "actual". - */ - protected abstract void performAssertEquals(Object first, Object second); - - @Test - public final void assertEqualsBothNull() { - performAssertEquals(null, null); - } - - @Test(expected=AssertionError.class) - public final void assertEqualsNullExpected() { - performAssertEquals(null, new Container(null)); - } - - @Test(expected=AssertionError.class) - public final void assertEqualsNullActual() { - performAssertEquals(new Container(null), null); - } - - /** - * Tests that {@link PojomaticAssert#assertEqualsWithDiff(Object, Object)} - * uses {@link Object#equals(Object)} instead of {@link Pojomatic#equals(Object, Object)}. - */ - @Test(expected=AssertionError.class) - public final void assertEqualsViaInheritedEquals() { - //create objects which are never equal via Object.equals(Object), but are equal via - //Pojomatic.equals(Object, Object) - OnlyPojomaticEqual first = new OnlyPojomaticEqual(); - OnlyPojomaticEqual second = new OnlyPojomaticEqual(); - - performAssertEquals(first, second); - } - - @Test - public final void assertEqualsMessagingOrder() { - String first = "foo"; - String second = "bar"; - try { - performAssertEquals(new Container(first), new Container(second)); - } - catch (AssertionError e) { - //expected, check the message - assertAppearanceOrder(e.getMessage(), first, second); - } - } - - /** - * Asserts that {@code first} appears before {@code second} in {@code text}. - * - * @param text must contain both {@code first} and {@code second} - * @param first cannot be {@code null} - * @param second cannot be {@code null} - * @throws NullPointerException if {@code first} or {@code second} is {@code null} - * @throws IllegalArgumentException if {@code text} does not contain both - * {@code first} and {@code second} - */ - protected final void assertAppearanceOrder(String text, String first, String second) { - if (first == null || second == null) { - throw new NullPointerException(); - } - int firstIndex = text.indexOf(first); - int secondIndex = text.indexOf(second); - if (firstIndex < 0 || secondIndex < 0) { - throw new IllegalArgumentException("The string \"" + text + "\" does not conatin " + - "both \"" + first + "\" and \"" + second + "\""); - } - String message = "In the string \"" + text + "\", " + - "\"" + first + "\" should come before \"" + second + "\""; - assertTrue(message, firstIndex < secondIndex); - } - -} Copied: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java (from rev 144, branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,92 @@ +package org.pojomatic.test; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.pojomatic.Pojomatic; +import org.pojomatic.junit.PojomaticAssert; + +/** + * Tests assertion methods such as assertEquals(Object, Object) for correctness of assertions. + */ +public abstract class AssertTest { + + /** + * Only the unit under test should throw {@link AssertionError}, so no assertions are allowed + * within the implementation of this method. + * + * @param first the object which should appear first if the assertion fails. Note that this + * could be either "expected" or "actual". + * @param second the object which should appear second if the assertion fails. Note that this + * could be either "expected" or "actual". + */ + protected abstract void performAssertEquals(Object first, Object second); + + @Test + public final void assertEqualsBothNull() { + performAssertEquals(null, null); + } + + @Test(expected=AssertionError.class) + public final void assertEqualsNullExpected() { + performAssertEquals(null, new Container(null)); + } + + @Test(expected=AssertionError.class) + public final void assertEqualsNullActual() { + performAssertEquals(new Container(null), null); + } + + /** + * Tests that {@link PojomaticAssert#assertEqualsWithDiff(Object, Object)} + * uses {@link Object#equals(Object)} instead of {@link Pojomatic#equals(Object, Object)}. + */ + @Test(expected=AssertionError.class) + public final void assertEqualsViaInheritedEquals() { + //create objects which are never equal via Object.equals(Object), but are equal via + //Pojomatic.equals(Object, Object) + OnlyPojomaticEqual first = new OnlyPojomaticEqual(); + OnlyPojomaticEqual second = new OnlyPojomaticEqual(); + + performAssertEquals(first, second); + } + + @Test + public final void assertEqualsMessagingOrder() { + String first = "foo"; + String second = "bar"; + try { + performAssertEquals(new Container(first), new Container(second)); + } + catch (AssertionError e) { + //expected, check the message + assertAppearanceOrder(e.getMessage(), first, second); + } + } + + /** + * Asserts that {@code first} appears before {@code second} in {@code text}. + * + * @param text must contain both {@code first} and {@code second} + * @param first cannot be {@code null} + * @param second cannot be {@code null} + * @throws NullPointerException if {@code first} or {@code second} is {@code null} + * @throws IllegalArgumentException if {@code text} does not contain both + * {@code first} and {@code second} + */ + protected final void assertAppearanceOrder(String text, String first, String second) { + if (first == null || second == null) { + throw new NullPointerException(); + } + int firstIndex = text.indexOf(first); + int secondIndex = text.indexOf(second); + if (firstIndex < 0 || secondIndex < 0) { + throw new IllegalArgumentException("The string \"" + text + "\" does not conatin " + + "both \"" + first + "\" and \"" + second + "\""); + } + String message = "In the string \"" + text + "\", " + + "\"" + first + "\" should come before \"" + second + "\""; + assertTrue(message, firstIndex < secondIndex); + } + +} Deleted: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertUtilsTest.java =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertUtilsTest.java 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertUtilsTest.java 2009-08-28 04:18:05 UTC (rev 145) @@ -1,40 +0,0 @@ -package org.pojomatic.test; - -import static org.junit.Assert.*; - -import org.junit.Test; - -public class AssertUtilsTest extends AssertTest { - - @Override - protected void performAssertEquals(Object first, Object second) { - AssertUtils.assertEquals(null, first, second); - } - - @Test - public void testEquals() { - assertTrue(AssertUtils.equal(new Container(""), new Container(""))); - } - - @Test - public void testEqualsReflexive() { - Container instance = new Container(""); - assertTrue(AssertUtils.equal(instance, instance)); - } - - @Test - public void testEqualsBothNull() { - assertTrue(AssertUtils.equal(null, null)); - } - - @Test - public void testEqualsNullFirst() { - assertFalse(AssertUtils.equal(null, new Container(null))); - } - - @Test - public void testEqualsNullSecond() { - assertFalse(AssertUtils.equal(new Container(null), null)); - } - -} Copied: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertUtilsTest.java (from rev 144, branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertUtilsTest.java) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertUtilsTest.java (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertUtilsTest.java 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,40 @@ +package org.pojomatic.test; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class AssertUtilsTest extends AssertTest { + + @Override + protected void performAssertEquals(Object first, Object second) { + AssertUtils.assertEquals(null, first, second); + } + + @Test + public void testEquals() { + assertTrue(AssertUtils.equal(new Container(""), new Container(""))); + } + + @Test + public void testEqualsReflexive() { + Container instance = new Container(""); + assertTrue(AssertUtils.equal(instance, instance)); + } + + @Test + public void testEqualsBothNull() { + assertTrue(AssertUtils.equal(null, null)); + } + + @Test + public void testEqualsNullFirst() { + assertFalse(AssertUtils.equal(null, new Container(null))); + } + + @Test + public void testEqualsNullSecond() { + assertFalse(AssertUtils.equal(new Container(null), null)); + } + +} Deleted: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/Container.java =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/test/Container.java 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/Container.java 2009-08-28 04:18:05 UTC (rev 145) @@ -1,37 +0,0 @@ -package org.pojomatic.test; - -import org.pojomatic.Pojomatic; -import org.pojomatic.annotations.AutoProperty; - -/** - * Simple one-object container for use in tests. - */ -@AutoProperty -public class Container { - - private final Object test; - - public Container(Object test) { - this.test = test; - } - - public Object getTest() { - return test; - } - - @Override - public int hashCode() { - return Pojomatic.hashCode(this); - } - - @Override - public String toString() { - return Pojomatic.toString(this); - } - - @Override - public boolean equals(Object o) { - return Pojomatic.equals(this, o); - } - -} Copied: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/Container.java (from rev 144, branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/test/Container.java) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/Container.java (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/Container.java 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,37 @@ +package org.pojomatic.test; + +import org.pojomatic.Pojomatic; +import org.pojomatic.annotations.AutoProperty; + +/** + * Simple one-object container for use in tests. + */ +@AutoProperty +public class Container { + + private final Object test; + + public Container(Object test) { + this.test = test; + } + + public Object getTest() { + return test; + } + + @Override + public int hashCode() { + return Pojomatic.hashCode(this); + } + + @Override + public String toString() { + return Pojomatic.toString(this); + } + + @Override + public boolean equals(Object o) { + return Pojomatic.equals(this, o); + } + +} Deleted: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java 2009-08-28 04:18:05 UTC (rev 145) @@ -1,23 +0,0 @@ -package org.pojomatic.test; - -import org.pojomatic.Pojomatic; -import org.pojomatic.annotations.AutoProperty; - -/** - * Class where every instance is equal via {@link Pojomatic#equals(Object, Object)}, but never - * by {@code this.equals(other)}. - */ -@AutoProperty -public class OnlyPojomaticEqual { - @SuppressWarnings("unused") - private final int number = 3; - - @Override - public boolean equals(Object obj) { - //cannot assert because only the unit under test should throw AssertionError - if (!Pojomatic.equals(this, obj)) { - throw new IllegalStateException("Invariant violated"); - } - return false; - } -} Copied: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java (from rev 144, branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,23 @@ +package org.pojomatic.test; + +import org.pojomatic.Pojomatic; +import org.pojomatic.annotations.AutoProperty; + +/** + * Class where every instance is equal via {@link Pojomatic#equals(Object, Object)}, but never + * by {@code this.equals(other)}. + */ +@AutoProperty +public class OnlyPojomaticEqual { + @SuppressWarnings("unused") + private final int number = 3; + + @Override + public boolean equals(Object obj) { + //cannot assert because only the unit under test should throw AssertionError + if (!Pojomatic.equals(this, obj)) { + throw new IllegalStateException("Invariant violated"); + } + return false; + } +} Deleted: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java 2009-08-28 04:02:17 UTC (rev 144) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java 2009-08-28 04:18:05 UTC (rev 145) @@ -1,13 +0,0 @@ -package org.pojomatic.testng; - -import org.pojomatic.test.AssertTest; - -public class PojomaticAssertTest extends AssertTest { - - @Override - protected void performAssertEquals(Object first, Object second) { - //in TestNG, the arguments are included in any failure message in reverse order - PojomaticAssert.assertEqualsWithDiff(second, first); - } - -} Copied: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java (from rev 144, branches/TestUtils/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,13 @@ +package org.pojomatic.testng; + +import org.pojomatic.test.AssertTest; + +public class PojomaticAssertTest extends AssertTest { + + @Override + protected void performAssertEquals(Object first, Object second) { + //in TestNG, the arguments are included in any failure message in reverse order + PojomaticAssert.assertEqualsWithDiff(second, first); + } + +} Copied: trunk/PojomaticAll/pom.xml (from rev 144, branches/TestUtils/pom.xml) =================================================================== --- trunk/PojomaticAll/pom.xml (rev 0) +++ trunk/PojomaticAll/pom.xml 2009-08-28 04:18:05 UTC (rev 145) @@ -0,0 +1,178 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.pojomatic</groupId> + <artifactId>pojomatic-all</artifactId> + <packaging>pom</packaging> + <version>TestUtils-SNAPSHOT</version> + <name>PojomaticAll</name> + <description> + Parent and aggregator for all artifacts related to the Pojomatic project. + </description> + <url>http://www.pojomatic.org</url> + <inceptionYear>2008</inceptionYear> + <scm> + <connection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/PojomaticAll</connection> + <developerConnection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/PojomaticAll</developerConnection> + <url>https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/PojomaticAll</url> + </scm> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + </dependencies> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.7</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.pojomatic</groupId> + <artifactId>pojomatic</artifactId> + <version>${version}</version> + </dependency> + </dependencies> + </dependencyManagement> + + <developers> + <developer> + <name>Ian Robertson</name> + <roles> + <role>Lead Developer</role> + </roles> + <email>ian...@gm...</email> + <id>ian.b.robertson</id> + <organization>Overstock.com</organization> + <organizationUrl>http://www.overstock.com</organizationUrl> + <url>http://www.artima.com/weblogs/index.jsp?blogger=ianr</url> + </developer> + <developer> + <name>Chris Hansen</name> + <roles> + <role>Lead Developer</role> + </roles> + <email>han...@gm...</email> + <id>hansen.chris.w</id> + <organization>Overstock.com</organization> + <organizationUrl>http://www.overstock.com</organizationUrl> + <url>http://polyglot-window.blogspot.com/</url> + </developer> + </developers> + + <licenses> + <license> + <name>Apache License 2.0</name> + <url>h... [truncated message content] |
From: <chr...@us...> - 2009-08-28 04:02:25
|
Revision: 144 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=144&view=rev Author: chriswhansen Date: 2009-08-28 04:02:17 +0000 (Fri, 28 Aug 2009) Log Message: ----------- Move Pojomatic to a subfolder Added Paths: ----------- trunk/PojomaticAll/Pojomatic/ Removed Paths: ------------- trunk/Pojomatic/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2009-08-28 04:00:59
|
Revision: 143 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=143&view=rev Author: chriswhansen Date: 2009-08-28 04:00:48 +0000 (Fri, 28 Aug 2009) Log Message: ----------- Create root folder for parent pom. Added Paths: ----------- trunk/PojomaticAll/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2009-08-24 06:05:06
|
Revision: 142 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=142&view=rev Author: chriswhansen Date: 2009-08-24 06:04:50 +0000 (Mon, 24 Aug 2009) Log Message: ----------- Moved PMD report configuration to child poms. Modified Paths: -------------- branches/TestUtils/Pojomatic/pom.xml branches/TestUtils/PojomaticTestUtils/pom.xml branches/TestUtils/pom.xml Added Paths: ----------- branches/TestUtils/PojomaticTestUtils/src/pmd.xml Property Changed: ---------------- branches/TestUtils/ Property changes on: branches/TestUtils ___________________________________________________________________ Added: svn:ignore + target Modified: branches/TestUtils/Pojomatic/pom.xml =================================================================== --- branches/TestUtils/Pojomatic/pom.xml 2009-08-24 01:31:16 UTC (rev 141) +++ branches/TestUtils/Pojomatic/pom.xml 2009-08-24 06:04:50 UTC (rev 142) @@ -19,12 +19,18 @@ <url>https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/pojomatic-all/pojomatic</url> </scm> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - <scope>test</scope> - </dependency> - </dependencies> + <reporting> + <plugins> + <plugin> + <artifactId>maven-pmd-plugin</artifactId> + <configuration> + <targetJdk>1.5</targetJdk> + <rulesets> + <ruleset>${project.basedir}/src/pmd.xml</ruleset> + </rulesets> + <includeTests>true</includeTests> + </configuration> + </plugin> + </plugins> + </reporting> </project> Modified: branches/TestUtils/PojomaticTestUtils/pom.xml =================================================================== --- branches/TestUtils/PojomaticTestUtils/pom.xml 2009-08-24 01:31:16 UTC (rev 141) +++ branches/TestUtils/PojomaticTestUtils/pom.xml 2009-08-24 06:04:50 UTC (rev 142) @@ -10,20 +10,32 @@ <artifactId>pojomatic-test-utils</artifactId> <packaging>jar</packaging> <name>PojomaticTestUtils</name> + <description> + Utilities to help with writing tests for, or using, classes which use Pojomatic. + For example, this library includes classes with JUnit and TestNG style + assertEquals methods which include differences (via Pojomatic.diff(Object, Object)) + in the error message if the assertion fails. + </description> <dependencies> - <!-- TODO move this to a common parent pom --> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.6</version> - <scope>test</scope> - </dependency> - <dependency> - <!-- TODO move this to a common parent pom --> <groupId>org.pojomatic</groupId> <artifactId>pojomatic</artifactId> - <version>TestUtils-SNAPSHOT</version> </dependency> </dependencies> + + <reporting> + <plugins> + <plugin> + <artifactId>maven-pmd-plugin</artifactId> + <configuration> + <targetJdk>1.5</targetJdk> + <rulesets> + <ruleset>${project.basedir}/src/pmd.xml</ruleset> + </rulesets> + <includeTests>true</includeTests> + </configuration> + </plugin> + </plugins> + </reporting> </project> Added: branches/TestUtils/PojomaticTestUtils/src/pmd.xml =================================================================== --- branches/TestUtils/PojomaticTestUtils/src/pmd.xml (rev 0) +++ branches/TestUtils/PojomaticTestUtils/src/pmd.xml 2009-08-24 06:04:50 UTC (rev 142) @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<ruleset name="Custom ruleset" + xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <description> + This ruleset checks my code for bad stuff + </description> + + <rule ref="rulesets/basic.xml"> + <exclude name="EmptyCatchBlock"/> + <exclude name="EmptyWhileStmt"/> + </rule> + <rule ref="rulesets/basic.xml/EmptyCatchBlock"> + <properties> + <property name="allowCommentedBlocks" value="true"/> + </properties> + </rule> + + <rule ref="rulesets/strings.xml"> + <exclude name="AvoidDuplicateLiterals"/> + </rule> + <rule ref="rulesets/unusedcode.xml"/> + <rule ref="rulesets/imports.xml"> + <exclude name="UnusedImports"/> + </rule> + <rule ref="rulesets/braces.xml"/> +</ruleset> + Modified: branches/TestUtils/pom.xml =================================================================== --- branches/TestUtils/pom.xml 2009-08-24 01:31:16 UTC (rev 141) +++ branches/TestUtils/pom.xml 2009-08-24 06:04:50 UTC (rev 142) @@ -20,11 +20,25 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>4.7</version> - <scope>test</scope> </dependency> </dependencies> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.7</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.pojomatic</groupId> + <artifactId>pojomatic</artifactId> + <version>${version}</version> + </dependency> + </dependencies> + </dependencyManagement> + <developers> <developer> <name>Ian Robertson</name> @@ -155,16 +169,6 @@ <version>2.1</version> </plugin> <plugin> - <artifactId>maven-pmd-plugin</artifactId> - <configuration> - <targetJdk>1.5</targetJdk> - <rulesets> - <ruleset>${project.basedir}/pmd.xml</ruleset> - </rulesets> - <includeTests>true</includeTests> - </configuration> - </plugin> - <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.2</version> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2009-08-24 01:31:22
|
Revision: 141 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=141&view=rev Author: chriswhansen Date: 2009-08-24 01:31:16 +0000 (Mon, 24 Aug 2009) Log Message: ----------- Upgrade to junit 4.7 Modified Paths: -------------- branches/TestUtils/pom.xml Modified: branches/TestUtils/pom.xml =================================================================== --- branches/TestUtils/pom.xml 2009-08-24 01:02:54 UTC (rev 140) +++ branches/TestUtils/pom.xml 2009-08-24 01:31:16 UTC (rev 141) @@ -15,6 +15,16 @@ <developerConnection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/PojomaticAll</developerConnection> <url>https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/PojomaticAll</url> </scm> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.7</version> + <scope>test</scope> + </dependency> + </dependencies> + <developers> <developer> <name>Ian Robertson</name> @@ -39,6 +49,7 @@ <url>http://polyglot-window.blogspot.com/</url> </developer> </developers> + <licenses> <license> <name>Apache License 2.0</name> @@ -46,10 +57,12 @@ <distribution>repo</distribution> </license> </licenses> + <issueManagement> <system>Sourceforge</system> <url>https://sourceforge.net/tracker/?func=browse&group_id=239113</url> </issueManagement> + <distributionManagement> <repository> <id>pojomatic-releases</id> @@ -68,6 +81,7 @@ <url>scp://shell.sourceforge.net/home/groups/p/po/pojomatic/htdocs</url> </site> </distributionManagement> + <mailingLists> <mailingList> <archive>http://sourceforge.net/mailarchive/forum.php?forum_name=pojomatic-users</archive> @@ -77,6 +91,7 @@ <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/pojomatic-users</unsubscribe> </mailingList> </mailingLists> + <build> <plugins> <plugin> @@ -104,7 +119,6 @@ <version>2.0-beta-9</version> </plugin> </plugins> - </build> <modules> @@ -157,12 +171,4 @@ </plugin> </plugins> </reporting> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - <scope>test</scope> - </dependency> - </dependencies> </project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2009-08-24 01:03:02
|
Revision: 140 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=140&view=rev Author: chriswhansen Date: 2009-08-24 01:02:54 +0000 (Mon, 24 Aug 2009) Log Message: ----------- Added base/aggregator pom.xml Modified Paths: -------------- branches/TestUtils/Pojomatic/pom.xml branches/TestUtils/PojomaticTestUtils/pom.xml Added Paths: ----------- branches/TestUtils/pom.xml Modified: branches/TestUtils/Pojomatic/pom.xml =================================================================== --- branches/TestUtils/Pojomatic/pom.xml 2009-08-24 00:33:03 UTC (rev 139) +++ branches/TestUtils/Pojomatic/pom.xml 2009-08-24 01:02:54 UTC (rev 140) @@ -1,158 +1,24 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>pojomatic-all</artifactId> + <groupId>org.pojomatic</groupId> + <version>TestUtils-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> <modelVersion>4.0.0</modelVersion> - <groupId>org.pojomatic</groupId> <artifactId>pojomatic</artifactId> <packaging>jar</packaging> - <version>TestUtils-SNAPSHOT</version> <name>Pojomatic</name> <description> Automatically provides configurable implementations of the equals(Object), toString() and hashCode() methods inherited from java.lang.Object </description> - <url>http://www.pojomatic.org</url> - <inceptionYear>2008</inceptionYear> <scm> - <connection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/Pojomatic</connection> - <developerConnection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/Pojomatic</developerConnection> - <url>https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/Pojomatic</url> + <connection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/pojomatic-all/pojomatic</connection> + <developerConnection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/pojomatic-all/pojomatic</developerConnection> + <url>https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/pojomatic-all/pojomatic</url> </scm> - <developers> - <developer> - <name>Ian Robertson</name> - <roles> - <role>Lead Developer</role> - </roles> - <email>ian...@gm...</email> - <id>ian.b.robertson</id> - <organization>Overstock.com</organization> - <organizationUrl>http://www.overstock.com</organizationUrl> - <url>http://www.artima.com/weblogs/index.jsp?blogger=ianr</url> - </developer> - <developer> - <name>Chris Hansen</name> - <roles> - <role>Lead Developer</role> - </roles> - <email>han...@gm...</email> - <id>hansen.chris.w</id> - <organization>Overstock.com</organization> - <organizationUrl>http://www.overstock.com</organizationUrl> - <url>http://polyglot-window.blogspot.com/</url> - </developer> - </developers> - <licenses> - <license> - <name>Apache License 2.0</name> - <url>http://www.apache.org/licenses/LICENSE-2.0</url> - <distribution>repo</distribution> - </license> - </licenses> - <issueManagement> - <system>Sourceforge</system> - <url>https://sourceforge.net/tracker/?func=browse&group_id=239113</url> - </issueManagement> - <distributionManagement> - <repository> - <id>pojomatic-releases</id> - <name>Pojomatic Release Repository</name> - <url>sftp://web.sourceforge.net/home/groups/p/po/pojomatic/releases</url> - </repository> - <snapshotRepository> - <id>pojomatic-snapshots</id> - <name>Pojomatic snapshot Repository</name> - <url>sftp://web.sourceforge.net/home/groups/p/po/pojomatic/snapshots</url> - </snapshotRepository> - <site> - <id>pojomatic-site</id> - <name>Pojomatic</name> - <!-- before deploying, you'll need to run ssh <username>,poj...@sh... create --> - <url>scp://shell.sourceforge.net/home/groups/p/po/pojomatic/htdocs</url> - </site> - </distributionManagement> - <mailingLists> - <mailingList> - <archive>http://sourceforge.net/mailarchive/forum.php?forum_name=pojomatic-users</archive> - <name>pojomatic-users</name> - <post>poj...@li...</post> - <subscribe>http://lists.sourceforge.net/mailman/listinfo/pojomatic-users</subscribe> - <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/pojomatic-users</unsubscribe> - </mailingList> - </mailingLists> - <build> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.0.2</version> - <configuration> - <source>1.5</source> - <target>1.5</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.4.2</version> - <configuration> - <excludes> - <exclude>**/TestUtils.java</exclude> - <exclude>examples/*.java</exclude> - </excludes> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-release-plugin</artifactId> - <version>2.0-beta-9</version> - </plugin> - </plugins> - </build> - - <reporting> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <version>2.4</version> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-site-plugin</artifactId> - <version>2.0-beta-5</version> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>findbugs-maven-plugin</artifactId> - <version>1.1.1</version> - <configuration> - <excludeFilterFile>${basedir}/FindBugsFilter.xml</excludeFilterFile> - </configuration> - </plugin> - <plugin> - <artifactId>maven-surefire-report-plugin</artifactId> - <version>2.4.2</version> - </plugin> - <plugin> - <artifactId>maven-jxr-plugin</artifactId> - <version>2.1</version> - </plugin> - <plugin> - <artifactId>maven-pmd-plugin</artifactId> - <configuration> - <targetJdk>1.5</targetJdk> - <rulesets> - <ruleset>${project.basedir}/src/pmd.xml</ruleset> - </rulesets> - <includeTests>true</includeTests> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>cobertura-maven-plugin</artifactId> - <version>2.2</version> - </plugin> - </plugins> - </reporting> <dependencies> <dependency> <groupId>junit</groupId> Modified: branches/TestUtils/PojomaticTestUtils/pom.xml =================================================================== --- branches/TestUtils/PojomaticTestUtils/pom.xml 2009-08-24 00:33:03 UTC (rev 139) +++ branches/TestUtils/PojomaticTestUtils/pom.xml 2009-08-24 01:02:54 UTC (rev 140) @@ -1,12 +1,15 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>pojomatic-all</artifactId> + <groupId>org.pojomatic</groupId> + <version>TestUtils-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> <modelVersion>4.0.0</modelVersion> - <groupId>org.pojomatic</groupId> <artifactId>pojomatic-test-utils</artifactId> <packaging>jar</packaging> - <version>1.0-SNAPSHOT</version> - <name>pojomatic-test-utils</name> - <url>http://maven.apache.org</url> + <name>PojomaticTestUtils</name> <dependencies> <!-- TODO move this to a common parent pom --> @@ -23,18 +26,4 @@ <version>TestUtils-SNAPSHOT</version> </dependency> </dependencies> - - <build> - <plugins> - <!-- TODO move this to a common parent pom --> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.0.2</version> - <configuration> - <source>1.5</source> - <target>1.5</target> - </configuration> - </plugin> - </plugins> - </build> </project> Added: branches/TestUtils/pom.xml =================================================================== --- branches/TestUtils/pom.xml (rev 0) +++ branches/TestUtils/pom.xml 2009-08-24 01:02:54 UTC (rev 140) @@ -0,0 +1,168 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.pojomatic</groupId> + <artifactId>pojomatic-all</artifactId> + <packaging>pom</packaging> + <version>TestUtils-SNAPSHOT</version> + <name>PojomaticAll</name> + <description> + Parent and aggregator for all artifacts related to the Pojomatic project. + </description> + <url>http://www.pojomatic.org</url> + <inceptionYear>2008</inceptionYear> + <scm> + <connection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/PojomaticAll</connection> + <developerConnection>scm:svn:https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/PojomaticAll</developerConnection> + <url>https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/PojomaticAll</url> + </scm> + <developers> + <developer> + <name>Ian Robertson</name> + <roles> + <role>Lead Developer</role> + </roles> + <email>ian...@gm...</email> + <id>ian.b.robertson</id> + <organization>Overstock.com</organization> + <organizationUrl>http://www.overstock.com</organizationUrl> + <url>http://www.artima.com/weblogs/index.jsp?blogger=ianr</url> + </developer> + <developer> + <name>Chris Hansen</name> + <roles> + <role>Lead Developer</role> + </roles> + <email>han...@gm...</email> + <id>hansen.chris.w</id> + <organization>Overstock.com</organization> + <organizationUrl>http://www.overstock.com</organizationUrl> + <url>http://polyglot-window.blogspot.com/</url> + </developer> + </developers> + <licenses> + <license> + <name>Apache License 2.0</name> + <url>http://www.apache.org/licenses/LICENSE-2.0</url> + <distribution>repo</distribution> + </license> + </licenses> + <issueManagement> + <system>Sourceforge</system> + <url>https://sourceforge.net/tracker/?func=browse&group_id=239113</url> + </issueManagement> + <distributionManagement> + <repository> + <id>pojomatic-releases</id> + <name>Pojomatic Release Repository</name> + <url>sftp://web.sourceforge.net/home/groups/p/po/pojomatic/releases</url> + </repository> + <snapshotRepository> + <id>pojomatic-snapshots</id> + <name>Pojomatic snapshot Repository</name> + <url>sftp://web.sourceforge.net/home/groups/p/po/pojomatic/snapshots</url> + </snapshotRepository> + <site> + <id>pojomatic-site</id> + <name>Pojomatic</name> + <!-- before deploying, you'll need to run ssh <username>,poj...@sh... create --> + <url>scp://shell.sourceforge.net/home/groups/p/po/pojomatic/htdocs</url> + </site> + </distributionManagement> + <mailingLists> + <mailingList> + <archive>http://sourceforge.net/mailarchive/forum.php?forum_name=pojomatic-users</archive> + <name>pojomatic-users</name> + <post>poj...@li...</post> + <subscribe>http://lists.sourceforge.net/mailman/listinfo/pojomatic-users</subscribe> + <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/pojomatic-users</unsubscribe> + </mailingList> + </mailingLists> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.0.2</version> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.4.2</version> + <configuration> + <excludes> + <exclude>**/TestUtils.java</exclude> + <exclude>examples/*.java</exclude> + </excludes> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-release-plugin</artifactId> + <version>2.0-beta-9</version> + </plugin> + </plugins> + + </build> + + <modules> + <module>Pojomatic</module> + <module>PojomaticTestUtils</module> + </modules> + + <reporting> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.4</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-site-plugin</artifactId> + <version>2.0-beta-5</version> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>findbugs-maven-plugin</artifactId> + <version>1.1.1</version> + <configuration> + <excludeFilterFile>${basedir}/FindBugsFilter.xml</excludeFilterFile> + </configuration> + </plugin> + <plugin> + <artifactId>maven-surefire-report-plugin</artifactId> + <version>2.4.2</version> + </plugin> + <plugin> + <artifactId>maven-jxr-plugin</artifactId> + <version>2.1</version> + </plugin> + <plugin> + <artifactId>maven-pmd-plugin</artifactId> + <configuration> + <targetJdk>1.5</targetJdk> + <rulesets> + <ruleset>${project.basedir}/pmd.xml</ruleset> + </rulesets> + <includeTests>true</includeTests> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>cobertura-maven-plugin</artifactId> + <version>2.2</version> + </plugin> + </plugins> + </reporting> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |