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 org.cougaar.planning.ldm.measure.Latitude;
030: import org.cougaar.planning.ldm.measure.Longitude;
031:
032: public class GeolocLocationImpl extends NamedPositionImpl implements
033: GeolocLocation, NewGeolocLocation {
034:
035: String GeolocCode, InstallTypeCode, CSCode, CSName, IcaoCode;
036:
037: public GeolocLocationImpl() {
038: super ();
039: }
040:
041: public GeolocLocationImpl(Latitude la, Longitude lon, String name) {
042: super (la, lon, name);
043: }
044:
045: /** @return String - the geoloc code representing this position */
046: public String getGeolocCode() {
047: return GeolocCode;
048: }
049:
050: /** @return String - the installation type code representing this position*/
051: public String getInstallationTypeCode() {
052: return InstallTypeCode;
053: }
054:
055: /** @return String - the Country state code representing this position*/
056: public String getCountryStateCode() {
057: return CSCode;
058: }
059:
060: /** @return String - the Country state name representing this position*/
061: public String getCountryStateName() {
062: return CSName;
063: }
064:
065: /** @return String - the Icao code representing this position*/
066: public String getIcaoCode() {
067: return IcaoCode;
068: }
069:
070: /** @param aGeolocCode - set the geoloc code representing this position */
071: public void setGeolocCode(String aGeolocCode) {
072: if (aGeolocCode != null)
073: aGeolocCode = aGeolocCode.intern();
074: GeolocCode = aGeolocCode;
075: }
076:
077: /** @param aInstCode - set the installation type code representing this position*/
078: public void setInstallationTypeCode(String aInstCode) {
079: if (aInstCode != null)
080: aInstCode = aInstCode.intern();
081: InstallTypeCode = aInstCode;
082: }
083:
084: /** @param aCSCode - set the Country state code representing this position*/
085: public void setCountryStateCode(String aCSCode) {
086: if (aCSCode != null)
087: aCSCode = aCSCode.intern();
088: CSCode = aCSCode;
089: }
090:
091: /** @param aCSName - set the Country state name representing this position*/
092: public void setCountryStateName(String aCSName) {
093: if (aCSName != null)
094: aCSName = aCSName.intern();
095: CSName = aCSName;
096: }
097:
098: /** @param anIcaoCode - set the Icao code representing this position*/
099: public void setIcaoCode(String anIcaoCode) {
100: if (anIcaoCode != null)
101: anIcaoCode = anIcaoCode.intern();
102: IcaoCode = anIcaoCode;
103: }
104:
105: public String toString() {
106: String n = getName();
107: return ((n != null) ? (super .toString() + " " + GeolocCode
108: + "(" + n + ")")
109: : (super .toString() + " " + GeolocCode));
110: }
111:
112: public Object clone() {
113: GeolocLocationImpl gli = new GeolocLocationImpl();
114: gli.setGeolocCode(GeolocCode);
115: gli.setInstallationTypeCode(InstallTypeCode);
116: gli.setCountryStateCode(CSCode);
117: gli.setCountryStateName(CSName);
118: gli.setIcaoCode(IcaoCode);
119: gli.setName(getName());
120: gli.setLatitude(lat);
121: gli.setLongitude(lon);
122: return gli;
123: }
124:
125: public boolean equals(Object object) {
126: if (object == null) {
127: return false;
128: }
129:
130: if (object == this ) {
131: return true;
132: }
133:
134: if (!(object instanceof GeolocLocation)) {
135: return false;
136: }
137:
138: GeolocLocation other = (GeolocLocation) object;
139:
140: return (matches(getGeolocCode(), other.getGeolocCode())
141: && matches(getInstallationTypeCode(), other
142: .getInstallationTypeCode())
143: && matches(getCountryStateCode(), other
144: .getCountryStateCode())
145: && matches(getCountryStateName(), other
146: .getCountryStateName())
147: && matches(getIcaoCode(), other.getIcaoCode())
148: && matches(getName(), other.getName())
149: && matches(getLatitude(), other.getLatitude()) && matches(
150: getLongitude(), other.getLongitude()));
151: }
152:
153: private transient int _hc = 0;
154:
155: public int hashCode() {
156: if (_hc == 0) {
157: String n = getGeolocCode();
158: if (n == null)
159: n = getName();
160: if (n != null) {
161: _hc = n.hashCode();
162: } else {
163: _hc = 1;
164: }
165: }
166:
167: return _hc;
168: }
169:
170: private boolean matches(Object a, Object b) {
171: return (a == null) ? (b == null) : (a.equals(b));
172: }
173:
174: }
|