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.ldm.asset;
027:
028: import org.cougaar.planning.ldm.measure.Area;
029: import org.cougaar.planning.ldm.measure.Distance;
030: import org.cougaar.planning.ldm.measure.Mass;
031: import org.cougaar.planning.ldm.measure.Volume;
032:
033: public class PropertyTest {
034: public static void main(String args[]) {
035: NewPhysicalPG p = PropertyGroupFactory.newPhysicalPG();
036: p.setLength(Distance.newMeters(23.4));
037: p.setWidth((Distance) Distance
038: .newMeasure("12", Distance.INCHES));
039: p.setHeight(Distance.newDistance("0.001", Distance.MILES));
040: p.setFootprintArea(Area.newSquareMeters(1.0));
041: p.setVolume(Volume.newCubicCentimeters(123.4));
042: p.setMass(Mass.newTons("3"));
043: System.out.println("Original = " + p.toString());
044:
045: System.out.println(" length = " + p.getLength());
046: System.out.println(" Width = " + p.getWidth());
047: System.out.println(" Height = " + p.getHeight());
048: System.out.println(" FootprintArea = " + p.getFootprintArea());
049: System.out.println(" Volume = " + p.getVolume());
050: System.out.println(" Mass = " + p.getMass());
051:
052: System.out.println();
053: System.out.println(" length (in m) = "
054: + p.getLength().getMeters());
055: System.out.println(" length (in mi) = "
056: + p.getLength().getMiles());
057: System.out.println(" length (in nmi) = "
058: + p.getLength().getNauticalMiles());
059: System.out.println(" length (in yds) = "
060: + p.getLength().getYards());
061: System.out.println(" length (in ft) = "
062: + p.getLength().getFeet());
063: System.out.println(" length (in inches) = "
064: + p.getLength().getInches());
065: System.out.println(" length (in km) = "
066: + p.getLength().getKilometers());
067: System.out.println(" length (in cm) = "
068: + p.getLength().getCentimeters());
069: System.out.println(" length (in mm) = "
070: + p.getLength().getMillimeters());
071: System.out.println(" length (in furlongs) = "
072: + p.getLength().getValue(Distance.FURLONGS));
073: System.out.println();
074:
075: Object key = new Object();
076: Object wrong = new Object();
077: PhysicalPG p1 = (PhysicalPG) p.lock(key);
078: System.out.println("Locked = " + p1.toString());
079: NewPhysicalPG p2 = null;
080: try {
081: p2 = (NewPhysicalPG) p1.unlock(key);
082: } catch (Exception e) {
083: System.out.println("Couldn't unlock with rightkey.");
084: }
085:
086: System.out.println("Unlocked = " + p2.toString());
087: try {
088: System.out.println("Wrong Key = "
089: + ((NewPhysicalPG) p1.unlock(wrong)).toString());
090: } catch (Exception e) {
091: System.out.println("Couldn't unlock with wrong key.");
092: }
093: System.out.println("Original length = " + p.getLength());
094: System.out.println("Locked length = " + p1.getLength());
095: System.out.println("Unlocked length = " + p2.getLength());
096: p.setLength(Distance.newMeters(10.4));
097: System.out.println("(new) Original length = " + p.getLength());
098: System.out.println("(new) Locked length = " + p1.getLength());
099: System.out.println("(new) Unlocked length = " + p2.getLength());
100:
101: NewPhysicalPG p3 = PropertyGroupFactory.newPhysicalPG(p1);
102: System.out.println("new (from prototype) = " + p3);
103: p3.setWidth(Distance.newInches("18"));
104: System.out.println("new width = " + p3.getWidth());
105: //System.out.println("original width = "+p.getWidth());
106: // PropertyGroup Prototypes not supported - use Asset prototypes instead
107: /*
108: System.out.println("original width (via getPrototype) = "+
109: ((PhysicalPG)(p3.getPrototype())).getWidth());
110:
111: */
112: }
113: }
|