Source code: com/clra/rowing/RowingSessionLevel.java
1 /*
2 * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3 * Distributed under the GPL license. See doc/COPYING.
4 * $RCSfile: RowingSessionLevel.java,v $
5 * $Date: 2003/02/26 03:38:45 $
6 * $Revision: 1.3 $
7 */
8
9 package com.clra.rowing;
10
11 import com.clra.util.ValidationException;
12 import java.io.Serializable;
13 import java.rmi.RemoteException;
14 import java.util.Date;
15 import java.util.Map;
16 import javax.ejb.EJBObject;
17
18 /**
19 * Represents the level of a rowing session.
20 *
21 * @version $Id: RowingSessionLevel.java,v 1.3 2003/02/26 03:38:45 rphall Exp $
22 * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
23 */
24 public class RowingSessionLevel implements Comparable, Serializable {
25
26 public final static String NAME_LTR = "LTR";
27
28 public final static String NAME_REGULAR = "REGULAR";
29
30 public final static RowingSessionLevel LTR =
31 new RowingSessionLevel( NAME_LTR );
32
33 public final static RowingSessionLevel REGULAR =
34 new RowingSessionLevel( NAME_REGULAR );
35
36 private final String name;
37
38 protected RowingSessionLevel( String name ) {
39
40 // Assign blank final
41 this.name = name;
42
43 // Enforce preconditions
44 }
45
46 public static RowingSessionLevel getLevel( String name )
47 throws RowingException {
48
49 // Preconditions
50 if ( name == null || name.trim().length() == 0 ) {
51 throw new RowingException( "invalid level name" );
52 }
53
54 RowingSessionLevel retVal = null;
55 name = name.trim();
56 if ( name.equalsIgnoreCase( NAME_LTR ) ) {
57 retVal = LTR;
58 }
59 else if ( name.equalsIgnoreCase( NAME_REGULAR ) ) {
60 retVal = REGULAR;
61 }
62 else {
63 throw new RowingException( "invalid name == '" + name + "'" );
64 }
65
66 return retVal;
67 } // getLevel(String)
68
69 public String getName() {
70 return name;
71 }
72
73 public String toString() {
74 return name;
75 }
76
77 public boolean equals( Object o ) {
78
79 boolean retVal = false;
80 if ( o instanceof RowingSessionLevel ) {
81 retVal = getName().equalsIgnoreCase( ((RowingSessionLevel)o).getName() );
82 }
83
84 return retVal;
85 } // equals(Object)
86
87 public int hashCode() {
88 return getName().toUpperCase().hashCode();
89 }
90
91 /**
92 * Compares a level to other levels and valid level names. The default
93 * order is described in the documentation for
94 * <tt>DefaultRowingSessionLevelComparator</tt>
95 * @param o a non-null RowingSessionLevel or a String NAME of a level
96 * @see DefaultRowingSessionLevelComparator
97 */
98 public int compareTo( Object o ) {
99 return DefaultRowingSessionLevelComparator.staticCompare( this, o );
100 }
101
102 } // RowingSessionLevel
103
104 /*
105 * $Log: RowingSessionLevel.java,v $
106 * Revision 1.3 2003/02/26 03:38:45 rphall
107 * Added copyright and GPL license
108 *
109 * Revision 1.2 2002/02/18 18:04:54 rphall
110 * Ran dos2unix to remove ^M (carriage return) from end of lines
111 *
112 * Revision 1.1.1.1 2002/01/03 21:57:28 rphall
113 * Initial load, 5th try, Jan-03-2002 4:57 PM
114 *
115 * Revision 1.7 2001/12/18 13:31:07 rphall
116 * Whitespace
117 *
118 * Revision 1.6 2001/12/07 01:07:24 rphall
119 * Checkpt: before debugging slow perf
120 *
121 * Revision 1.5 2001/12/06 21:26:48 rphall
122 * Checkpt
123 *
124 * Revision 1.4 2001/12/06 04:47:20 rphall
125 * Added equals(Object) and hashCode()
126 *
127 * Revision 1.3 2001/11/30 11:38:00 rphall
128 * First working version, RowingSession entity bean
129 *
130 * Revision 1.2 2001/11/29 15:42:54 rphall
131 * Added static utility that looks up instance by name
132 *
133 * Revision 1.1 2001/11/23 18:34:08 rphall
134 * Major revision.
135 *
136 */
137