Source code: com/clra/member/Address.java
1 /*
2 * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3 * Distributed under the GPL license. See doc/COPYING.
4 * $RCSfile: Address.java,v $
5 * $Date: 2003/02/26 03:38:45 $
6 * $Revision: 1.7 $
7 */
8
9 package com.clra.member;
10
11 import java.io.Serializable;
12
13 /**
14 * Encapsulates address information about a member.
15 * @version $Id: Address.java,v 1.7 2003/02/26 03:38:45 rphall Exp $
16 * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
17 */
18 public class Address implements Serializable {
19
20 private String street1 = null;
21 private String street2 = null;
22 private String city = null;
23 private String state = null;
24 private String zip = null;
25
26 /** Produces an invalid Address object. Used only during deserialization. */
27 public Address() {}
28
29 public Address( String street1, String street2,
30 String city, String state, String zip ) {
31 // Assign blank finals
32 this.street1 = street1 == null ? null : street1.trim() ;
33 this.street2 = street2 == null ? null : street2.trim() ;
34 this.city = city == null ? null : city.trim() ;
35 this.state = state == null ? null : state.trim() ;
36 this.zip = zip == null ? null : zip.trim() ;
37
38 // Enforce preconditions
39 if ( street1 == null || this.street1.length() == 0 ) {
40 throw new IllegalArgumentException( "invalid street1" );
41 }
42 if ( city == null || this.city.length() == 0 ) {
43 throw new IllegalArgumentException( "invalid city" );
44 }
45 if ( state == null || this.state.length() == 0 ) {
46 throw new IllegalArgumentException( "invalid state" );
47 }
48 if ( zip == null || this.zip.length() == 0 ) {
49 throw new IllegalArgumentException( "invalid zip" );
50 }
51
52 } // ctor(..)
53
54 public String getStreet1() { return this.street1; }
55
56 public String getStreet2() { return this.street2; }
57
58 public String getCity() { return this.city; }
59
60 public String getState() { return this.state; }
61
62 public String getZip() { return this.zip; }
63
64 public boolean equals( Object o ) {
65
66 boolean retVal;
67 if ( o == null ) {
68 retVal = false;
69 }
70 else if ( o instanceof Address ) {
71 Address that = (Address) o;
72 retVal = this.street1.equals(that.street1);
73 if ( retVal ) {
74 if ( this.street2 != null ) {
75 retVal = this.street2.equals(that.street2);
76 } else {
77 retVal = that.street2 == null;
78 }
79 }
80 retVal = retVal && this.city.equals(that.city);
81 retVal = retVal && this.state.equals(that.state);
82 retVal = retVal && this.zip.equals(that.zip);
83 }
84 else {
85 retVal = false;
86 }
87
88 return retVal;
89 } // equals(Object)
90
91 public int hashCode() {
92 int retVal = this.street1.hashCode(); // good enough
93 return retVal;
94 }
95
96 } // Address
97
98 /*
99 * $Log: Address.java,v $
100 * Revision 1.7 2003/02/26 03:38:45 rphall
101 * Added copyright and GPL license
102 *
103 * Revision 1.6 2003/02/19 22:23:01 rphall
104 * Removed gratuitous use of CLRA acronym
105 *
106 * Revision 1.5 2003/02/18 04:16:41 rphall
107 * Removed ValidationException
108 *
109 * Revision 1.4 2003/02/16 00:38:44 rphall
110 * Fixed bug in 'equals' method
111 *
112 * Revision 1.3 2003/02/15 04:31:41 rphall
113 * Changes connected to major revision of MemberBean
114 *
115 */
116