001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.glm.ldm.plan;
028:
029: import java.io.IOException;
030: import java.io.ObjectInputStream;
031: import java.io.Serializable;
032:
033: import org.cougaar.util.UnaryPredicate;
034:
035: /** Abstract Representation of a personal skill or capability.
036: * Examples of Skills:
037: * MOS/11B = INFANTRYMAN: Army Enlisted: Military Occupational Speciality
038: * ASI/B4 = SNIPER: Army Enlisted: Additional Skill Identifier
039: * SQI/P = PARACHUTIST: Army Enlisted: Special Qualification IDentifier
040: * AOC/15A = AVIATION, GENERAL: Army Commissioned Officer: AreaOfConcentration
041: * OSC/B2 = UH60 PILOT: Army Commissioned Officer: Officer Skill Codes
042: **/
043:
044: public class Skill implements Serializable {
045: protected String type; // eg "MOS"
046: protected String code; // eg "11B"
047: protected String nomenclature; // eg "INFANTRYMAN: Army Enlisted: Military Occupational"
048:
049: public String getType() {
050: return type;
051: }
052:
053: public String getCode() {
054: return code;
055: }
056:
057: public String getNomenclature() {
058: return nomenclature;
059: }
060:
061: /** empty constructor for use by subs, which will need to fill out
062: * type, code, nomenclature members themselves.
063: **/
064: protected Skill() {
065: }
066:
067: /**
068: * @param type Skill class, e.g. MOS, ASI, AOC, SQI, etc.
069: * @param code Skill code, e.g. 11B, B4, P, etc
070: * @param nomenclature Human-readable description of skill, may be null.
071: **/
072: public Skill(String type, String code, String nomenclature) {
073: this .type = type.intern();
074: this .code = code.intern();
075: this .nomenclature = nomenclature;
076: }
077:
078: /** equivalent to Skill(type, code, null). **/
079: public Skill(String type, String code) {
080: this (type, code, null);
081: }
082:
083: /** parser constructor: expects "TYPE/CODE[/NOMENCLATURE]" **/
084: public Skill(String s) {
085: int s1 = s.indexOf('/');
086: if (s1 == -1)
087: throw new IllegalArgumentException("Invalid Skill syntax: "
088: + s);
089: int s2 = s.indexOf('/', s1 + 1);
090: String t = s.substring(0, s1);
091: String c;
092: String n = null;
093: if (s2 == -1) {
094: c = s.substring(s1 + 1);
095: } else {
096: c = s.substring(s1 + 1, s2);
097: n = s.substring(s2 + 1);
098: }
099: this .type = t.intern();
100: this .code = c.intern();
101: this .nomenclature = n;
102:
103: }
104:
105: /** alternate parser constructor **/
106: public static Skill newSkill(String s) {
107: return new Skill(s);
108: }
109:
110: /** @return "TYPE/CODE" **/
111: public String toString() {
112: return type + "/" + code;
113: }
114:
115: /** @return true iff type and code are the same. **/
116: public boolean equals(Object s) {
117: if (s.getClass() == this .getClass()) { // must be exact class!
118: Skill os = (Skill) s;
119: // we can use == because type and code are always interned
120: return (type == os.getType() && code == os.getCode());
121: } else {
122: return false;
123: }
124: }
125:
126: public int hashCode() {
127: return type.hashCode() + code.hashCode();
128: }
129:
130: // make sure type and code remain interned.
131: private void readObject(ObjectInputStream stream)
132: throws ClassNotFoundException, IOException {
133: stream.defaultReadObject();
134: type = type.intern();
135: code = code.intern();
136: }
137:
138: // some utility predicates for Skill types:
139: // Note that the use of == instead of .equals is both intentional
140: // and safe: the types are interned and string literals are always
141: // interned.
142: /** A Predicate which selects for MOS skill type **/
143: public static final UnaryPredicate mosP = new UnaryPredicate() {
144: public boolean execute(Object o) {
145: return (o instanceof Skill && ((Skill) o).getType() == "MOS");
146: }
147: };
148: /** A Predicate which selects for Aircrew skill type **/
149: public static final UnaryPredicate aircrewP = new UnaryPredicate() {
150: public boolean execute(Object o) {
151: return (o instanceof Skill && ((Skill) o).getType() == "Aircrew");
152: }
153: };
154: /** A Predicate which selects for ASI skill type **/
155: public static final UnaryPredicate asiP = new UnaryPredicate() {
156: public boolean execute(Object o) {
157: return (o instanceof Skill && ((Skill) o).getType() == "ASI");
158: }
159: };
160: /** A Predicate which selects for SQI skill type **/
161: public static final UnaryPredicate sqiP = new UnaryPredicate() {
162: public boolean execute(Object o) {
163: return (o instanceof Skill && ((Skill) o).getType() == "SQI");
164: }
165: };
166: /** A Predicate which selects for AOC skill type **/
167: public static final UnaryPredicate aocP = new UnaryPredicate() {
168: public boolean execute(Object o) {
169: return (o instanceof Skill && ((Skill) o).getType() == "AOC");
170: }
171: };
172: /** A Predicate which selects for OSC skill type **/
173: public static final UnaryPredicate oscP = new UnaryPredicate() {
174: public boolean execute(Object o) {
175: return (o instanceof Skill && ((Skill) o).getType() == "OSC");
176: }
177: };
178: }
|