Source Code Cross Referenced for Capacity.java in  » Science » Cougaar12_4 » org » cougaar » planning » ldm » measure » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.planning.ldm.measure 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.planning.ldm.measure;
027:
028:        import java.lang.reflect.Constructor;
029:
030:        /** A generic Scalar per Duration class that can be interpreted in a 
031:         * variety of ways depending on context.
032:         **/
033:
034:        public class Capacity extends AbstractMeasure {
035:            private Scalar quantity;
036:            private Duration period;
037:
038:            /** Construct a capacity object which represents
039:             * a Scalar Measure (e.g. Volume, Distance, etc) divided by a
040:             * Duration (time).  Example: Miles per hour, hours per day, gallons per second.
041:             * May also be used
042:             **/
043:            public Capacity(Scalar quantity, Duration period) {
044:                this .quantity = quantity;
045:                this .period = period;
046:            }
047:
048:            /** String constructor.  Allowed syntax is:
049:             * "Scalarmeasure=ValueUnits Duration=ValueUnits"
050:             * Example: "Count=20units Duration=1weeks"
051:             * For instantaneous: "Count=20units"
052:             **/
053:            public Capacity(String s) {
054:                int i = s.indexOf(' ');
055:                String qs;
056:                String ps;
057:                if (i == -1) {
058:                    qs = s;
059:                    ps = null;
060:                } else {
061:                    qs = s.substring(0, i);
062:                    ps = s.substring(i + 1);
063:                }
064:
065:                try {
066:                    Class[] sa = new Class[1];
067:                    sa[0] = String.class;
068:
069:                    int qse = qs.indexOf('=');
070:                    String qsn = qs.substring(0, qse);
071:                    Class qsc = Class
072:                            .forName("org.cougaar.planning.ldm.measure." + qsn);
073:                    Constructor qscc = qsc.getConstructor(sa);
074:                    Object[] qargs = new Object[1];
075:                    qargs[0] = qs.substring(qse + 1);
076:                    quantity = (Scalar) qscc.newInstance(qargs);
077:
078:                    if (ps != null) {
079:                        int pse = ps.indexOf('=');
080:                        String psn = ps.substring(0, pse);
081:                        Class psc = Class
082:                                .forName("org.cougaar.planning.ldm.measure."
083:                                        + psn);
084:                        Constructor pscc = psc.getConstructor(sa);
085:                        Object[] pargs = new Object[1];
086:                        pargs[0] = ps.substring(pse + 1);
087:                        period = (Duration) pscc.newInstance(pargs);
088:                    } else {
089:                        period = null;
090:                    }
091:                } catch (Exception e) {
092:                    e.printStackTrace();
093:                    throw new RuntimeException("Exception: " + e);
094:                }
095:            }
096:
097:            /** @return an illegal value, since Capacity is a tuple **/
098:            public int getCommonUnit() {
099:                return -1;
100:            }
101:
102:            public int getMaxUnit() {
103:                return -1;
104:            }
105:
106:            /** @return null, since Capacity is a tuple **/
107:            public String getUnitName(int i) {
108:                return null;
109:            }
110:
111:            public double getValue(int unit) {
112:                throw new IllegalArgumentException();
113:            }
114:
115:            /** Construct an "instantaneous" capacity object - e.g. 
116:             * the capactity of "holding 10000 Gallons" or "having 48 Het-equivalents".
117:             **/
118:            public Capacity(Scalar quantity) {
119:                this .quantity = quantity;
120:                this .period = null;
121:            }
122:
123:            /** @return the numerator of the Capacity **/
124:            public Scalar getQuantity() {
125:                return quantity;
126:            }
127:
128:            /** @return the denominator of the Capacty **/
129:            public Duration getPeriod() {
130:                return period;
131:            }
132:
133:            /** is this a representation of instantaneous capacity? **/
134:            public boolean isInstantaneous() {
135:                return period == null;
136:            }
137:
138:            /** compute the figure that the capacity represents. E.g.
139:             * Capacity cap = new Capacity(new Volume("10 liters"), new Duration("1 seconds"));
140:             * double rate = cap.getCapacity(Volume.GALLONS, Duration.HOURS);
141:             *
142:             * Note that to get the quantityUnits correct, you need to know
143:             * what the concrete type of the quantity is.
144:             *
145:             * @exception UnknownUnitException if a bad unit in either argument.
146:             * @exceptionx DivideByZero if duration is 0.
147:             * @exception NullPointerException if duration is null.
148:             **/
149:            public double getRate(int quantityUnits, int periodUnits) {
150:                if (isInstantaneous())
151:                    throw new IllegalArgumentException(
152:                            "Cannot compute rate of an instantaneous Capacity");
153:                return quantity.getValue(quantityUnits)
154:                        / period.getValue(periodUnits);
155:            }
156:
157:            /**
158:             * TODO : fill in
159:             * @param other
160:             * @return
161:             */
162:            public Measure add(Measure other) {
163:                return null;
164:            }
165:
166:            /**
167:             * TODO : fill in
168:             * @param other
169:             * @return
170:             */
171:            public Measure subtract(Measure other) {
172:                return null;
173:            }
174:
175:            /**
176:             * TODO : fill in
177:             * @param other
178:             * @return
179:             */
180:            public Measure multiply(Measure other) {
181:                return null;
182:            }
183:
184:            /**
185:             * TODO : fill in
186:             * @param other
187:             * @return
188:             */
189:            public Duration divide(Rate other) {
190:                return null;
191:            }
192:
193:            public Measure negate() {
194:                return null;
195:            }
196:
197:            public Measure scale(double scale) {
198:                return null;
199:            }
200:
201:            public Measure floor(int unit) {
202:                return null;
203:            }
204:
205:            public Measure valueOf(double value) {
206:                return null;
207:            }
208:
209:            public Measure valueOf(double value, int unit) {
210:                return null;
211:            }
212:
213:            public int getNativeUnit() {
214:                return 0;
215:            }
216:
217:            public double getNativeValue() {
218:                return getValue(getNativeUnit());
219:            }
220:
221:            public String toString() {
222:                if (isInstantaneous()) {
223:                    return "Capacity of " + quantity;
224:                } else {
225:                    return quantity + " per " + period;
226:                }
227:            }
228:
229:            public boolean equals(Object o) {
230:                if (o instanceof  Capacity) {
231:                    Capacity oc = (Capacity) o;
232:                    Duration ocp = oc.getPeriod();
233:                    if ((period == null) != (ocp == null))
234:                        return false;
235:                    if (period == null)
236:                        return quantity.equals(oc.getQuantity());
237:                    else
238:                        return (getRate(0, 0) == oc.getRate(0, 0));
239:                } else
240:                    return false;
241:            }
242:
243:            public int hashCode() {
244:                int qh = quantity.hashCode();
245:                if (period != null)
246:                    qh = (qh << 2) + period.hashCode();
247:                return qh;
248:            }
249:
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.