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.planning.ldm.plan;
028:
029: /**
030: * An AspectValue with a location instead of a value.
031: *
032: */
033:
034: public class AspectLocation extends TypedAspectValue {
035: private Location loc_value;
036:
037: protected AspectLocation(int type, Location new_loc_value) {
038: super (type);
039: this .loc_value = new_loc_value;
040: }
041:
042: private static boolean hack_warnedUser; // FIXME big hack!
043:
044: public static AspectValue create(int type, Object o) {
045: if (o instanceof Number && ((Number) o).doubleValue() == 0.0) {
046: if (!hack_warnedUser) {
047: // this bug can easily occur in the thousands, so we
048: // only make a fuss this once
049: hack_warnedUser = true;
050: org.cougaar.util.log.LoggerFactory
051: .getInstance()
052: .createLogger(AspectLocation.class)
053: .warn(
054: "BUG 2509: create("
055: + type
056: + ", "
057: + o
058: + ") with non-location type "
059: + (o == null ? "null" : (o
060: .getClass().getName()
061: + ": " + o))
062: + "! This will be the *only* warning!",
063: new RuntimeException("Trace"));
064: }
065: // bogus!
066: o = new Location() {
067: };
068: }
069: if (o instanceof Location) {
070: return new AspectLocation(type, (Location) o);
071: } else {
072: throw new IllegalArgumentException(
073: "Cannot construct an AspectLocation from "
074: + (o == null ? "null" : (o.getClass()
075: .getName()
076: + ": " + o)));
077: }
078: }
079:
080: public final double doubleValue() {
081: throw new IllegalArgumentException(
082: "AspectLocations do not have numeric values");
083: }
084:
085: public final long longValue() {
086: throw new IllegalArgumentException(
087: "AspectLocations do not have numeric values");
088: }
089:
090: public final float floatValue() {
091: throw new IllegalArgumentException(
092: "AspectLocations do not have numeric values");
093: }
094:
095: public final int intValue() {
096: throw new IllegalArgumentException(
097: "AspectLocations do not have numeric values");
098: }
099:
100: /** The location associated with the AspectValue.
101: * @note locationValue is the preferred method.
102: */
103: public final Location getLocationValue() {
104: return loc_value;
105: }
106:
107: /** The location associated with the AspectValue. */
108: public final Location locationValue() {
109: return loc_value;
110: }
111:
112: public int hashCode() {
113: return getType() + loc_value.hashCode();
114: }
115:
116: public String toString() {
117: return loc_value + "[" + getType() + "]";
118: }
119:
120: public boolean nearlyEquals(Object o) {
121: return (o instanceof AspectValue && this
122: .equals((AspectValue) o));
123: }
124:
125: public boolean equals(AspectValue v) {
126: if (v instanceof AspectLocation) {
127: AspectLocation loc_v = (AspectLocation) v;
128: return (loc_v.getAspectType() == getType() && loc_v
129: .getLocationValue() == getLocationValue());
130: } else {
131: return false;
132: }
133: }
134: }
|