Source Code Cross Referenced for Count.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 Count.
029:         **/package org.cougaar.planning.ldm.measure;
030:
031:        import java.io.*;
032:
033:        public final class Count extends Scalar implements  Externalizable {
034:            // Conversion factor constants
035:            public static final double UNITS_PER_EACHES = (1.0d / 1.0);
036:            public static final double EACHES_PER_UNITS = 1.0;
037:            public static final double UNITS_PER_DOZEN = 12;
038:            public static final double DOZEN_PER_UNITS = (1.0d / 12);
039:            public static final double UNITS_PER_HUNDRED = 100;
040:            public static final double HUNDRED_PER_UNITS = (1.0d / 100);
041:            public static final double UNITS_PER_GROSS = 144;
042:            public static final double GROSS_PER_UNITS = (1.0d / 144);
043:            public static final double UNITS_PER_MILLION = 1000000;
044:            public static final double MILLION_PER_UNITS = (1.0d / 1000000);
045:
046:            // the value is stored as units
047:            private double theValue;
048:
049:            /** No-arg constructor is only for use by serialization **/
050:            public Count() {
051:            }
052:
053:            // private constructor
054:            private Count(double v) {
055:                theValue = v;
056:            }
057:
058:            /** parameterized constructor **/
059:            public Count(double v, int unit) {
060:                if (unit >= 0 && unit <= MAXUNIT)
061:                    theValue = v * getConvFactor(unit);
062:                else
063:                    throw new UnknownUnitException();
064:            }
065:
066:            /** takes strings of the form "Number unit" **/
067:            public Count(String s) {
068:                int i = indexOfType(s);
069:                if (i < 0)
070:                    throw new UnknownUnitException();
071:                double n = Double.valueOf(s.substring(0, i).trim())
072:                        .doubleValue();
073:                String u = s.substring(i).trim().toLowerCase();
074:                if (u.equals("units"))
075:                    theValue = n;
076:                else if (u.equals("eaches"))
077:                    theValue = n * UNITS_PER_EACHES;
078:                else if (u.equals("dozen"))
079:                    theValue = n * UNITS_PER_DOZEN;
080:                else if (u.equals("hundred"))
081:                    theValue = n * UNITS_PER_HUNDRED;
082:                else if (u.equals("gross"))
083:                    theValue = n * UNITS_PER_GROSS;
084:                else if (u.equals("million"))
085:                    theValue = n * UNITS_PER_MILLION;
086:                else
087:                    throw new UnknownUnitException();
088:            }
089:
090:            // TypeNamed factory methods
091:            public static final Count newUnits(double v) {
092:                return new Count(v);
093:            }
094:
095:            public static final Count newUnits(String s) {
096:                return new Count((Double.valueOf(s).doubleValue()));
097:            }
098:
099:            public static final Count newEaches(double v) {
100:                return new Count(v * UNITS_PER_EACHES);
101:            }
102:
103:            public static final Count newEaches(String s) {
104:                return new Count((Double.valueOf(s).doubleValue())
105:                        * UNITS_PER_EACHES);
106:            }
107:
108:            public static final Count newDozen(double v) {
109:                return new Count(v * UNITS_PER_DOZEN);
110:            }
111:
112:            public static final Count newDozen(String s) {
113:                return new Count((Double.valueOf(s).doubleValue())
114:                        * UNITS_PER_DOZEN);
115:            }
116:
117:            public static final Count newHundred(double v) {
118:                return new Count(v * UNITS_PER_HUNDRED);
119:            }
120:
121:            public static final Count newHundred(String s) {
122:                return new Count((Double.valueOf(s).doubleValue())
123:                        * UNITS_PER_HUNDRED);
124:            }
125:
126:            public static final Count newGross(double v) {
127:                return new Count(v * UNITS_PER_GROSS);
128:            }
129:
130:            public static final Count newGross(String s) {
131:                return new Count((Double.valueOf(s).doubleValue())
132:                        * UNITS_PER_GROSS);
133:            }
134:
135:            public static final Count newMillion(double v) {
136:                return new Count(v * UNITS_PER_MILLION);
137:            }
138:
139:            public static final Count newMillion(String s) {
140:                return new Count((Double.valueOf(s).doubleValue())
141:                        * UNITS_PER_MILLION);
142:            }
143:
144:            public int getCommonUnit() {
145:                return UNITS;
146:            }
147:
148:            public int getMaxUnit() {
149:                return MAXUNIT;
150:            }
151:
152:            // unit names for getUnitName
153:            private static final String unitNames[] = { "units", "eaches",
154:                    "dozen", "hundred", "gross", "million", };
155:
156:            public String getUnitName(int unit) {
157:                return unitNames[unit];
158:            }
159:
160:            // Index Typed factory methods
161:            static final double convFactor[] = { 1.0, UNITS_PER_EACHES,
162:                    UNITS_PER_DOZEN, UNITS_PER_HUNDRED, UNITS_PER_GROSS,
163:                    UNITS_PER_MILLION, };
164:
165:            public static final double getConvFactor(int i) {
166:                return convFactor[i];
167:            }
168:
169:            // indexes into factor array
170:            public static final int UNITS = 0;
171:            public static final int EACHES = 1;
172:            public static final int DOZEN = 2;
173:            public static final int HUNDRED = 3;
174:            public static final int GROSS = 4;
175:            public static final int MILLION = 5;
176:            public static final int MAXUNIT = 5;
177:
178:            // Index Typed factory methods
179:            public static final Count newCount(double v, int unit) {
180:                if (unit >= 0 && unit <= MAXUNIT)
181:                    return new Count(v * getConvFactor(unit));
182:                else
183:                    throw new UnknownUnitException();
184:            }
185:
186:            public static final Count newCount(String s, int unit) {
187:                if (unit >= 0 && unit <= MAXUNIT)
188:                    return new Count((Double.valueOf(s).doubleValue())
189:                            * getConvFactor(unit));
190:                else
191:                    throw new UnknownUnitException();
192:            }
193:
194:            // Support for AbstractMeasure-level constructor
195:            public static final AbstractMeasure newMeasure(String s, int unit) {
196:                return newCount(s, unit);
197:            }
198:
199:            public static final AbstractMeasure newMeasure(double v, int unit) {
200:                return newCount(v, unit);
201:            }
202:
203:            // simple math : addition and subtraction
204:            public final Measure add(Measure toAdd) {
205:                if (!(toAdd instanceof  Count))
206:                    throw new IllegalArgumentException();
207:                return new Count(theValue + toAdd.getNativeValue());
208:            }
209:
210:            public final Measure subtract(Measure toSubtract) {
211:                if (!(toSubtract instanceof  Count))
212:                    throw new IllegalArgumentException();
213:                return new Count(theValue - toSubtract.getNativeValue());
214:            }
215:
216:            public final Measure scale(double scale) {
217:                return new Count(theValue * scale, 0);
218:            }
219:
220:            public final Measure negate() {
221:                return newCount(-1 * theValue, 0);
222:            }
223:
224:            public final Measure floor(int unit) {
225:                return newCount(Math.floor(getValue(unit)), 0);
226:            }
227:
228:            public final Measure valueOf(double value) {
229:                return new Count(value);
230:            }
231:
232:            public final Measure valueOf(double value, int unit) {
233:                return new Count(value, unit);
234:            }
235:
236:            public final double getNativeValue() {
237:                return theValue;
238:            }
239:
240:            public final int getNativeUnit() {
241:                return 0;
242:            }
243:
244:            public final Duration divide(Rate toRate) {
245:                Measure canonicalNumerator = toRate.getCanonicalNumerator();
246:                if (!(toRate.getCanonicalNumerator() instanceof  Count)) {
247:                    throw new IllegalArgumentException(
248:                            "Expecting a Count/Duration");
249:                }
250:                int durationNativeUnit = toRate.getCanonicalDenominator()
251:                        .getNativeUnit(); // seconds
252:                double value = toRate.getValue(canonicalNumerator
253:                        .getNativeUnit(), durationNativeUnit); // ?/seconds
254:                return new Duration(theValue / value, durationNativeUnit); // ?/?/second = seconds
255:            }
256:
257:            // Unit-based Reader methods
258:            public double getUnits() {
259:                return (theValue);
260:            }
261:
262:            public double getEaches() {
263:                return (theValue / UNITS_PER_EACHES);
264:            }
265:
266:            public double getDozen() {
267:                return (theValue / UNITS_PER_DOZEN);
268:            }
269:
270:            public double getHundred() {
271:                return (theValue / UNITS_PER_HUNDRED);
272:            }
273:
274:            public double getGross() {
275:                return (theValue / UNITS_PER_GROSS);
276:            }
277:
278:            public double getMillion() {
279:                return (theValue / UNITS_PER_MILLION);
280:            }
281:
282:            public double getValue(int unit) {
283:                if (unit >= 0 && unit <= MAXUNIT)
284:                    return (theValue / getConvFactor(unit));
285:                else
286:                    throw new UnknownUnitException();
287:            }
288:
289:            public boolean equals(Object o) {
290:                return (o instanceof  Count && theValue == ((Count) o).theValue);
291:            }
292:
293:            public String toString() {
294:                return Double.toString(theValue) + "units";
295:            }
296:
297:            public int hashCode() {
298:                return (new Double(theValue)).hashCode();
299:            }
300:
301:            // serialization
302:            public void writeExternal(ObjectOutput out) throws IOException {
303:                out.writeDouble(theValue);
304:            }
305:
306:            public void readExternal(ObjectInput in) throws IOException {
307:                theValue = in.readDouble();
308:            }
309:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.