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: package org.cougaar.glm.plugins;
027:
028: import org.cougaar.util.log.Logger;
029: import org.cougaar.util.log.Logging;
030:
031: import java.io.Serializable;
032: import java.util.HashMap;
033:
034: /**
035: * Trimmed down, representation of an asset
036: **/
037: public class MaintainedItem implements Serializable {
038:
039: protected String maintainedItemType = null;
040: protected String typeIdentification = null;
041: protected String itemIdentification = null;
042: protected String nomenclature = null;
043: private static HashMap cache = new HashMap();
044: private static Logger logger = Logging
045: .getLogger(MaintainedItem.class);
046:
047: public MaintainedItem() {
048: }
049:
050: public MaintainedItem(String type, String typeId, String itemId,
051: String nomen) {
052: maintainedItemType = type;
053: typeIdentification = typeId;
054: itemIdentification = itemId;
055: nomenclature = nomen;
056: }
057:
058: public String getMaintainedItemType() {
059: return maintainedItemType;
060: }
061:
062: public String getTypeIdentification() {
063: return typeIdentification;
064: }
065:
066: public String getItemIdentification() {
067: return itemIdentification;
068: }
069:
070: public String getNomenclature() {
071: return nomenclature;
072: }
073:
074: public static MaintainedItem findOrMakeMaintainedItem(String type,
075: String typeId, String itemId, String nomen) {
076: if (type == null || typeId == null) {
077: if (logger.isErrorEnabled()) {
078: logger
079: .error("MaintainedItem"
080: + "Type and/or TypeIdentification cannot be null");
081: }
082: return null;
083: }
084: String key = type + typeId;
085: if (itemId != null)
086: key = key + itemId;
087: MaintainedItem item = (MaintainedItem) cache.get(key);
088: if (item == null) {
089: item = new MaintainedItem(type, typeId, itemId, nomen);
090: cache.put(key, item);
091: }
092: return item;
093: }
094:
095: public String toString() {
096: return this .getClass().getName() + ": <" + maintainedItemType
097: + ">, <" + typeIdentification + ">, <"
098: + itemIdentification + ">, <" + nomenclature + ">";
099: }
100:
101: private transient int _hc = 0;
102:
103: public int hashCode() {
104: if (_hc != 0)
105: return _hc;
106: int hc = 1;
107: if (maintainedItemType != null)
108: hc += maintainedItemType.hashCode();
109: if (typeIdentification != null)
110: hc += typeIdentification.hashCode();
111: if (itemIdentification != null)
112: hc += itemIdentification.hashCode();
113: _hc = hc;
114: return hc;
115: }
116:
117: /** Equals for MaintainedItems is equivalent to the test for equal
118: * assets. Assumes
119: **/
120: public boolean equals(Object o) {
121: if (this == o)
122: return true;
123: if (o == null)
124: return false;
125: if (!(this .getClass() == o.getClass()))
126: return false;
127: MaintainedItem oi = (MaintainedItem) o;
128: String oType = oi.getMaintainedItemType();
129: if (oType == null || maintainedItemType == null
130: || !(maintainedItemType.equals(oType)))
131: return false;
132: String oTypeID = oi.getTypeIdentification();
133: if (oTypeID == null || typeIdentification == null
134: || !(typeIdentification.equals(oTypeID)))
135: return false;
136: String oItemID = oi.getItemIdentification();
137: if (oItemID == itemIdentification)
138: return true;
139: if (itemIdentification != null) {
140: return itemIdentification.equals(oItemID);
141: } else {
142: return false;
143: }
144: }
145: }
|