Source code: com/clra/member/AccountType.java
1 /*
2 * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3 * Distributed under the GPL license. See doc/COPYING.
4 * $RCSfile: AccountType.java,v $
5 * $Date: 2003/03/01 00:45:14 $
6 * $Revision: 1.6 $
7 */
8
9 package com.clra.member;
10
11 import java.io.Serializable;
12
13 /**
14 * Encapsulates information about the type of account of a member.
15 * The type of an account is used in several ways:<ul>
16 * <li> By the treasurer, as a part of accounting</li>
17 * <li> By the member-manager and others, when boatings are created</li>
18 * <li> By social chairs and others, when contacting past and present
19 * membership of the club.</li></ul>
20 *
21 * @version $Revision: 1.6 $ $Date: 2003/03/01 00:45:14 $
22 * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
23 */
24 public class AccountType implements Serializable {
25
26 /** Designates a current account of an experienced member */
27 public final static String TYPE_FULL = "FULL";
28
29 /**
30 * Designates a current account of a member with less than
31 * a year's experience.
32 */
33 public final static String TYPE_NOVICE = "NOVICE";
34
35 /** Designates a current account of a Learn-To-Row participant */
36 public final static String TYPE_LTR = "LTR";
37
38 /** Designates the account of a former novice or experienced member */
39 public final static String TYPE_ALUMNI = "ALUMNI";
40
41 /** Designates the account of a former LTR participant */
42 public final static String TYPE_LTR_ALUM = "LTR-ALUM";
43
44 /** Designates the account of a paid contractor */
45 public final static String TYPE_CONTRACTOR = "CONTRACT";
46
47 /** Designates a duplicate account */
48 public final static String TYPE_DUPLICATE = "DUPLICAT";
49
50 public final static AccountType FULL =
51 new AccountType( TYPE_FULL );
52
53 public final static AccountType NOVICE =
54 new AccountType( TYPE_NOVICE );
55
56 public final static AccountType LTR =
57 new AccountType( TYPE_LTR );
58
59 public final static AccountType ALUMNI =
60 new AccountType( TYPE_ALUMNI );
61
62 public final static AccountType LTR_ALUM =
63 new AccountType( TYPE_LTR_ALUM );
64
65 public final static AccountType CONTRACTOR =
66 new AccountType( TYPE_CONTRACTOR );
67
68 public final static AccountType DUPLICATE =
69 new AccountType( TYPE_DUPLICATE );
70
71 public final static String[] ALLOWED_TYPES() {
72 return new String[] {
73 TYPE_FULL,
74 TYPE_NOVICE,
75 TYPE_LTR,
76 TYPE_ALUMNI,
77 TYPE_LTR_ALUM,
78 TYPE_CONTRACTOR,
79 TYPE_DUPLICATE
80 };
81 }
82
83 /** The type of the Member */
84 private final String accountType;
85
86 public AccountType( String type ) {
87 // Preconditions
88 if ( type == null ) {
89 throw new IllegalArgumentException( "null type" );
90 }
91 type = type.toUpperCase().trim();
92 boolean isOK = false;
93 String[] ALLOWED = ALLOWED_TYPES();
94 for ( int i=0; i<ALLOWED.length; i++ ) {
95 if ( ALLOWED[i].equals(type) ) {
96 isOK = true;
97 break;
98 }
99 }
100 if ( !isOK ) {
101 String msg = "invalid account type == '" + type + "'";
102 throw new IllegalArgumentException( msg );
103 }
104
105 this.accountType = type;
106
107 } // ctor(String,String)
108
109 public String getAccountType() {
110 return this.accountType;
111 }
112
113 public String toString() {
114 return this.accountType;
115 }
116
117 public boolean equals( Object o ) {
118 boolean retVal;
119 if ( o == null ) {
120 retVal = false;
121 }
122 else if ( o instanceof AccountType ) {
123 AccountType that = (AccountType) o;
124 retVal = this.accountType.equalsIgnoreCase( that.accountType );
125 }
126 else if ( o instanceof String ) {
127 retVal = this.accountType.equalsIgnoreCase( o.toString().trim() );
128 }
129 else {
130 retVal = false;
131 }
132
133 return retVal;
134 } // equals(Object)
135
136 public int hashCode() {
137 return this.accountType.trim().toUpperCase().hashCode();
138 }
139
140 } // AccountType
141
142 /*
143 * $Log: AccountType.java,v $
144 * Revision 1.6 2003/03/01 00:45:14 rphall
145 * Removed no-param default constructor
146 *
147 * Revision 1.5 2003/02/28 14:05:48 rphall
148 * Added default constructor so that class could be used as a Java bean
149 *
150 * Revision 1.4 2003/02/26 03:38:45 rphall
151 * Added copyright and GPL license
152 *
153 * Revision 1.3 2003/02/21 04:59:54 rphall
154 * Shortened DB value for 'DUPLICATE'
155 *
156 * Revision 1.2 2003/02/19 22:23:01 rphall
157 * Removed gratuitous use of CLRA acronym
158 *
159 * Revision 1.1 2003/02/19 03:41:39 rphall
160 * Working with unit tests
161 *
162 */
163