001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-api/src/java/org/sakaiproject/section/api/facade/Role.java $
003: * $Id: Role.java 18134 2006-11-14 18:59:25Z jholtzman@berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.section.api.facade;
021:
022: import java.io.Serializable;
023:
024: /**
025: * A type-safe enumeration of the roles a user can play in a LearningContext.
026: *
027: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
028: *
029: */
030: public class Role implements Serializable {
031: private static final long serialVersionUID = 1L;
032:
033: public static final Role NONE = new Role("", 0);
034: public static final Role INSTRUCTOR = new Role("instructor", 1);
035: public static final Role STUDENT = new Role("student", 2);
036: public static final Role TA = new Role("ta", 3);
037:
038: private final String mName;
039: private final int mValue;
040:
041: /**
042: * Private constructor.
043: */
044: private Role(String name, int value) {
045: mName = name;
046: mValue = value;
047: }
048:
049: /**
050: * Returns whether this instance is the {@link Role#NONE} instance.
051: *
052: * @return whether this instance is the {@link Role#NONE} instance
053: */
054: public boolean isNone() {
055: return this == Role.NONE;
056: }
057:
058: /**
059: * Returns whether this instance is the {@link Role#INSTRUCTOR} instance.
060: *
061: * @return whether this instance is the {@link Role#INSTRUCTOR} instance
062: */
063: public boolean isInstructor() {
064: return this == Role.INSTRUCTOR;
065: }
066:
067: /**
068: * Returns whether this instance is the {@link Role#INSTRUCTOR} instance.
069: *
070: * @return whether this instance is the {@link Role#INSTRUCTOR} instance
071: */
072: public boolean isTeachingAssistant() {
073: return this == Role.TA;
074: }
075:
076: /**
077: * Returns whether this instance is the {@link Role#STUDENT} instance.
078: *
079: * @return whether this instance is the {@link Role#STUDENT} instance
080: */
081: public boolean isStudent() {
082: return this == Role.STUDENT;
083: }
084:
085: /**
086: * Returns the name.
087: *
088: * @return the name.
089: */
090: public String getName() {
091: return mName;
092: }
093:
094: /**
095: * Returns the value.
096: *
097: * @return the value.
098: */
099: public int getValue() {
100: return mValue;
101: }
102:
103: public String getDescription() {
104: return mName;
105: }
106:
107: /**
108: * Returns a String description of this <code>Role</code>.
109: *
110: * Do not use commons-lang ToStringBuilder, since this class will be
111: * deployed to sakai's shared/lib.
112: *
113: * @return a String description of this object.
114: */
115: public String toString() {
116: StringBuffer result = new StringBuffer();
117: result.append("Role[");
118: result.append("name=").append(getName());
119: result.append(", ");
120: result.append("value=").append(getValue());
121: result.append("]");
122: return result.toString();
123: }
124:
125: /**
126: * This role is considered equal if it is a Role whos getValue() is equal
127: * to this object's getValue().
128: *
129: * Do not use commons-lang EqualsBuilder, since this class will be
130: * deployed to sakai's shared/lib.
131: *
132: * @see java.lang.Object#equals(Object)
133: */
134: public boolean equals(Object o) {
135: // Algorithm from "Effective Java" by Joshua Bloch.
136: if (o == this ) {
137: return true;
138: }
139: if (!(o instanceof Role)) {
140: return false;
141: }
142: Role other = (Role) o;
143: return getValue() == other.getValue();
144: }
145:
146: /**
147: * Do not use commons-lang HashCodeBuilder, since this class will be
148: * deployed to sakai's shared/lib.
149: *
150: * @see java.lang.Object#hashCode()
151: */
152: public int hashCode() {
153: int result = 17 * getClass().getName().hashCode();
154: result = 37 * result + getValue();
155: return result;
156: }
157: }
|