Java J2EE Portal
Enterprise Java Station
J2EE curve
Java News / Articles
Java News / Articles
odf-ooxml
Office Open XML (OOXML) vs Open Document Format (ODF)
JSF and Ajax: Latest strategies for building Ajax applications
Password Based Authentication Using Message Digests
Processing...
Buy Java, Deals On Software Technology Store
Click here for great deals on computers, laptops, software and books
Why pick JTiger Java Unit Testing Framework over good old JUnit? PDF Print
Oct 05, 2005 at 05:37 AM




package persons;
import java.io.Serializable;
interface Person extends Serializable {
String getFirstName();
String getLastName();
}
public final class PersonImpl {
private PersonImpl() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public static Person getPerson(final String firstName
, final String lastName)
throws NullPointerException {
if(firstName == null || lastName == null) {
throw new NullPointerException();
}
else {
return new _Person(firstName, lastName);
}
}
private static final class _Person implements Person {
private final String firstName;
private final String lastName;
_Person(final String firstName, final String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
@Override
public boolean equals(final Object o) {
if(this == o) {
return true;
}
else if(!(o instanceof Person)) {
return false;
}
else {
final Person p = (Person)o;
return firstName.equals(p.getFirstName()) && lastName.equals(p.getLastName());
}
}
@Override
public int hashCode() {
// let's make it simple... don't know about you, but I'm out of breath :)
return firstName.hashCode() ^ lastName.hashCode();
}
}
}




Add This Feed Button

Enter your Email


Java Expert Interviews
JavaFX Expert
JavaFX Is Many Times Faster And Easier Than Swing
Satish Talim
Java and J2EE Today: An interview with Satish Talim
ChristopherDuncan
Programmers lose because they are unwilling to learn any skill beyond the technical
Processing...
Go to top of page  Home |
SiteMap

Copyright 2004 to 2008 Rightrix Solutions. All rights reserved. All product names are trademarks of their respective companies. Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Rightrix Solutions and IndicThreads.com are independent of Sun Microsystems, Inc.

Views expressed at IndicThreads.com reflect the views of the authors alone, and do not necessarily reflect those of IndicThreads.com. IndicThreads.com and it's authors are not responsible for reader comments and opinions.

Enterprise Java J2EE JEE Portal >> IndicThreads.com