1 /*
2 * TelescopeModel.java
3 *
4 * Copyright (c) 2003, Raben Systems, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * Neither the name of Raben Systems, Inc. nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35 package com.raben.telescope.comm;
36 import java.io.Serializable;
37 import java.io.ObjectStreamException;
38 import java.util.List;
39 import java.util.Arrays;
40 import java.util.ResourceBundle;
41 import java.util.Collections;
42
43 /***
44 * Ordinal-based typesafe enum of Telescope Models
45 * @author Vern Raben
46 * @version $Revision: 1.5 $ $Date: 2003/09/11 15:15:13 $
47 */
48 public class TelescopeModel implements Comparable, Serializable {
49 /*** Reference to resource bundle */
50 private static final ResourceBundle RB = ResourceBundle.getBundle(
51 "resources/comm/Telescope");
52
53 /*** Define generic Celestron telescope, software will try to identify model */
54 public static final TelescopeModel CELESTRON =
55 new TelescopeModel(RB.getString("CELESTRON"));
56
57 /*** Define Celestron Advanced Serices */
58 public static final TelescopeModel CELESTRON_ASC =
59 new TelescopeModel(RB.getString("CELESTRON_ASC"));
60
61 /*** Define Celestron CGE */
62 public static final TelescopeModel CELESTRON_CGE =
63 new TelescopeModel(RB.getString("CELESTRON_CGE"));
64
65 /*** Define Nexstar 5i */
66 public static final TelescopeModel CELESTRON_NEXSTAR_5I_8I =
67 new TelescopeModel(RB.getString("CELESTRON_NEXSTAR_5I_8I"));
68
69 /*** Define Nexstar 8 */
70 public static final TelescopeModel CELESTRON_NEXSTAR_5_8 =
71 new TelescopeModel(RB.getString("CELESTRON_NEXSTAR_5_8"));
72
73 /*** Define Nexstar GPS */
74 public static final TelescopeModel CELESTRON_NEXSTAR_GPS =
75 new TelescopeModel(RB.getString("CELESTRON_NEXSTAR_GPS"));
76
77 /*** Define Nexstar GT */
78 public static final TelescopeModel CELESTRON_NEXSTAR_GT =
79 new TelescopeModel(RB.getString("CELESTRON_NEXSTAR_GT"));
80
81 /*** Define original Nexstar GT */
82 public static final TelescopeModel CELESTRON_NEXSTAR_OGT =
83 new TelescopeModel(RB.getString("CELESTRON_NEXSTAR_OGT"));
84
85 /*** Define generic Meade telescope, software will try to identify model */
86 public static final TelescopeModel MEADE =
87 new TelescopeModel(RB.getString("MEADE"));
88
89 /*** Define Meade Autostar */
90 public static final TelescopeModel MEADE_AUTOSTAR =
91 new TelescopeModel(RB.getString("MEADE_AUTOSTAR"));
92
93 /*** Define Meade LX-200 < 16" */
94 public static final TelescopeModel MEADE_LX200 =
95 new TelescopeModel(RB.getString("MEADE_LX200"));
96
97 /*** Define Mead LX200 16" */
98 public static final TelescopeModel MEADE_LX200_16 =
99 new TelescopeModel(RB.getString("MEADE_LX200_16"));
100
101 /*** Define Mead LX200 GPS */
102 public static final TelescopeModel MEADE_LX200_GPS =
103 new TelescopeModel(RB.getString("MEADE_LX200_GPS"));
104
105
106 // TODO - Add additional TelescopeModels
107
108 /*** Next ordinal number */
109 private static int nextOrdinal = 0;
110
111 /*** Current ordinal number */
112 private final int ordinal = nextOrdinal++;
113
114 /*** Telescope model name */
115 private final String name;
116
117 /*** Array of supported telescope models */
118 private static final TelescopeModel[] PRIVATE_VALUES = {
119 CELESTRON_ASC, CELESTRON_CGE, CELESTRON_NEXSTAR_5_8,
120 CELESTRON_NEXSTAR_5I_8I, CELESTRON_NEXSTAR_GPS,
121 CELESTRON_NEXSTAR_GT, CELESTRON_NEXSTAR_OGT,
122 MEADE_AUTOSTAR, MEADE_LX200, MEADE_LX200_16, MEADE_LX200_GPS
123 };
124 // TODO - Add additional telescope models
125
126 /*** List of telescope models */
127 public static final List VALUES = Collections.unmodifiableList(
128 Arrays.asList(PRIVATE_VALUES));
129
130 /***
131 * Prevent external instanciation to make this class a singleton
132 * @param name of the telescope model
133 */
134 private TelescopeModel(String name) {
135 this.name = name;
136 }
137
138 /***
139 * Compare TelescopeModels
140 * @param obj TelescopeModel to compare
141 * @return Ordinal difference
142 */
143 public int compareTo(Object obj) {
144 return ordinal - ((TelescopeModel) obj).ordinal;
145 }
146
147 /***
148 * Return name of TelescopeModel
149 * @return Name of telescope model
150 */
151 public String toString() {
152 return name;
153 }
154
155 /***
156 * Guarantee singularity during serialization
157 * @return ordinal value
158 * @exception ObjectStreamException may be thrown
159 */
160 private Object readResolve() throws ObjectStreamException {
161 return PRIVATE_VALUES[ordinal];
162 }
163
164 /***
165 * Get TelescopeModel from model name
166 * @param modelName of telescope
167 * @return TelescopeModel (May return null)
168 */
169 public static TelescopeModel fromString(String modelName) {
170 TelescopeModel model = null;
171
172 for (int i = 0; i < PRIVATE_VALUES.length; i++) {
173 if (PRIVATE_VALUES[i].toString().equals(modelName)) {
174 model = PRIVATE_VALUES[i];
175 break;
176 }
177 }
178
179 return model;
180
181
182 }
183
184 }
This page was automatically generated by Maven