FileDocCategorySizeDatePackage
Person.javaAPI DocExample5794Thu Dec 15 22:36:34 GMT 2005com.oreilly.jent.annotation.people

Person

public class Person extends Object implements Serializable
A JavaBean containing basic information about a person.

Fields Summary
private String
mFirstName
private String
mLastName
private Collection
mEmailAddresses
private String
mID
Constructors Summary
public Person()

    
      
        mID = null;
        mFirstName = null;
        mLastName = null;
    
public Person(String fname, String lname)
Create a person with just name information

        setFirstName(fname);
        setLastName(lname);
        mID = getFirstName() + " " + getLastName();
    
public Person(String fname, String lname, String id)
Create a person with name and a unique identifier.

        mID = id;
        setFirstName(fname);
        setLastName(lname);
    
public Person(String fname, String lname, String[] eAddrs)
Constructor with all data defined

        setFirstName(fname);
        setLastName(lname);
        setEmailAddresses(eAddrs);
    
Methods Summary
public voidaddEmailAddress(java.lang.String address)

        // Make sure the address isn't there already
        if (!mEmailAddresses.contains(address)) {
            mEmailAddresses.add(address);
        }
    
public booleanequals(java.lang.Object other)

        boolean eq = false;
        if (other instanceof Person) {
            Person p2 = (Person)other;
            // If both references point to the same object, then 
            // shortcut the equality check below
            if (p2 == this) {
                return true;
            }
            // The id and name attributes should either be both null, or
            // both non-null and equal to each other
            eq = ((p2.getId() == null && this.getId() == null) ||
                  (p2.getId() != null && this.getId() != null &&
                   p2.getId().equals(this.getId())));
            eq = eq &&
                 ((p2.getFirstName() == null && this.getFirstName() == null) ||
                  (p2.getFirstName() != null && this.getFirstName() != null &&
                   p2.getFirstName().equals(this.getFirstName())));
            eq = eq && 
                 ((p2.getLastName() == null && this.getFirstName() == null) ||
                  (p2.getLastName() != null && this.getLastName() != null &&
                   p2.getLastName().equals(this.getLastName())));
            // Both should have the same number of email addresses
            eq = eq && 
                 (p2.getEmailAddresses().length ==
                  this.getEmailAddresses().length);
            if (eq) {
                // For each of our email addresses, confirm that the 
                // other has the address on its list
                // We do this by putting one set of addresses in a collection
                // and iterating through the other using contains() to check
                // for its presence on the other list. 
                // This isn't the most efficient approach, but it's easy to
                // implement.
                ArrayList tmpList = new ArrayList();
                for (int i = 0; i < p2.getEmailAddresses().length; i++) {
                    tmpList.add(p2.getEmailAddresses()[i]);
                }
                for (int i = 0; i < this.getEmailAddresses().length; i++) {
                    eq = eq && tmpList.contains(this.getEmailAddresses()[i]);
                }
            }
        }
        return eq;
    
public java.lang.String[]getEmailAddresses()

        String[] addrs = new String[mEmailAddresses.size()];
        Object[] origAddrs = mEmailAddresses.toArray();
        for (int i = 0; i < addrs.length; i++) {
            addrs[i] = (String)origAddrs[i];
        }
        return addrs;
    
public java.lang.StringgetFirstName()

        return mFirstName;
    
public java.lang.StringgetId()

return
Returns the id for this person.

        return mID;
    
public java.lang.StringgetLastName()

        return mLastName;
    
public voidsetEmailAddresses(java.lang.String[] addresses)

        mEmailAddresses = new ArrayList();
        for (int i = 0; i < addresses.length; i++) {
            mEmailAddresses.add(addresses[i]);
        }
    
public voidsetFirstName(java.lang.String fName)

        mFirstName = fName;
    
public voidsetLastName(java.lang.String lName)

        mLastName = lName;