001: //
002: /*
003: * <copyright>
004: *
005: * Copyright 1997-2004 BBNT Solutions, LLC
006: * under sponsorship of the Defense Advanced Research Projects
007: * Agency (DARPA).
008: *
009: * You can redistribute this software and/or modify it under the
010: * terms of the Cougaar Open Source License as published on the
011: * Cougaar Open Source Website (www.cougaar.org).
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
017: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
018: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
019: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
020: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
021: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
022: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
023: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024: *
025: * </copyright>
026: */
027:
028: package org.cougaar.glm.util;
029:
030: /**
031: * Static class to extract some information out
032: * of the cargo category codes.
033: * Cargo category codes are 3 letter codes that define
034: * how a piece of cargo can be transported from point A
035: * to point B.
036: */
037: public final class CargoCategoryDecoder {
038:
039: /**
040: * See if the cargo is air transportable.
041: * @param code - 3 letter cargo category code
042: * @return boolean
043: */
044: public static boolean AirTransportable(String code) {
045: code = code.toUpperCase();
046: char c = code.charAt(1);
047: return ((c != '0') && (c != '4') && (c != 'A'));
048: }
049:
050: /**
051: * See if cargo is outsized.
052: * @param code - 3 letter cargo category code
053: * @return boolean
054: */
055:
056: public static boolean isOutsized(String code) {
057: code = code.toUpperCase();
058: char c = code.charAt(1);
059: return ((c == '1') || (c == '5') || (c == 'B'));
060: }
061:
062: /**
063: * See if cargo is oversized.
064: * @param code - 3 letter cargo category code
065: * @return boolean
066: */
067:
068: public static boolean isOversized(String code) {
069: code = code.toUpperCase();
070: char c = code.charAt(1);
071: return ((c == '2') || (c == '6') || (c == 'C'));
072: }
073:
074: /**
075: * See if the cargo fits on a C5 or a C17 Plane.
076: * There is a limit to outsize a C17 can carry. This info
077: * can not be deduced from the cargo category code and must
078: * be found using the length and width info. in ContainCapability.java.
079: * @param code - 3 letter cargo category code
080: * @return boolean
081: */
082:
083: public static boolean FitsOnC5orC17(String code) {
084: code = code.toUpperCase();
085: char c = code.charAt(1);
086: // only bulk organic and oversized
087: // and outsized equipment
088: return (FitsOnAnyPlane(code) || FitsOnC17orC141(code)
089: || c == '1' || c == '5' || c == 'B');
090: }
091:
092: /**
093: * See if the cargo fits on a C17 or C141 plane
094: * @param code - 3 letter cargo category code
095: * @return boolean
096: */
097: public static boolean FitsOnC17orC141(String code) {
098: code = code.toUpperCase();
099: char c = code.charAt(1);
100: // only bulk organic and oversized equipment
101: return (FitsOnAnyPlane(code) || c == '2' || c == '6' || c == 'C');
102: }
103:
104: /**
105: * See if the cargo fits on any kind of US Military
106: * cargo plane.
107: * @param code - 3 letter cargo category code
108: * @return boolean
109: */
110: public static boolean FitsOnAnyPlane(String code) {
111: code = code.toUpperCase();
112: char c = code.charAt(1);
113: // bulk or organic cargo
114: return (c == '3' || c == '7' || c == 'D' || c == '8' || c == '9');
115: }
116:
117: /**
118: * See if the cargo can go by ship. For
119: * the 1998 demo we will assume that anything
120: * can go by ship.
121: * @param code - 3 letter cargo category code
122: * @return boolean
123: */
124: public static boolean FitsOnShip(String code) {
125: return true;
126: }
127:
128: /**
129: * Can be transported down american roads, if not then
130: * it must go by train.
131: * @param code - 3 letter cargo category code
132: * @return boolean
133: */
134: public static boolean IsRoadable(String code) {
135: code = code.toUpperCase();
136: char c = code.charAt(0);
137: return (c != 'A');
138: }
139:
140: /**
141: * Roadable vehicles, may be hazardouz, may require security
142: * @param code - 3 letter cargo category code
143: * @return boolean
144: */
145: public static boolean IsSelfTransportable(String code) {
146: code = code.toUpperCase();
147: char c = code.charAt(0);
148: return (c == 'K' || c == 'L' || c == 'R');
149: }
150:
151: /**
152: * Cargo can be put in a 20 ft container
153: * @param code - 3 letter cargo category code
154: * @return boolean
155: */
156: public static boolean Is20FtContainarizable(String code) {
157: code = code.toUpperCase();
158: char c = code.charAt(2);
159: return (c == 'B');
160: }
161:
162: /**
163: * Cargo can be put in a 20 ft container
164: * @param code - 3 letter cargo category code
165: * @return boolean
166: */
167: public static boolean Is40FtContainarizable(String code) {
168: code = code.toUpperCase();
169: char c = code.charAt(2);
170: return (c == 'C');
171: }
172:
173: /**
174: * See if some cargo can be transported by train
175: * For the 1998 demo we assume that all vehicles are
176: * trainable.
177: * @param code - 3 letter cargo category code
178: * @return boolean
179: */
180: public static boolean IsTrainable(String code) {
181: return true;
182: }
183:
184: /**
185: * See if we are a Roll on Roll off vehicle
186: * @param code - 3 letter cargo category code
187: * @return boolean
188: **/
189: public static boolean isRORO(String code) {
190: code = code.toUpperCase();
191: char c = code.charAt(0);
192: return c == 'A' || c == 'K' || c == 'L' || c == 'R';
193: }
194:
195: /**
196: * See if we are Ammo
197: * @param code - 3 letter cargo category code
198: * @return boolean
199: **/
200: public static boolean isAmmo(String code) {
201: code = code.toUpperCase();
202: char c = code.charAt(0);
203: return c == 'M' || c == 'N' || c == 'P';
204: }
205: }
|