public class PoliticalCandidate { // Member variables - omitted for brevity // Constructors - omitted for brevity // get/set methods - omitted for brevity // A hashCode which creates a hash from the two unique identifiers public int hashCode( ) { return new HashCodeBuilder( 17 , 37 ) .append(firstName) .append(lastName).toHashCode( ); } // An equals which compares two unique identifiers public boolean equals(Object o) { boolean equals = false ; if ( o != null && PoliticalCandidate. class .isAssignableFrom(o) ) { PoliticalCandidate pc = (PoliticalCandidate) o; equals = ( new EqualsBuilder( ) .append(firstName, ps.firstName) .append(lastName, ps.lastName)).isEquals( ); } return equals; } }
public class PoliticalCandidate { // Static variable private static String averageAge;
// Member variables private String firstName; private String lastName;
private transient String fullName; // Constructors // get/set methods // Build a compareTo function from reflection public int compareTo(Object o) { return CompareToBuilder.reflectionCompare( this , obj); } }
public int compareTo(Object o) { int compare = - 1 ; // By default return less-than if ( o != null && PoliticalCandidate. class .isAssignableFrom( o.getClass( ) ) ) {
PoliticalCandidate pc = (PoliticalCandidate) o; compare = ( new CompareToBuilder( ) .append(firstName, pc.firstName) .append(lastName, pc.lastName)).toComparison( ); } return compare; }
public class PoliticalCandidate { private String lastName; private String firstName; private Date dateOfBirth; private BigDecimal moneyRaised; private State homeState;
// get/set方法省略 public void toString( ) { ReflectionToStringBuilder.toString( this ); } }
该bean里面有个toString()方法,假设有以下操作:
// Create a State State va = new State( "VA", "Virginia");
// Create a Birth Date Calendar calendar = new GregorianCalendar( ); calendar.set( Calendar.YEAR, 1743 ); calendar.set( Calendar.MONTH, Calendar.APRIL ); calendar.set( Calendar.DAY_OF_MONTH, 13 ); Date dob = calendar.getTime( );
BigDecimal moneyRaised = new BigDecimal( 293829292.93 );
// Create a Political Candidate PoliticalCandidate candidate = new PoliticalCandidate( "Jefferson", "Thomas", dob, moneyRaised, va );
public class PoliticalCandidate { // Member variables - omitted for brevity // Constructors - omitted for brevity // get/set methods - omitted for brevity // A hashCode which creates a hash from the two unique identifiers public int hashCode( ) { return new HashCodeBuilder( 17 , 37 ) .append(firstName) .append(lastName).toHashCode( ); } // An equals which compares two unique identifiers public boolean equals(Object o) { boolean equals = false ; if ( o != null && PoliticalCandidate. class .isAssignableFrom(o) ) { PoliticalCandidate pc = (PoliticalCandidate) o; equals = ( new EqualsBuilder( ) .append(firstName, ps.firstName) .append(lastName, ps.lastName)).isEquals( ); } return equals; } }
public class PoliticalCandidate { // Static variable private static String averageAge;
// Member variables private String firstName; private String lastName;
private transient String fullName; // Constructors // get/set methods // Build a compareTo function from reflection public int compareTo(Object o) { return CompareToBuilder.reflectionCompare( this , obj); } }
public int compareTo(Object o) { int compare = - 1 ; // By default return less-than if ( o != null && PoliticalCandidate. class .isAssignableFrom( o.getClass( ) ) ) {
PoliticalCandidate pc = (PoliticalCandidate) o; compare = ( new CompareToBuilder( ) .append(firstName, pc.firstName) .append(lastName, pc.lastName)).toComparison( ); } return compare; }
public class PoliticalCandidate { private String lastName; private String firstName; private Date dateOfBirth; private BigDecimal moneyRaised; private State homeState;
// get/set方法省略 public void toString( ) { ReflectionToStringBuilder.toString( this ); } }
该bean里面有个toString()方法,假设有以下操作:
// Create a State State va = new State( "VA", "Virginia");
// Create a Birth Date Calendar calendar = new GregorianCalendar( ); calendar.set( Calendar.YEAR, 1743 ); calendar.set( Calendar.MONTH, Calendar.APRIL ); calendar.set( Calendar.DAY_OF_MONTH, 13 ); Date dob = calendar.getTime( );
BigDecimal moneyRaised = new BigDecimal( 293829292.93 );
// Create a Political Candidate PoliticalCandidate candidate = new PoliticalCandidate( "Jefferson", "Thomas", dob, moneyRaised, va );