Source code: com/clra/rowing/SeatPreference.java
1 /*
2 * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3 * Distributed under the GPL license. See doc/COPYING.
4 * $RCSfile: SeatPreference.java,v $
5 * $Date: 2003/02/26 03:38:45 $
6 * $Revision: 1.3 $
7 */
8
9 package com.clra.rowing;
10
11 import java.io.Serializable;
12
13 /**
14 * Defines seating preference that may be specified by a participant for
15 * a rowing session.
16 *
17 * @version $Id: SeatPreference.java,v 1.3 2003/02/26 03:38:45 rphall Exp $
18 * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
19 */
20 public class SeatPreference implements Serializable {
21
22 /** Indicates a member prefers a starboard rowing position */
23 public final static String NAME_STARBOARD = "STARBOARD";
24
25 /** Indicates a member prefers a port rowing position */
26 public final static String NAME_PORT = "PORT";
27
28 /**
29 * Indicates a member prefers a starboard position, but will also
30 * row port.
31 */
32 public final static String NAME_STARBOARD_THEN_PORT = "S(P)";
33
34 /**
35 * Indicates a member prefers a port position, but will also
36 * row starboard.
37 */
38 public final static String NAME_PORT_THEN_STARBOARD = "P(S)";
39
40 /** Indicates a member prefers to cox. */
41 public final static String NAME_COX = "COX";
42
43 /** Indicates a member prefers a starboard rowing position */
44 public final static SeatPreference STARBOARD =
45 new SeatPreference( NAME_STARBOARD );
46
47 /** Indicates a member prefers a port rowing position */
48 public final static SeatPreference PORT =
49 new SeatPreference( NAME_PORT );
50
51 /**
52 * Indicates a member prefers a starboard position, but will also
53 * row port.
54 */
55 public final static SeatPreference STARBOARD_THEN_PORT =
56 new SeatPreference( NAME_STARBOARD_THEN_PORT );
57
58 /**
59 * Indicates a member prefers a port position, but will also
60 * row starboard.
61 */
62 public final static SeatPreference PORT_THEN_STARBOARD =
63 new SeatPreference( NAME_PORT_THEN_STARBOARD );
64
65 /** Indicates a member prefers to cox. */
66 public final static SeatPreference COX =
67 new SeatPreference( NAME_COX );
68
69 private final String name;
70
71 protected SeatPreference( String name ) {
72
73 // Assign blank final
74 this.name = name;
75
76 // Enforce preconditions
77 }
78
79 /**
80 * SeatPreference is not a required field in a participant record, therefore
81 * if a null or blank name is passed to this method, an
82 * IllegalArgumentException is <strong>NOT</strong> thrown, but rather
83 * a null instance is returned.
84 * </p><p>
85 * Note: values not defined by this class, will throw a RowingException.
86 */
87 public static SeatPreference getSeatPreference( String name )
88 throws RowingException {
89
90 SeatPreference retVal = null;
91 if ( name != null && name.trim().length() != 0 ) {
92 name = name.trim();
93 if ( name.equalsIgnoreCase( NAME_STARBOARD ) ) {
94 retVal = STARBOARD;
95 }
96 else if ( name.equalsIgnoreCase( NAME_PORT ) ) {
97 retVal = PORT;
98 }
99 else if ( name.equalsIgnoreCase( NAME_STARBOARD_THEN_PORT ) ) {
100 retVal = STARBOARD_THEN_PORT;
101 }
102 else if ( name.equalsIgnoreCase( NAME_PORT_THEN_STARBOARD ) ) {
103 retVal = PORT_THEN_STARBOARD;
104 }
105 else if ( name.equalsIgnoreCase( NAME_COX ) ) {
106 retVal = COX;
107 }
108 else {
109 throw new RowingException( "invalid name == '" + name + "'" );
110 }
111 }
112
113 return retVal;
114 } // getSeatPreference(String)
115
116 public String getName() {
117 return name;
118 }
119
120 public String toString() {
121 return name;
122 }
123
124 public int hashCode() {
125 return this.getName().toUpperCase().hashCode();
126 }
127
128 public static boolean compare( String s1, String s2 ) {
129
130 boolean retVal = false;
131 if ( s1 != null ) {
132 if ( s2 != null ) {
133 retVal = s1.toUpperCase().trim().equals( s2.toUpperCase().trim() );
134 }
135 }
136
137 return retVal;
138 } // compare(String,String)
139
140 public boolean equals( Object o ) {
141
142 boolean retVal = false;
143 if ( o instanceof SeatPreference ) {
144 retVal = this.getName().equalsIgnoreCase( ((SeatPreference)o).getName() );
145 }
146
147 return retVal;
148 } // equals(Object)
149
150 } // SeatPreference
151
152 /*
153 * $Log: SeatPreference.java,v $
154 * Revision 1.3 2003/02/26 03:38:45 rphall
155 * Added copyright and GPL license
156 *
157 * Revision 1.2 2002/02/18 18:05:09 rphall
158 * Ran dos2unix to remove ^M (carriage return) from end of lines
159 *
160 * Revision 1.1.1.1 2002/01/03 21:57:28 rphall
161 * Initial load, 5th try, Jan-03-2002 4:57 PM
162 *
163 * Revision 1.7 2001/12/19 02:19:16 rphall
164 * Fixed static getXxx factory method to accept blank names
165 *
166 * Revision 1.6 2001/12/18 16:43:48 rphall
167 * Serializable
168 *
169 * Revision 1.5 2001/12/18 13:29:58 rphall
170 * Simplified 'equals' method
171 *
172 * Revision 1.4 2001/12/15 02:25:03 rphall
173 * Added equals, compareTo, hashCode
174 *
175 * Revision 1.3 2001/12/13 21:17:04 rphall
176 * Fixed handling of null name in static lookup
177 *
178 * Revision 1.2 2001/12/13 01:30:21 rphall
179 * Enrollment business and web objects
180 *
181 * Revision 1.1 2001/11/23 18:34:08 rphall
182 * Major revision.
183 *
184 * Revision 1.2 2001/11/18 18:15:01 rphall
185 * Fixed compilation problems
186 *
187 * Revision 1.1 2001/11/18 17:07:07 rphall
188 * Checkpt before major revision of rowing package
189 *
190 */
191