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: // Source file: LDM/AggregateAsset.java
027: // Subsystem: LDM
028: // Module: AggregateAsset
029:
030: package org.cougaar.planning.ldm.asset;
031:
032: import java.beans.IntrospectionException;
033: import java.beans.PropertyDescriptor;
034: import java.io.IOException;
035: import java.io.ObjectInputStream;
036: import java.io.ObjectOutputStream;
037:
038: public class AggregateAssetAdapter extends Asset {
039: private transient Asset myAsset;
040: private long thequantity;
041:
042: AggregateAssetAdapter() {
043: }
044:
045: AggregateAssetAdapter(AggregateAssetAdapter prototype) {
046: super (prototype);
047: myAsset = prototype.getAsset();
048: }
049:
050: public Asset getAsset() {
051: return myAsset;
052: }
053:
054: public void setAsset(Asset arg_Asset) {
055: myAsset = arg_Asset;
056: }
057:
058: public long getQuantity() {
059: return thequantity;
060: }
061:
062: void setQuantity(long quantity) {
063: thequantity = quantity;
064: }
065:
066: private void readObject(ObjectInputStream stream)
067: throws ClassNotFoundException, IOException {
068: stream.defaultReadObject();
069: myAsset = (Asset) stream.readObject();
070: }
071:
072: private void writeObject(ObjectOutputStream stream)
073: throws IOException {
074: stream.defaultWriteObject();
075: stream.writeObject(myAsset);
076: }
077:
078: private static PropertyDescriptor properties[];
079: static {
080: try {
081: properties = new PropertyDescriptor[2];
082: properties[0] = new PropertyDescriptor("Asset",
083: AggregateAssetAdapter.class, "getAsset", null);
084: properties[1] = new PropertyDescriptor("Quantity",
085: AggregateAssetAdapter.class, "getQuantity", null);
086: } catch (IntrospectionException ie) {
087: }
088: }
089:
090: public PropertyDescriptor[] getPropertyDescriptors() {
091: PropertyDescriptor[] pds = super .getPropertyDescriptors();
092: PropertyDescriptor[] ps = new PropertyDescriptor[pds.length
093: + properties.length];
094: System.arraycopy(pds, 0, ps, 0, pds.length);
095: System.arraycopy(properties, 0, ps, pds.length,
096: properties.length);
097: return ps;
098: }
099:
100: public int hashCode() {
101: int hc = 0;
102: if (myAsset != null)
103: hc = myAsset.hashCode();
104: hc += thequantity;
105: return hc;
106: }
107:
108: /** Equals for aggregate assets is defined as having the
109: * same quantity of the same (equals) asset. TID and IID are
110: * ignored.
111: **/
112: public boolean equals(Object o) {
113: if (this == o)
114: return true;
115: if (!(getClass() == o.getClass()))
116: return false;
117: AggregateAssetAdapter oaa = (AggregateAssetAdapter) o;
118: if (myAsset != null && !(myAsset.equals(oaa.getAsset())))
119: return false;
120: if (thequantity != oaa.getQuantity())
121: return false;
122: ItemIdentificationPG pg1 = getItemIdentificationPG();
123: String id1 = (pg1 == null) ? null : pg1.getItemIdentification();
124: ItemIdentificationPG pg2 = oaa.getItemIdentificationPG();
125: String id2 = (pg2 == null) ? null : pg2.getItemIdentification();
126:
127: // return true IFF
128: return (id1 != null && // both have non-null item ids
129: id1.equals(id2) // which are .equals
130: );
131: }
132: }
|