Source Code Cross Referenced for Power.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:
027:        /* @generated Thu Sep 27 15:20:43 EDT 2007 from /u01/builds/cougaar/B12_4/B12_4/070927151721/src/planning/src/org/cougaar/planning/ldm/measure/measures.def - DO NOT HAND EDIT */
028:        /** Immutable implementation of Power.
029:         **/package org.cougaar.planning.ldm.measure;
030:
031:        import java.io.*;
032:
033:        public final class Power extends AbstractMeasure implements 
034:                Externalizable {
035:            // Conversion factor constants
036:            public static final double WATTS_PER_KILOWATTS = (1.0d / 0.001);
037:            public static final double KILOWATTS_PER_WATTS = 0.001;
038:            public static final double WATTS_PER_HORSEPOWER = (1.0d / 0.0013410221);
039:            public static final double HORSEPOWER_PER_WATTS = 0.0013410221;
040:
041:            // the value is stored as watts
042:            private double theValue;
043:
044:            /** No-arg constructor is only for use by serialization **/
045:            public Power() {
046:            }
047:
048:            // private constructor
049:            private Power(double v) {
050:                theValue = v;
051:            }
052:
053:            /** parameterized constructor **/
054:            public Power(double v, int unit) {
055:                if (unit >= 0 && unit <= MAXUNIT)
056:                    theValue = v * getConvFactor(unit);
057:                else
058:                    throw new UnknownUnitException();
059:            }
060:
061:            /** takes strings of the form "Number unit" **/
062:            public Power(String s) {
063:                int i = indexOfType(s);
064:                if (i < 0)
065:                    throw new UnknownUnitException();
066:                double n = Double.valueOf(s.substring(0, i).trim())
067:                        .doubleValue();
068:                String u = s.substring(i).trim().toLowerCase();
069:                if (u.equals("watts"))
070:                    theValue = n;
071:                else if (u.equals("kilowatts"))
072:                    theValue = n * WATTS_PER_KILOWATTS;
073:                else if (u.equals("horsepower"))
074:                    theValue = n * WATTS_PER_HORSEPOWER;
075:                else
076:                    throw new UnknownUnitException();
077:            }
078:
079:            // TypeNamed factory methods
080:            public static final Power newWatts(double v) {
081:                return new Power(v);
082:            }
083:
084:            public static final Power newWatts(String s) {
085:                return new Power((Double.valueOf(s).doubleValue()));
086:            }
087:
088:            public static final Power newKilowatts(double v) {
089:                return new Power(v * WATTS_PER_KILOWATTS);
090:            }
091:
092:            public static final Power newKilowatts(String s) {
093:                return new Power((Double.valueOf(s).doubleValue())
094:                        * WATTS_PER_KILOWATTS);
095:            }
096:
097:            public static final Power newHorsepower(double v) {
098:                return new Power(v * WATTS_PER_HORSEPOWER);
099:            }
100:
101:            public static final Power newHorsepower(String s) {
102:                return new Power((Double.valueOf(s).doubleValue())
103:                        * WATTS_PER_HORSEPOWER);
104:            }
105:
106:            public int getCommonUnit() {
107:                return KILOWATTS;
108:            }
109:
110:            public int getMaxUnit() {
111:                return MAXUNIT;
112:            }
113:
114:            // unit names for getUnitName
115:            private static final String unitNames[] = { "watts", "kilowatts",
116:                    "horsepower", };
117:
118:            public String getUnitName(int unit) {
119:                return unitNames[unit];
120:            }
121:
122:            // Index Typed factory methods
123:            static final double convFactor[] = { 1.0, WATTS_PER_KILOWATTS,
124:                    WATTS_PER_HORSEPOWER, };
125:
126:            public static final double getConvFactor(int i) {
127:                return convFactor[i];
128:            }
129:
130:            // indexes into factor array
131:            public static final int WATTS = 0;
132:            public static final int KILOWATTS = 1;
133:            public static final int HORSEPOWER = 2;
134:            public static final int MAXUNIT = 2;
135:
136:            // Index Typed factory methods
137:            public static final Power newPower(double v, int unit) {
138:                if (unit >= 0 && unit <= MAXUNIT)
139:                    return new Power(v * getConvFactor(unit));
140:                else
141:                    throw new UnknownUnitException();
142:            }
143:
144:            public static final Power newPower(String s, int unit) {
145:                if (unit >= 0 && unit <= MAXUNIT)
146:                    return new Power((Double.valueOf(s).doubleValue())
147:                            * getConvFactor(unit));
148:                else
149:                    throw new UnknownUnitException();
150:            }
151:
152:            // Support for AbstractMeasure-level constructor
153:            public static final AbstractMeasure newMeasure(String s, int unit) {
154:                return newPower(s, unit);
155:            }
156:
157:            public static final AbstractMeasure newMeasure(double v, int unit) {
158:                return newPower(v, unit);
159:            }
160:
161:            // simple math : addition and subtraction
162:            public final Measure add(Measure toAdd) {
163:                if (!(toAdd instanceof  Power))
164:                    throw new IllegalArgumentException();
165:                return new Power(theValue + toAdd.getNativeValue());
166:            }
167:
168:            public final Measure subtract(Measure toSubtract) {
169:                if (!(toSubtract instanceof  Power))
170:                    throw new IllegalArgumentException();
171:                return new Power(theValue - toSubtract.getNativeValue());
172:            }
173:
174:            public final Measure scale(double scale) {
175:                return new Power(theValue * scale, 0);
176:            }
177:
178:            public final Measure negate() {
179:                return newPower(-1 * theValue, 0);
180:            }
181:
182:            public final Measure floor(int unit) {
183:                return newPower(Math.floor(getValue(unit)), 0);
184:            }
185:
186:            public final Measure valueOf(double value) {
187:                return new Power(value);
188:            }
189:
190:            public final Measure valueOf(double value, int unit) {
191:                return new Power(value, unit);
192:            }
193:
194:            public final double getNativeValue() {
195:                return theValue;
196:            }
197:
198:            public final int getNativeUnit() {
199:                return 0;
200:            }
201:
202:            public final Duration divide(Rate toRate) {
203:                Measure canonicalNumerator = toRate.getCanonicalNumerator();
204:                if (!(toRate.getCanonicalNumerator() instanceof  Power)) {
205:                    throw new IllegalArgumentException(
206:                            "Expecting a Power/Duration");
207:                }
208:                int durationNativeUnit = toRate.getCanonicalDenominator()
209:                        .getNativeUnit(); // seconds
210:                double value = toRate.getValue(canonicalNumerator
211:                        .getNativeUnit(), durationNativeUnit); // ?/seconds
212:                return new Duration(theValue / value, durationNativeUnit); // ?/?/second = seconds
213:            }
214:
215:            // Unit-based Reader methods
216:            public double getWatts() {
217:                return (theValue);
218:            }
219:
220:            public double getKilowatts() {
221:                return (theValue / WATTS_PER_KILOWATTS);
222:            }
223:
224:            public double getHorsepower() {
225:                return (theValue / WATTS_PER_HORSEPOWER);
226:            }
227:
228:            public double getValue(int unit) {
229:                if (unit >= 0 && unit <= MAXUNIT)
230:                    return (theValue / getConvFactor(unit));
231:                else
232:                    throw new UnknownUnitException();
233:            }
234:
235:            public boolean equals(Object o) {
236:                return (o instanceof  Power && theValue == ((Power) o).theValue);
237:            }
238:
239:            public String toString() {
240:                return Double.toString(theValue) + "w";
241:            }
242:
243:            public int hashCode() {
244:                return (new Double(theValue)).hashCode();
245:            }
246:
247:            // serialization
248:            public void writeExternal(ObjectOutput out) throws IOException {
249:                out.writeDouble(theValue);
250:            }
251:
252:            public void readExternal(ObjectInput in) throws IOException {
253:                theValue = in.readDouble();
254:            }
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.