01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.planning.ldm.plan;
28:
29: import java.util.HashMap;
30:
31: /**
32: * Relationship - maps relationship between any two objects
33: * Role describes the Role the direct object is performing for the
34: * indirect object.
35: * BOZO think up better terms than direct/indirect object
36: **/
37:
38: public class RelationshipType {
39: private static HashMap myTypes = new HashMap(3);
40:
41: public static RelationshipType create(String firstSuffix,
42: String secondSuffix) {
43:
44: RelationshipType existing = get(firstSuffix);
45:
46: if (existing == null) {
47: return new RelationshipType(firstSuffix, secondSuffix);
48: } else if ((existing.getFirstSuffix().equals(firstSuffix))
49: && (existing.getSecondSuffix().equals(secondSuffix))) {
50: return existing;
51: } else {
52: throw new java.lang.IllegalArgumentException(
53: "First suffix " + firstSuffix + " or "
54: + " second suffix " + secondSuffix
55: + " already used in - " + existing);
56: }
57:
58: }
59:
60: public static RelationshipType get(String suffix) {
61: return (RelationshipType) myTypes.get(suffix);
62: }
63:
64: private String myFirstSuffix;
65: private String mySecondSuffix;
66:
67: public String getFirstSuffix() {
68: return myFirstSuffix;
69: }
70:
71: public String getSecondSuffix() {
72: return mySecondSuffix;
73: }
74:
75: public String toString() {
76: return myFirstSuffix + ", " + mySecondSuffix;
77: }
78:
79: private RelationshipType(String firstSuffix, String secondSuffix) {
80: myFirstSuffix = firstSuffix;
81: mySecondSuffix = secondSuffix;
82:
83: myTypes.put(firstSuffix, this );
84: myTypes.put(secondSuffix, this );
85: }
86:
87: public static void main(String[] args) {
88: create("Superior", "Subordinate");
89: create("Provider", "Customer");
90: //create("aaa", "Customer");
91: //create("Superior", "bbb");
92:
93: System.out.println("Match on chocolate - " + get("chocolate"));
94: System.out.println("Match on Superior - " + get("Superior"));
95: System.out.println("Match on Customer - " + get("Customer"));
96:
97: }
98: }
|