Source code: com/clra/rowing/BoatView.java
1 /*
2 * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3 * Distributed under the GPL license. See doc/COPYING.
4 * $RCSfile: BoatView.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.DBConfiguration;
12 import com.clra.util.ValidationException;
13 import java.io.Serializable;
14 import java.util.Date;
15 import java.util.Map;
16
17 /**
18 * Read-only information about a boat.
19 *
20 * @version $Id: BoatView.java,v 1.3 2003/02/26 03:38:45 rphall Exp $
21 * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
22 */
23 public class BoatView implements Comparable, Serializable {
24
25 private int id = 0;
26 private String name = null;
27 private int size = 0;
28 private String type = null;
29
30 private int hashCode = 0;
31
32 public BoatView(int id, String name, int size, String type)
33 throws ValidationException {
34
35 // Assign blank finals
36 this.id = id;
37 this.name = name;
38 this.size = size;
39 this.type = type;
40
41 this.hashCode = ( new Integer(this.getId()) ).hashCode();
42
43 // Enforce preconditions
44 /*
45 if ( !isValidBoatId( id ) ) {
46 throw new ValidationException( BOAT_ID );
47 }
48 if ( !isValidBoatName( name ) ) {
49 throw new ValidationException( BOAT_ACCOUNT_NAME );
50 }
51 ...
52 */
53
54 } // ctor(..)
55
56 public int getId() {
57 return this.id;
58 }
59
60 public String getName() {
61 return this.name;
62 }
63
64 public int getSize() {
65 return this.size;
66 }
67
68 public String getType() {
69 return this.type;
70 }
71
72 /** Two boats are equal iff their id's are equal. */
73 public boolean equals( Object o ) {
74
75 boolean retVal = false;
76 if ( o instanceof BoatView ) {
77 retVal = this.getId() == ((BoatView)o).getId();
78 }
79
80 return retVal;
81 } // equals(Object)
82
83 /** Boat objects are hashed by id's */
84 public int hashCode() {
85 return hashCode;
86 }
87
88 /**
89 * Defines a natural ordering for boats by name.
90 *
91 * Note: this class has a natural ordering that is inconsistent with equals.
92 * Equality is defined by boat id's, not by boat names.
93 *
94 * @param o A boat object.
95 * @exception ClassCastException if o is not a boat object.
96 */
97 public int compareTo( Object o ) throws ClassCastException {
98 // Precondition
99 if ( !(o instanceof BoatView) ) {
100 throw new ClassCastException( "not a boat object" );
101 }
102
103 BoatView other = (BoatView) o;
104 int retVal;
105
106 // Compare last names (which are never null)
107 String thisName = this.getName();
108 String otherName = other.getName();
109 retVal = thisName.compareToIgnoreCase( otherName );
110
111 return retVal;
112 } // compareTo(Object)
113
114 } // BoatView
115
116 /*
117 * $Log: BoatView.java,v $
118 * Revision 1.3 2003/02/26 03:38:45 rphall
119 * Added copyright and GPL license
120 *
121 * Revision 1.2 2002/02/18 18:03:44 rphall
122 * Ran dos2unix to remove ^M (carriage return) from end of lines
123 *
124 * Revision 1.1.1.1 2002/01/03 21:57:28 rphall
125 * Initial load, 5th try, Jan-03-2002 4:57 PM
126 *
127 * Revision 1.2 2001/11/28 11:53:32 rphall
128 * Made Serializable
129 *
130 * Revision 1.1 2001/11/18 17:07:07 rphall
131 * Checkpt before major revision of rowing package
132 *
133 */
134