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.lib.util;
028:
029: /**
030: * Static class to extract some information out
031: * of the cargo category codes.
032: * Cargo category codes are 3 letter codes that define
033: * how a piece of cargo can be transported from point A
034: * to point B.
035: */
036: public final class UTILCargoCategoryDecoder {
037:
038: /**
039: * See if the cargo is air transportable.
040: * @param code - 3 letter cargo category code
041: * @return boolean
042: */
043: public boolean AirTransportable(String code) {
044: code = code.toUpperCase();
045: char c = code.charAt(1);
046: return ((c != '0') && (c != '4') && (c != 'A'));
047: }
048:
049: /**
050: * See if cargo is outsized.
051: * @param code - 3 letter cargo category code
052: * @return boolean
053: */
054:
055: public boolean isOutsized(String code) {
056: code = code.toUpperCase();
057: char c = code.charAt(1);
058: return ((c == '1') || (c == '5') || (c == 'B'));
059: }
060:
061: /**
062: * See if cargo is oversized.
063: * @param code - 3 letter cargo category code
064: * @return boolean
065: */
066:
067: public boolean isOversized(String code) {
068: code = code.toUpperCase();
069: char c = code.charAt(1);
070: return ((c == '2') || (c == '6') || (c == 'C'));
071: }
072:
073: /**
074: * See if the cargo fits on a C5 or a C17 Plane.
075: * There is a limit to outsize a C17 can carry. This info
076: * can not be deduced from the cargo category code and must
077: * be found using the length and width info. in ContainCapability.java.
078: * @param code - 3 letter cargo category code
079: * @return boolean
080: */
081:
082: public boolean FitsOnC5orC17(String code) {
083: code = code.toUpperCase();
084: char c = code.charAt(1);
085: // only bulk organic and oversized
086: // and outsized equipment
087: return (FitsOnAnyPlane(code) || FitsOnC17orC141(code)
088: || c == '1' || c == '5' || c == 'B');
089: }
090:
091: /**
092: * See if the cargo fits on a C17 or C141 plane
093: * @param code - 3 letter cargo category code
094: * @return boolean
095: */
096: public boolean FitsOnC17orC141(String code) {
097: code = code.toUpperCase();
098: char c = code.charAt(1);
099: // only bulk organic and oversized equipment
100: return (FitsOnAnyPlane(code) || c == '2' || c == '6' || c == 'C');
101: }
102:
103: /**
104: * See if the cargo fits on any kind of US Military
105: * cargo plane.
106: * @param code - 3 letter cargo category code
107: * @return boolean
108: */
109: public boolean FitsOnAnyPlane(String code) {
110: code = code.toUpperCase();
111: char c = code.charAt(1);
112: // bulk or organic cargo
113: return (c == '3' || c == '7' || c == 'D' || c == '8' || c == '9');
114: }
115:
116: /**
117: * See if the cargo can go by ship. For
118: * the 1998 demo we will assume that anything
119: * can go by ship.
120: * @param code - 3 letter cargo category code
121: * @return boolean
122: */
123: public boolean FitsOnShip(String code) {
124: return true;
125: }
126:
127: /**
128: * Can be transported down american roads, if not then
129: * it must go by train.
130: * @param code - 3 letter cargo category code
131: * @return boolean
132: */
133: public boolean IsRoadable(String code) {
134: code = code.toUpperCase();
135: char c = code.charAt(0);
136: return (c != 'A');
137: }
138:
139: /**
140: * Roadable vehicles, may be hazardouz, may require security
141: * @param code - 3 letter cargo category code
142: * @return boolean
143: */
144: public boolean IsSelfTransportable(String code) {
145: code = code.toUpperCase();
146: char c = code.charAt(0);
147: return (c == 'K' || c == 'L' || c == 'R');
148: }
149:
150: /**
151: * Cargo can be put in a 20 ft container
152: * @param code - 3 letter cargo category code
153: * @return boolean
154: */
155: public boolean Is20FtContainarizable(String code) {
156: code = code.toUpperCase();
157: char c = code.charAt(2);
158: return (c == 'B');
159: }
160:
161: /**
162: * Cargo can be put in a 20 ft container
163: * @param code - 3 letter cargo category code
164: * @return boolean
165: */
166: public boolean Is40FtContainarizable(String code) {
167: code = code.toUpperCase();
168: char c = code.charAt(2);
169: return (c == 'C');
170: }
171:
172: /**
173: * See if some cargo can be transported by train
174: * For the 1998 demo we assume that all vehicles are
175: * trainable.
176: * @param code - 3 letter cargo category code
177: * @return boolean
178: */
179: public boolean IsTrainable(String code) {
180: return true;
181: }
182:
183: /**
184: * See if we are a Roll on Roll off vehicle
185: * @param code - 3 letter cargo category code
186: * @return boolean
187: **/
188: public boolean isRORO(String code) {
189: code = code.toUpperCase();
190: char c = code.charAt(0);
191: return c == 'A' || c == 'K' || c == 'L' || c == 'R';
192: }
193:
194: /**
195: * See if we are Ammo
196: * @param code - 3 letter cargo category code
197: * @return boolean
198: **/
199: public boolean isAmmo(String code) {
200: code = code.toUpperCase();
201: char c = code.charAt(0);
202: return c == 'M' || c == 'N' || c == 'P';
203: }
204: }
|