/[projects]/android/TrainInfoServiceGoogle/src/dk/thoerup/traininfoservice/geo/Length.java
ViewVC logotype

Annotation of /android/TrainInfoServiceGoogle/src/dk/thoerup/traininfoservice/geo/Length.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1105 - (hide annotations) (download)
Wed Sep 22 21:09:39 2010 UTC (13 years, 8 months ago) by torben
File size: 4821 byte(s)
Got DAO working, now i'm just missing the last bit of loading station identifiers from app.t-hoerup.dk
1 torben 1105 // **********************************************************************
2     //
3     // <copyright>
4     //
5     // BBN Technologies
6     // 10 Moulton Street
7     // Cambridge, MA 02138
8     // (617) 873-8000
9     //
10     // Copyright (C) BBNT Solutions LLC. All rights reserved.
11     //
12     // </copyright>
13     // **********************************************************************
14     //
15     // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/proj/Length.java,v $
16     // $RCSfile: Length.java,v $
17     // $Revision: 1.5.2.2 $
18     // $Date: 2005/08/10 22:45:12 $
19     // $Author: dietrick $
20     //
21     // **********************************************************************
22    
23     package dk.thoerup.traininfoservice.geo;
24    
25     /*
26     * Length is a convenience class used for a couple of things. It can
27     * be used to specifiy unit type, and can be used for conversion from
28     * radians to/from whatever units are represented by the implemented
29     * class.
30     */
31     public class Length {
32    
33     /** Miles, in WGS 84 spherical earth model units. */
34     public final static Length MILE = new Length("mile", "miles", Planet.wgs84_earthEquatorialCircumferenceMiles_D);
35     /** Feet, in WGS 84 spherical earth model units. */
36     public final static Length FEET = new Length("feet", "feet", Planet.wgs84_earthEquatorialCircumferenceMiles_D * 5280.0);
37     /** Meters, in WGS 84 Spherical earth model units. */
38     public final static Length METER = new Length("meter", "m", Planet.wgs84_earthEquatorialCircumferenceMeters_D);
39     /** Kilometers, in WGS 84 Spherical earth model units. */
40     public final static Length KM = new Length("kilometer", "km", Planet.wgs84_earthEquatorialCircumferenceKM_D);
41     /** Nautical Miles, in WGS 84 Spherical earth model units. */
42     public final static Length NM = new Length("nautical mile", "nm", Planet.wgs84_earthEquatorialCircumferenceNMiles_D);
43     /** Decimal Degrees, in WGS 84 Spherical earth model units. */
44     public final static Length DECIMAL_DEGREE = new Length("decimal degree", "deg", 360.0);
45     /** Radians, in terms of a spherical earth. */
46     public final static Length RADIAN = new Length("radian", "rad", MoreMath.TWO_PI_D);
47     /** Data Mile, in WGS 84 spherical earth model units. */
48     public final static Length DM = new Length("datamile", "dm", Planet.wgs84_earthEquatorialCircumferenceMiles_D * 5280.0 / 6000.0);
49    
50     /** Unit/radians */
51     protected final double constant;
52     protected final String name;
53     protected final String abbr;
54     protected double unitEquatorCircumference;
55    
56    
57     /**
58     * Create a Length, with a name an the number of it's units that
59     * go around the earth at its equator. The name and abbreviation
60     * are converted to lower case for consistency.
61     */
62     public Length(String name, String abbr, double unitEquatorCircumference) {
63     this.name = name;
64     this.unitEquatorCircumference = unitEquatorCircumference;
65     this.constant = unitEquatorCircumference / MoreMath.TWO_PI_D;
66     this.abbr = abbr.toLowerCase().intern();
67     }
68    
69     /**
70     * Given a number of units provided by this Length, convert to a
71     * number of radians.
72     */
73     public float toRadians(float numUnits) {
74    
75     return numUnits / (float) constant;
76     }
77    
78     public double toRadians(double numUnits) {
79    
80    
81     return numUnits / constant;
82     }
83    
84     /**
85     * Given a number of radians, convert to the number of units
86     * represented by this length.
87     */
88     public float fromRadians(float numRadians) {
89    
90    
91     return numRadians * (float) constant;
92     }
93    
94     /**
95     * Given a number of radians, convert to the number of units
96     * represented by this length.
97     */
98     public double fromRadians(double numRadians) {
99    
100    
101     return numRadians * constant;
102     }
103    
104     /**
105     * Return the name for this length type.
106     */
107     public String toString() {
108     return name;
109     }
110    
111     /**
112     * Return the abbreviation for this length type.
113     */
114     public String getAbbr() {
115     return abbr;
116     }
117    
118     /**
119     * Get a list of the Lengths currently defined as static
120     * implementations of this class.
121     */
122     public static Length[] getAvailable() {
123     return new Length[] { METER, KM, FEET, MILE, DM, NM, DECIMAL_DEGREE };
124     }
125    
126     /**
127     * Get the Length object with the given name or abbreviation. If
128     * nothing exists with that name, then return null. The lower case
129     * version of the name or abbreviation is checked against the
130     * available options.
131     */
132     public static Length get(String name) {
133     Length[] choices = getAvailable();
134    
135     for (int i = 0; i < choices.length; i++) {
136     if (name.toLowerCase().intern() == choices[i].toString()
137     || name.toLowerCase().intern() == choices[i].getAbbr()) {
138     return choices[i];
139     }
140     }
141     return null;
142     }
143     }

  ViewVC Help
Powered by ViewVC 1.1.20