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: /* hand generated! */
028:
029: package org.cougaar.glm.ldm.asset;
030:
031: import java.beans.IntrospectionException;
032: import java.beans.PropertyDescriptor;
033: import java.io.IOException;
034: import java.io.ObjectInputStream;
035: import java.io.ObjectOutputStream;
036: import java.util.Vector;
037:
038: import org.cougaar.planning.ldm.asset.Asset;
039: import org.cougaar.planning.ldm.measure.Latitude;
040: import org.cougaar.planning.ldm.measure.Longitude;
041:
042: public class TransportationGraph extends Facility {
043: public TransportationGraph() {
044: this (new Vector(), Longitude.newLongitude(179.0d), Longitude
045: .newLongitude(-180.0d), Latitude.newLatitude(90.0d),
046: Latitude.newLatitude(-90.0d));
047: }
048:
049: public TransportationGraph(TransportationGraph prototype) {
050: super (prototype);
051: myNodes = new Vector();
052: myMinLong = Longitude.newLongitude(179.0d);
053: myMaxLong = Longitude.newLongitude(-180.0d);
054: myMinLat = Latitude.newLatitude(90.0d);
055: myMaxLat = Latitude.newLatitude(-90.0d);
056: }
057:
058: public TransportationGraph(Vector nodes, Longitude minlong,
059: Longitude maxlong, Latitude minlat, Latitude maxlat) {
060: myNodes = nodes;
061: myMinLong = minlong;
062: myMaxLong = maxlong;
063: myMinLat = minlat;
064: myMaxLat = maxlat;
065: }
066:
067: /** For infrastructure only - use LdmFactory.copyInstance instead. **/
068: public Object clone() throws CloneNotSupportedException {
069: TransportationGraph _thing = (TransportationGraph) super
070: .clone();
071: if (myNodes != null)
072: _thing.setNodes(myNodes);
073: if (myMinLong != null)
074: _thing.setMinLong(myMinLong);
075: if (myMaxLong != null)
076: _thing.setMaxLong(myMaxLong);
077: if (myMinLat != null)
078: _thing.setMinLat(myMinLat);
079: if (myMaxLat != null)
080: _thing.setMaxLat(myMaxLat);
081: return _thing;
082: }
083:
084: /** create an instance of the right class for copy operations **/
085: public Asset instanceForCopy() {
086: return new TransportationGraph();
087: }
088:
089: /** create an instance of this prototype **/
090: public Asset createInstance() {
091: return new TransportationGraph(this );
092: }
093:
094: private transient Longitude myMinLong;
095:
096: public Longitude getMinLong() {
097: if (myMinLong == null) {
098: if (myPrototype != null) {
099: return ((TransportationGraph) myPrototype).getMinLong();
100: } else {
101: myMinLong = null;
102: }
103: }
104: return myMinLong;
105: }
106:
107: public void setMinLong(Longitude arg_MinLong) {
108: myMinLong = arg_MinLong;
109: }
110:
111: private transient Longitude myMaxLong;
112:
113: public Longitude getMaxLong() {
114: if (myMaxLong == null) {
115: if (myPrototype != null) {
116: return ((TransportationGraph) myPrototype).getMaxLong();
117: } else {
118: myMaxLong = null;
119: }
120: }
121: return myMaxLong;
122: }
123:
124: public void setMaxLong(Longitude arg_MaxLong) {
125: myMaxLong = arg_MaxLong;
126: }
127:
128: private transient Latitude myMinLat;
129:
130: public Latitude getMinLat() {
131: if (myMinLat == null) {
132: if (myPrototype != null) {
133: return ((TransportationGraph) myPrototype).getMinLat();
134: } else {
135: myMinLat = null;
136: }
137: }
138: return myMinLat;
139: }
140:
141: public void setMinLat(Latitude arg_MinLat) {
142: myMinLat = arg_MinLat;
143: }
144:
145: private transient Latitude myMaxLat;
146:
147: public Latitude getMaxLat() {
148: if (myMaxLat == null) {
149: if (myPrototype != null) {
150: return ((TransportationGraph) myPrototype).getMaxLat();
151: } else {
152: myMaxLat = null;
153: }
154: }
155: return myMaxLat;
156: }
157:
158: public void setMaxLat(Latitude arg_MaxLat) {
159: myMaxLat = arg_MaxLat;
160: }
161:
162: private transient Vector myNodes;
163:
164: public Vector getNodes() {
165: if (myNodes == null) {
166: if (myPrototype != null) {
167: return ((TransportationGraph) myPrototype).getNodes();
168: } else {
169: myNodes = null;
170: }
171: }
172: return myNodes;
173: }
174:
175: public void setNodes(Vector nodes) {
176: myNodes = nodes;
177: }
178:
179: public int getNumNodes() {
180: return myNodes.size();
181: }
182:
183: public void addNode(TransportationNode node) {
184: myNodes.addElement(node);
185: ExpandBounds(node);
186: }
187:
188: public void removeNode(TransportationNode node) {
189: myNodes.removeElement(node);
190: AdjustBounds(node);
191: }
192:
193: public void addGraphByNodes(Vector newnodes) {
194: for (int i = 0; i < newnodes.size(); i++) {
195: try {
196: addNode((TransportationNode) newnodes.elementAt(i));
197: } catch (Exception e) {
198: e.printStackTrace();
199: System.err.println("!!!error: got invalid node "
200: + "while setting nodes in TransportationGraph");
201: }
202: }
203: }
204:
205: public void setGraphByNodes(Vector newnodes) {
206: myNodes = new Vector();
207: myMaxLat = Latitude.newLatitude(Double.MIN_VALUE);
208: myMinLat = Latitude.newLatitude(Double.MAX_VALUE);
209: myMaxLong = Longitude.newLongitude(Double.MIN_VALUE);
210: myMinLong = Longitude.newLongitude(Double.MAX_VALUE);
211: addGraphByNodes(newnodes);
212: }
213:
214: public void addGraph(TransportationGraph otherGraph) {
215: Vector otherNodes = otherGraph.getNodes();
216: for (int i = 0; i < otherGraph.getNumNodes(); i++) {
217: try {
218: if (!myNodes.contains(otherNodes.elementAt(i)))
219: addNode((TransportationNode) otherNodes
220: .elementAt(i));
221: } catch (Exception e) {
222: e.printStackTrace();
223: System.err.println("!!!error: got invalid node "
224: + "while setting nodes in TransportationGraph");
225: }
226: }
227: }
228:
229: private void ExpandBounds(TransportationNode node) {
230: Latitude nodelat = node.getGeolocLocation().getLatitude();
231: Longitude nodelong = node.getGeolocLocation().getLongitude();
232:
233: if (nodelat.getValue(Latitude.DEGREES) < myMinLat
234: .getValue(Latitude.DEGREES))
235: myMinLat = Latitude.newLatitude(nodelat
236: .getValue(Latitude.DEGREES));
237: if (nodelat.getValue(Latitude.DEGREES) > myMaxLat
238: .getValue(Latitude.DEGREES))
239: myMaxLat = Latitude.newLatitude(nodelat
240: .getValue(Latitude.DEGREES));
241: if (nodelong.getValue(Longitude.DEGREES) < myMinLong
242: .getValue(Longitude.DEGREES))
243: myMinLong = Longitude.newLongitude(nodelong
244: .getValue(Longitude.DEGREES));
245: if (nodelong.getValue(Longitude.DEGREES) > myMaxLong
246: .getValue(Longitude.DEGREES))
247: myMaxLong = Longitude.newLongitude(nodelong
248: .getValue(Longitude.DEGREES));
249: }
250:
251: private void AdjustBounds(TransportationNode node) {
252: Latitude nodelat = node.getGeolocLocation().getLatitude();
253: Longitude nodelong = node.getGeolocLocation().getLongitude();
254:
255: double mindegrees = Double.MAX_VALUE;
256: double maxdegrees = Double.MIN_VALUE;
257: double target;
258: if (nodelat.equals(myMinLat) || nodelat.equals(myMaxLat)) {
259: for (int i = 0; i < myNodes.size(); i++) {
260: target = ((TransportationNode) myNodes.elementAt(i))
261: .getGeolocLocation().getLatitude().getValue(
262: Latitude.DEGREES);
263: if (target < mindegrees) {
264: mindegrees = target;
265: myMinLat = ((TransportationNode) myNodes
266: .elementAt(i)).getGeolocLocation()
267: .getLatitude();
268: }
269: if (target > maxdegrees) {
270: maxdegrees = target;
271: myMaxLat = ((TransportationNode) myNodes
272: .elementAt(i)).getGeolocLocation()
273: .getLatitude();
274: }
275: }
276: }
277: mindegrees = Double.MAX_VALUE;
278: maxdegrees = Double.MIN_VALUE;
279: if (nodelong.equals(myMinLong) || nodelong.equals(myMaxLong)) {
280: for (int i = 0; i < myNodes.size(); i++) {
281: target = ((TransportationNode) myNodes.elementAt(i))
282: .getGeolocLocation().getLongitude().getValue(
283: Longitude.DEGREES);
284: if (target < mindegrees) {
285: mindegrees = target;
286: myMinLong = ((TransportationNode) myNodes
287: .elementAt(i)).getGeolocLocation()
288: .getLongitude();
289: }
290: if (target > maxdegrees) {
291: maxdegrees = target;
292: myMaxLong = ((TransportationNode) myNodes
293: .elementAt(i)).getGeolocLocation()
294: .getLongitude();
295: }
296: }
297: }
298: }
299:
300: // Read/Write Methods
301: private void writeObject(ObjectOutputStream out) throws IOException {
302: out.defaultWriteObject();
303: out.writeObject(myNodes);
304: out.writeObject(myMinLong);
305: out.writeObject(myMaxLong);
306: out.writeObject(myMinLat);
307: out.writeObject(myMaxLat);
308: }
309:
310: private void readObject(ObjectInputStream in)
311: throws ClassNotFoundException, IOException {
312: in.defaultReadObject();
313: myNodes = (Vector) in.readObject();
314: myMinLong = (Longitude) in.readObject();
315: myMaxLong = (Longitude) in.readObject();
316: myMinLat = (Latitude) in.readObject();
317: myMaxLat = (Latitude) in.readObject();
318: }
319:
320: // beaninfo support
321: private static PropertyDescriptor properties[];
322: static {
323: try {
324: properties = new PropertyDescriptor[6];
325: properties[0] = new PropertyDescriptor("FacilityPG",
326: TransportationGraph.class, "getFacilityPG", null);
327: properties[1] = new PropertyDescriptor("Nodes",
328: TransportationGraph.class, "getNodes", null);
329: properties[2] = new PropertyDescriptor("MinLong",
330: TransportationGraph.class, "getMinLong", null);
331: properties[3] = new PropertyDescriptor("MaxLong",
332: TransportationGraph.class, "getMaxLong", null);
333: properties[4] = new PropertyDescriptor("MinLat",
334: TransportationGraph.class, "getMinLat", null);
335: properties[5] = new PropertyDescriptor("MaxLat",
336: TransportationGraph.class, "getMaxLat", null);
337: } catch (IntrospectionException ie) {
338: }
339: }
340:
341: public PropertyDescriptor[] getPropertyDescriptors() {
342: PropertyDescriptor[] pds = super .getPropertyDescriptors();
343: PropertyDescriptor[] ps = new PropertyDescriptor[pds.length + 6];
344: System.arraycopy(pds, 0, ps, 0, pds.length);
345: System.arraycopy(properties, 0, ps, pds.length, 6);
346: return ps;
347: }
348: }
|