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