FileDocCategorySizeDatePackage
PersonalData.javaAPI DocExample2339Sun Sep 02 14:59:02 BST 2001chap6

PersonalData

public class PersonalData extends Object
A helper class that stores personal information. XML generation is intentionally left out of this class. This class ensures that its data cannot be null, nor can it contain extra whitespace.

Fields Summary
private String
firstName
private String
lastName
private String
daytimePhone
private String
eveningPhone
private String
email
Constructors Summary
public PersonalData()

        this("", "", "", "", "");
    
public PersonalData(String firstName, String lastName, String daytimePhone, String eveningPhone, String email)

        this.firstName = cleanup(firstName);
        this.lastName = cleanup(lastName);
        this.daytimePhone = cleanup(daytimePhone);
        this.eveningPhone = cleanup(eveningPhone);
        this.email = cleanup(email);
    
Methods Summary
private static java.lang.Stringcleanup(java.lang.String str)
Cleanup the String parameter by replacing null with an empty String, and by trimming whitespace from non-null Strings.

        return (str != null) ? str.trim() : "";
    
public java.lang.StringgetDaytimePhone()

 return this.daytimePhone; 
public java.lang.StringgetEmail()

 return this.email; 
public java.lang.StringgetEveningPhone()

 return this.eveningPhone; 
public java.lang.StringgetFirstName()

 return this.firstName; 
public java.lang.StringgetLastName()

 return this.lastName; 
public booleanisValid()
eveningPhone is the only optional field.

return
true if all required fields are present.

        return this.firstName.length() > 0
                && this.lastName.length() > 0
                && this.daytimePhone.length() > 0
                && this.email.length() > 0;
    
public voidsetDaytimePhone(java.lang.String daytimePhone)

        this.daytimePhone = cleanup(daytimePhone);
    
public voidsetEmail(java.lang.String email)

        this.email = cleanup(email);
    
public voidsetEveningPhone(java.lang.String eveningPhone)

        this.eveningPhone = cleanup(eveningPhone);
    
public voidsetFirstName(java.lang.String firstName)

        this.firstName = cleanup(firstName);
    
public voidsetLastName(java.lang.String lastName)

        this.lastName = cleanup(lastName);