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: import java.util.Collection;
033: import java.util.HashMap;
034: import java.util.Set;
035:
036: /**
037: * An enumeration of known valid military (or otherwise) services.
038: * The implementation attempts to keep the number of duplicate service
039: * instances (e.g. that are .equals) to a minimum, but there are situations
040: * where this is not practical. Use .equals instead of ==.
041: **/
042:
043: public final class Service implements Serializable {
044:
045: public final static Service CIVILIAN = new Service("Civilian");
046: public final static Service ARMY = new Service("Army");
047: public final static Service NAVY = new Service("Navy");
048: public final static Service AIRFORCE = new Service("Airforce");
049: public final static Service MARINE = new Service("Marine");
050: public final static Service COASTGUARD = new Service("Coastguard");
051: public final static Service JOINT = new Service("Joint");
052: public final static Service OTHER = new Service("Other");
053:
054: private final static HashMap allTable = new HashMap(13);
055: static {
056: allTable.put("Civilian", CIVILIAN);
057: allTable.put("Army", ARMY);
058: allTable.put("Navy", NAVY);
059: allTable.put("Airforce", AIRFORCE);
060: allTable.put("Marine", MARINE);
061: allTable.put("Coastguard", COASTGUARD);
062: allTable.put("Joint", JOINT);
063: allTable.put("Other", OTHER);
064: }
065:
066: public static Collection getServices() {
067: return allTable.values();
068: }
069:
070: public static Set getNames() {
071: return allTable.keySet();
072: }
073:
074: public static Service getService(String name) {
075: return (Service) allTable.get(name);
076: }
077:
078: private String name;
079:
080: /** Constructor takes a String that represents the named Service.
081: * It is preferred to use the constant Services or the getService
082: * method rather than to use the constructor.
083: **/
084: public Service(String v) {
085: if (v == null)
086: throw new IllegalArgumentException();
087: name = v.intern();
088: }
089:
090: public String getName() {
091: return name;
092: }
093:
094: /** @return The name of the Service */
095: public String toString() {
096: return name;
097: }
098:
099: public boolean equals(Object v) {
100: // use == since name strings are interned
101: return (v instanceof Service && name == v.toString());
102: }
103:
104: public int hashCode() {
105: return name.hashCode() + 3;
106: }
107:
108: private void readObject(ObjectInputStream stream)
109: throws ClassNotFoundException, IOException {
110: stream.defaultReadObject();
111: name = name.intern();
112: }
113:
114: }
|