Source Code Cross Referenced for NamedLocationImpl.java in  » Science » Cougaar12_4 » org » cougaar » tools » csmart » util » 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.tools.csmart.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2001-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:        package org.cougaar.tools.csmart.util;
028:
029:        /**
030:         * A location (as a <code>LatLonPoint</code>) with a name.
031:         * Multiple constructors are available.
032:         * Utility functions to find the distance from this location to another
033:         *
034:         * @see NewNamedLocation
035:         * @see LatLonPoint
036:         */
037:        public class NamedLocationImpl implements  NewNamedLocation {
038:
039:            private String name = null; // name of this location
040:            private LatLonPoint pos = null; // position of this location
041:
042:            public NamedLocationImpl() {
043:            }
044:
045:            /**
046:             * Creates a new <code>NamedLocationImpl</code> instance.
047:             * This constructor will try to parse the String to find
048:             * a name, lat, and long (float degrees). If it cant, it treats the String
049:             * as a Name.<br>
050:             * The 3 fields are expected to be separated with a vertical bar (|).<br>
051:             * If there are errors parsing the lat & long, the default is 0.0 for each.
052:             *
053:             * @param name a <code>String</code> location name or composite location, lat, long
054:             */
055:            public NamedLocationImpl(String name) {
056:                if (name.indexOf('|') == -1) {
057:                    //System.err.println("setting name to full thing: " + name);
058:                    this .setName(name);
059:                } else {
060:                    this .setName(name.substring(0, name.indexOf('|')));
061:                    //System.err.println("Found composite name, set it to " + this.name);
062:                    name = name.substring(name.indexOf('|') + 1);
063:                    String lat = name.substring(0, name.indexOf('|'));
064:                    String lon = name.substring(name.indexOf('|') + 1);
065:                    //System.err.println("lat will be: " + lat + ", long: " + lon);
066:                    float flat = 0.0f;
067:                    float flon = 0.0f;
068:                    try {
069:                        flat = Float.parseFloat(lat);
070:                        flon = Float.parseFloat(lon);
071:                    } catch (NumberFormatException nfe) {
072:                    }
073:                    this .setPosition(new LatLonPoint(flat, flon));
074:                    //System.err.println("Got position: " + getPosition());
075:                }
076:            }
077:
078:            /**
079:             * Creates a new <code>NamedLocationImpl</code> instance.
080:             *
081:             * @param pos a <code>LatLonPoint</code> position
082:             */
083:            public NamedLocationImpl(LatLonPoint pos) {
084:                this .setPosition(pos);
085:            }
086:
087:            /**
088:             * Creates a new <code>NamedLocationImpl</code> instance.
089:             *
090:             * @param name a <code>String</code> name
091:             * @param pos a <code>LatLonPoint</code> 
092:             */
093:            public NamedLocationImpl(String name, LatLonPoint pos) {
094:                this .setPosition(pos);
095:                this .setName(name);
096:            }
097:
098:            /**
099:             * Creates a new <code>NamedLocationImpl</code> instance.
100:             *
101:             * @param name a <code>String</code> name
102:             * @param lat a <code>float</code> latitude in degrees
103:             * @param lon a <code>float</code> longitude in degrees
104:             */
105:            public NamedLocationImpl(String name, float lat, float lon) {
106:                this .setPosition(new LatLonPoint(lat, lon));
107:                this .setName(name);
108:            }
109:
110:            /**
111:             * Creates a new <code>NamedLocationImpl</code> instance.
112:             *
113:             * @param name a <code>String</code> location name
114:             * @param lat a <code>float</code> latitude in radians
115:             * @param lon a <code>float</code> longitdue in radians
116:             * @param isRadian a <code>boolean</code> that should be true and is always ignored
117:             */
118:            public NamedLocationImpl(String name, float lat, float lon,
119:                    boolean isRadian) {
120:                this .setPosition(new LatLonPoint(lat, lon, true));
121:                this .setName(name);
122:            }
123:
124:            /**
125:             * Creates a new <code>NamedLocationImpl</code> instance.
126:             *
127:             * @param pt a <code>NamedLocation</code> to copy
128:             */
129:            public NamedLocationImpl(NamedLocation pt) {
130:                this .setPosition(pt.getPosition());
131:                this .setName(pt.getName());
132:            }
133:
134:            /**
135:             * Creates a new <code>NamedLocationImpl</code> instance.
136:             *
137:             * @param name a <code>String</code> name
138:             * @param lat a <code>double</code> latitude in degrees
139:             * @param lon a <code>double</code> longitude in degrees
140:             */
141:            public NamedLocationImpl(String name, double lat, double lon) {
142:                this .setPosition(new LatLonPoint(lat, lon));
143:                this .setName(name);
144:            }
145:
146:            /**
147:             * Get the name of this location, possibly null
148:             *
149:             * @return a <code>String</code> location name, possibly null
150:             */
151:            public String getName() {
152:                return name;
153:            }
154:
155:            /**
156:             * Set the name of this location, overriding any previous name
157:             *
158:             * @param name a <code>String</code> location name
159:             */
160:            public void setName(String name) {
161:                this .name = name;
162:            }
163:
164:            /**
165:             * Get the position of this location
166:             *
167:             * @return a <code>LatLonPoint</code> 
168:             */
169:            public LatLonPoint getPosition() {
170:                return pos;
171:            }
172:
173:            /**
174:             * Set the position of this location
175:             *
176:             * @param pos a <code>LatLonPoint</code>
177:             */
178:            public void setPosition(LatLonPoint pos) {
179:                this .pos = pos;
180:            }
181:
182:            /**
183:             * Get the distance in kilometers from this point to the given point
184:             *
185:             * @param other a <code>LatLonPoint</code> to find the distance to
186:             * @return a <code>double</code> distance in kilometers
187:             */
188:            public double distanceFrom(LatLonPoint other) {
189:                return EarthConstants.DistanceBetweenLatLonPoints(this 
190:                        .getPosition(), other);
191:            }
192:
193:            /**
194:             * Get the distance in kilometers from this point to the given point
195:             *
196:             * @param other a <code>NamedLocation</code> value
197:             * @return a <code>double</code> distance in kilometers
198:             */
199:            public double distanceFrom(NamedLocation other) {
200:                return EarthConstants.DistanceBetweenLatLonPoints(this 
201:                        .getPosition(), other.getPosition());
202:            }
203:
204:            /**
205:             * Get the distance in kilometers from this point to the given point
206:             *
207:             * @param lat a <code>double</code> latitude in degrees
208:             * @param lon a <code>double</code> longitude in degrees
209:             * @return a <code>float</code> distance in kilometers
210:             */
211:            public float distanceFrom(double lat, double lon) {
212:                return EarthConstants.DistanceBetweenPoints(this .getPosition()
213:                        .getLatitude(), this .getPosition().getLongitude(),
214:                        (float) lat, (float) lon);
215:            }
216:
217:            /**
218:             * Get the distance in kilometers from this point to the given point
219:             *
220:             * @param lat a <code>float</code> latitude in degrees
221:             * @param lon a <code>float</code> longitude in degrees
222:             * @return a <code>float</code> distance in kilometers
223:             */
224:            public float distanceFrom(float lat, float lon) {
225:                return EarthConstants.DistanceBetweenPoints(this .getPosition()
226:                        .getLatitude(), this .getPosition().getLongitude(), lat,
227:                        lon);
228:            }
229:
230:            /**
231:             * 2 <code>NamedLocationImpl</code>s are <code>equals</code> if they have the same name
232:             * The position is ignored for this purpose.
233:             *
234:             * @param obj an <code>Object</code> to compare
235:             * @return a <code>boolean</code>
236:             */
237:            public boolean equals(Object obj) {
238:                if (obj instanceof  NamedLocation) {
239:                    return getName().equals(((NamedLocation) obj).getName());
240:                }
241:                return false;
242:            }
243:
244:            public String toString() {
245:                return "NamedLocationImpl[name=" + name + ", pos=" + pos + "]";
246:            }
247:        } // NamedLocationImpl.java
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.