Source Code Cross Referenced for Latitude.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:        /** Immutable implementation of Latitude.
027:         **/package org.cougaar.planning.ldm.measure;
028:
029:        public final class Latitude extends AbstractMeasure {
030:            private static final double upperBound = 90.0;
031:            private static final double lowerBound = -90.0;
032:
033:            //no real conversions for now
034:            private static final Conversion DEGREES_TO_DEGREES = new Conversion() {
035:                public double convert(double from) {
036:                    return from;
037:                }
038:            };
039:
040:            // basic unit is Degrees
041:            private double theValue;
042:
043:            // private constructor
044:            private Latitude(double v) throws ValueRangeException {
045:                if (inBounds(v)) {
046:                    theValue = v;
047:                } else {
048:                    throw new ValueRangeException(
049:                            "Latitude expects the double to be between -90.0 and +90.0.");
050:                }
051:
052:            }
053:
054:            public Latitude(String s) {
055:                int i = indexOfType(s);
056:                if (i < 0)
057:                    throw new UnknownUnitException();
058:                double n = Double.valueOf(s.substring(0, i).trim())
059:                        .doubleValue();
060:                String u = s.substring(i).trim().toLowerCase();
061:                if (u.equals("degrees"))
062:                    theValue = n;
063:                else
064:                    throw new UnknownUnitException();
065:            }
066:
067:            public int getCommonUnit() {
068:                return 0;
069:            }
070:
071:            public int getMaxUnit() {
072:                return 0;
073:            }
074:
075:            public String getUnitName(int i) {
076:                if (i == 0)
077:                    return "degrees";
078:                else
079:                    throw new IllegalArgumentException();
080:            }
081:
082:            // TypeNamed factory methods
083:            public static Latitude newLatitude(double v) {
084:                return new Latitude(v);
085:            }
086:
087:            public static Latitude newLatitude(String s) {
088:                return new Latitude((Double.valueOf(s).doubleValue()));
089:            }
090:
091:            // Index Typed factory methods
092:            // ***No real conversions for now
093:            private static final Conversion convFactor[] = {
094:            //conversions to base units
095:                    DEGREES_TO_DEGREES,
096:                    //RADIANS_TO_DEGREES,
097:                    // conversions from base units
098:                    DEGREES_TO_DEGREES
099:            //DEGREES_TO_RADIANS
100:            };
101:            // indexes into factor array
102:            public static int DEGREES = 0;
103:            //public static int RADIANS = 1;
104:            private static int MAXUNIT = 0;
105:
106:            // TypeNamed factory methods
107:            public static Latitude newDegrees(double v) {
108:                return new Latitude(v);
109:            }
110:
111:            public static Latitude newDegrees(String s) {
112:                return new Latitude((Double.valueOf(s).doubleValue()));
113:            }
114:
115:            // Index Typed factory methods
116:            public static Latitude newLatitude(double v, int unit) {
117:                if (unit >= 0 && unit <= MAXUNIT)
118:                    return new Latitude(convFactor[unit].convert(v));
119:                else
120:                    throw new UnknownUnitException();
121:            }
122:
123:            public static Latitude newLatitude(String s, int unit) {
124:                if (unit >= 0 && unit <= MAXUNIT)
125:                    return new Latitude(convFactor[unit].convert(Double
126:                            .valueOf(s).doubleValue()));
127:                else
128:                    throw new UnknownUnitException();
129:            }
130:
131:            // Support for AbstractMeasure-level constructor
132:            public static AbstractMeasure newMeasure(String s, int unit) {
133:                return newLatitude(s, unit);
134:            }
135:
136:            public static AbstractMeasure newMeasure(double v, int unit) {
137:                return newLatitude(v, unit);
138:            }
139:
140:            // Unit-based Reader methods
141:            public double getDegrees() {
142:                return (theValue);
143:            }
144:
145:            //public double getRADIANS() {
146:            //return (DEGREES_TO_RADIANS.convert(theValue));
147:            //}
148:
149:            public double getValue(int unit) {
150:                if (unit >= 0 && unit <= MAXUNIT)
151:                    return convFactor[MAXUNIT + 1 + unit].convert(theValue);
152:                else
153:                    throw new UnknownUnitException();
154:            }
155:
156:            public static Conversion getConversion(final int from, final int to) {
157:                if (from >= 0 && from <= MAXUNIT && to >= 0 && to <= MAXUNIT) {
158:                    return new Conversion() {
159:                        public double convert(double value) {
160:                            return convFactor[MAXUNIT + 1 + to]
161:                                    .convert(convFactor[from].convert(value));
162:                        }
163:                    };
164:                } else
165:                    throw new UnknownUnitException();
166:            }
167:
168:            public boolean equals(Object o) {
169:                return (o instanceof  Latitude && theValue == ((Latitude) o)
170:                        .getDegrees());
171:            }
172:
173:            public String toString() {
174:                return Double.toString(theValue) + "o";
175:            }
176:
177:            public int hashCode() {
178:                return (new Double(theValue)).hashCode();
179:            }
180:
181:            private boolean inBounds(double v) {
182:                boolean ok;
183:                if ((v <= upperBound) && (v >= lowerBound)) {
184:                    ok = true;
185:                } else {
186:                    ok = false;
187:                }
188:                return ok;
189:            }
190:
191:            /**
192:             * TODO : fill in
193:             * @param other
194:             * @return
195:             */
196:            public Measure add(Measure other) {
197:                return null;
198:            }
199:
200:            /**
201:             * TODO : fill in
202:             * @param other
203:             * @return
204:             */
205:            public Measure subtract(Measure other) {
206:                return null;
207:            }
208:
209:            public Measure negate() {
210:                return null;
211:            }
212:
213:            public Measure scale(double scale) {
214:                return null;
215:            }
216:
217:            public Measure floor(int unit) {
218:                return null;
219:            }
220:
221:            public Measure valueOf(double value) {
222:                return null;
223:            }
224:
225:            public Measure valueOf(double value, int unit) {
226:                return null;
227:            }
228:
229:            public int getNativeUnit() {
230:                return 0;
231:            }
232:
233:            public double getNativeValue() {
234:                return getValue(getNativeUnit());
235:            }
236:
237:            public Duration divide(Rate rate) {
238:                return null;
239:            }
240:        } // end Latitude
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.