001: /**********************************************************************************
002: *
003: * $Id: GradableObject.java 21419 2007-02-14 00:11:49Z ray@media.berkeley.edu $
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
008: *
009: * Licensed under the Educational Community License, Version 1.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.opensource.org/licenses/ecl1.php
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: **********************************************************************************/package org.sakaiproject.tool.gradebook;
022:
023: import java.io.Serializable;
024:
025: import org.apache.commons.lang.builder.EqualsBuilder;
026: import org.apache.commons.lang.builder.HashCodeBuilder;
027: import org.apache.commons.lang.builder.ToStringBuilder;
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030:
031: /**
032: * A GradableObject is a component of a Gradebook for which students can be
033: * assigned a GradeRecord.
034: *
035: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
036: */
037: public abstract class GradableObject implements Serializable {
038: protected static final Log log = LogFactory
039: .getLog(GradableObject.class);
040:
041: protected Long id;
042: protected int version;
043: protected Gradebook gradebook;
044: protected String name;
045: protected Double mean; // not persisted; not used in all contexts (in Overview & Assignment Grading,
046: // not in Roster or Student View)
047:
048: protected boolean removed; // We had trouble with foreign key constraints in the UCB pilot when
049:
050: // instructors "emptied" all scores for an assignment and then tried to
051: // delete the assignment. Instead, we should hide the "removed" assignments
052: // from the app by filtering the removed assignments in the hibernate queries
053:
054: /**
055: * @return Whether this gradable object is a course grade
056: */
057: public abstract boolean isCourseGrade();
058:
059: /**
060: * @return Returns the id.
061: */
062: public Long getId() {
063: return id;
064: }
065:
066: /**
067: * @param id The id to set.
068: */
069: public void setId(Long id) {
070: this .id = id;
071: }
072:
073: /**
074: * @return Returns the gradebook.
075: */
076: public Gradebook getGradebook() {
077: return gradebook;
078: }
079:
080: /**
081: * @param gradebook The gradebook to set.
082: */
083: public void setGradebook(Gradebook gradebook) {
084: this .gradebook = gradebook;
085: }
086:
087: /**
088: * @return Returns the mean.
089: */
090: public Double getMean() {
091: return mean;
092: }
093:
094: /**
095: * @return Returns the mean while protecting against displaying NaN.
096: */
097: public Double getFormattedMean() {
098: if (mean == null || mean.equals(new Double(Double.NaN))) {
099: return null;
100: } else {
101: return new Double(mean.doubleValue() / 100.0);
102: }
103: }
104:
105: /**
106: * @param mean The mean to set.
107: */
108: public void setMean(Double mean) {
109: this .mean = mean;
110: }
111:
112: /**
113: * This should really only be a field in Assignment objects, since
114: * the string describing CourseGrade needs to allow for localization.
115: * Unfortunately, such we keep CourseGrade and Assignment objects in
116: * the same table, and since we want Assignment names to be enforced
117: * as non-nullable, we're stuck with a bogus CourseGrade "name" field
118: * for now. The UI will have to be smart enough to disregard it.
119: *
120: * @return Returns the name.
121: */
122: public String getName() {
123: return name;
124: }
125:
126: /**
127: * @param name The name to set.
128: */
129: public void setName(String name) {
130: this .name = name;
131: }
132:
133: /**
134: * @return Returns the version.
135: */
136: public int getVersion() {
137: return version;
138: }
139:
140: /**
141: * @param version The version to set.
142: */
143: public void setVersion(int version) {
144: this .version = version;
145: }
146:
147: /**
148: * @return Returns the removed.
149: */
150: public boolean isRemoved() {
151: return removed;
152: }
153:
154: /**
155: * @param removed The removed to set.
156: */
157: public void setRemoved(boolean removed) {
158: this .removed = removed;
159: }
160:
161: public String toString() {
162: return new ToStringBuilder(this ).append("id", id).append(
163: "name", name).toString();
164:
165: }
166:
167: public boolean equals(Object other) {
168: if (!(other instanceof GradableObject)) {
169: return false;
170: }
171: GradableObject go = (GradableObject) other;
172: return new EqualsBuilder().append(gradebook, go.getGradebook())
173: .append(id, go.getId()).append(name, go.getName())
174: .isEquals();
175: }
176:
177: public int hashCode() {
178: return new HashCodeBuilder().append(gradebook).append(id)
179: .append(name).toHashCode();
180: }
181: }
|