001 package edu.nrao.sss.model.project.scan; 002 003 import java.util.ArrayList; 004 import java.util.EnumSet; 005 import java.util.List; 006 007 import edu.nrao.sss.util.EnumerationUtility; 008 009 /** 010 * An enumeration of the different kinds of time associated with a 011 * {@link Scan}. An observer may specify either a <i>duration</i> or a 012 * <i>point in time</i> for a scan. If duration is chosen, the observer 013 * may then choose either a total duration or the amount of time to 014 * spend on-source. 015 * If time is chosen, the observer may then 016 * choose either a start or stop time. For both durations and times 017 * a choice must also be made between expressing time in sidereal unit 018 * or standard units. 019 * <p> 020 * <b>Version Info:</b> 021 * <table style="margin-left:2em"> 022 * <tr><td>$Revision: 2142 $</td></tr> 023 * <tr><td>$Date: 2009-03-30 13:29:56 -0600 (Mon, 30 Mar 2009) $</td></tr> 024 * <tr><td>$Author: btruitt $</td></tr> 025 * </table></p> 026 * 027 * @author David M. Harland 028 * @since 2006-07-14 029 */ 030 public enum ScanTimeType 031 { 032 /** 033 * The amount of time spent observing a source, in sidereal units. 034 */ 035 ON_SOURCE_SIDEREAL(T.ON_SOURCE, T.SIDEREAL, "On Source (LST)"), 036 037 /** 038 * The total amount of time spent on a scan, in sidereal units. 039 * This time includes both time spent on the source 040 * and time spent moving the telescope from one source 041 * to another and time spent configuring the hardware. 042 */ 043 DURATION_SIDEREAL(T.TOTAL_DUR, T.SIDEREAL, "Duration (LST)"), 044 045 /** 046 * The local sidereal time at which a scan begins. 047 */ 048 START_LST(T.START, T.SIDEREAL, "Start Time (LST)"), 049 050 /** 051 * The local sidereal time at which a scan concludes. 052 */ 053 STOP_LST(T.STOP, T.SIDEREAL, "Stop Time (LST)"), 054 055 /** 056 * The amount of time spent observing a source, in SI units. 057 */ 058 ON_SOURCE_UT(T.ON_SOURCE, T.UT, "On Source (UT)"), 059 060 /** 061 * The total amount of time spent on a scan, in SI units. 062 * This time includes both time spent on the source 063 * and time spent moving the telescope from one source 064 * to another and time spent configuring the hardware. 065 */ 066 DURATION_UT(T.TOTAL_DUR, T.UT, "Duration (UT)"), 067 068 /** 069 * The date and time at which a scan begins. 070 * <p> 071 * The date/time is expressed in conventional units. 072 * Though the "UT" suffix may seem to imply that the Greenwich 073 * time zone be used, that is not the case. Any time zone may 074 * be used; the time merely needs to be in SI units, not 075 * sidereal units.</p> 076 */ 077 START_UT(T.START, T.UT, "Start Time (UT)"), 078 079 /** 080 * The date and time at which a scan concludes. 081 * <p> 082 * The date/time is expressed in conventional units. 083 * Though the "UT" suffix may seem to imply that the Greenwich 084 * time zone be used, that is not the case. Any time zone may 085 * be used; the time merely needs to be in SI units, not 086 * sidereal units.</p> 087 */ 088 STOP_UT(T.STOP, T.UT, "Stop Time (UT)"); 089 090 private static interface T 091 { 092 public int START = 1; 093 public int STOP = 2; 094 public int ON_SOURCE = 3; 095 public int TOTAL_DUR = 4; 096 097 public boolean SIDEREAL = true; 098 public boolean UT = false; 099 } 100 101 private String displayText; 102 103 private boolean isStart; 104 private boolean isStop; 105 private boolean isOnSource; 106 private boolean isTotalDuration; 107 private boolean isSidereal; 108 109 private ScanTimeType(int timeType, boolean isStellar, String display) 110 { 111 displayText = display; 112 113 isSidereal = isStellar; 114 115 switch (timeType) 116 { 117 case T.START: 118 isStart = true; 119 isStop = isOnSource = isTotalDuration = false; 120 break; 121 122 case T.STOP: 123 isStop = true; 124 isStart = isOnSource = isTotalDuration = false; 125 break; 126 127 case T.ON_SOURCE: 128 isOnSource = true; 129 isStart = isStop = isTotalDuration = false; 130 break; 131 132 case T.TOTAL_DUR: 133 isTotalDuration = true; 134 isStart = isStop = isOnSource = false; 135 break; 136 137 default: 138 throw new RuntimeException("PROGRAMMER ERROR: Unknown timeType of '" + 139 timeType +"'."); 140 } 141 } 142 143 /** 144 * Returns the time type to use as a default. 145 * @return a default scan time type. 146 */ 147 public static ScanTimeType getDefault() 148 { 149 return ON_SOURCE_SIDEREAL; 150 } 151 152 /** 153 * Returns <i>true</i> if this time type is a duration 154 * (as opposed to a point in time). 155 * 156 * @return <i>true</i> if this time type is a duration. 157 */ 158 public boolean isDuration() { return isOnSource || isTotalDuration; } 159 160 /** 161 * Returns <i>true</i> if this time type is a point in time 162 * (as opposed to a duration). 163 * 164 * @return <i>true</i> if this time type is a point in time. 165 */ 166 public boolean isPointInTime() { return isStart || isStop; } 167 168 /** 169 * Returns <i>true</i> if this time type is a time-on-source duration. 170 * @return <i>true</i> if this time type is a time-on-source duration. 171 */ 172 public boolean isOnSourceDuration() { return isOnSource; } 173 174 /** 175 * Returns <i>true</i> if this time type is a total duration. 176 * @return <i>true</i> if this time type is a total duration. 177 */ 178 public boolean isTotalDuration() { return isTotalDuration; } 179 180 /** 181 * Returns <i>true</i> if this time type is a start time. 182 * @return <i>true</i> if this time type is a start time. 183 */ 184 public boolean isStartTime() { return isStart; } 185 186 /** 187 * Returns <i>true</i> if this time type is a stop time. 188 * @return <i>true</i> if this time type is a stop time. 189 */ 190 public boolean isStopTime() { return isStop; } 191 192 /** 193 * Returns <i>true</i> if this time type is expressed in SI units. 194 * @return <i>true</i> if this time type is expressed in SI units. 195 */ 196 public boolean isUniversalTime() { return !isSidereal; } 197 198 /** 199 * Returns <i>true</i> if this time type is expressed in sidereal units. 200 * @return <i>true</i> if this time type is expressed in sidereal units. 201 */ 202 public boolean isSiderealTime() { return isSidereal; } 203 204 /** 205 * Returns a text representation of this enumeration constant. 206 * @return a text representation of this enumeration constant. 207 */ 208 @Override 209 public String toString() { return displayText; } 210 211 /** 212 * Returns the scan time type represented by {@code text}. 213 * <p> 214 * For details about the transformation, see 215 * {@link EnumerationUtility#enumFromString(Class, String)}.</p> 216 * 217 * @param text a text representation of a scan time type. 218 * 219 * @return the scan time type represented by {@code text}. 220 */ 221 public static ScanTimeType fromString(String text) 222 { 223 return EnumerationUtility.getSharedInstance() 224 .enumFromString(ScanTimeType.class, text); 225 } 226 227 //============================================================================ 228 // SUBSETS OF THIS ENUMERATION 229 //============================================================================ 230 231 private static final EnumSet<ScanTimeType> SIDEREAL_ELEMENTS = 232 EnumSet.of(ON_SOURCE_SIDEREAL, DURATION_SIDEREAL, START_LST, STOP_LST); 233 234 private static final EnumSet<ScanTimeType> UT_ELEMENTS = 235 EnumSet.of(ON_SOURCE_UT, DURATION_UT, START_UT, STOP_UT); 236 237 /** 238 * Returns the elements of this enumeration that are based on sidereal time. 239 * The returned list is not referenced by this class and may therefore be 240 * safely manipulated by clients. 241 * 242 * @return 243 * the elements of this enumeration that are based on sidereal time. 244 */ 245 public static List<ScanTimeType> siderealSubset() 246 { 247 return new ArrayList<ScanTimeType>(SIDEREAL_ELEMENTS); 248 } 249 250 /** 251 * Returns the elements of this enumeration that are based on universal time. 252 * The returned list is not referenced by this class and may therefore be 253 * safely manipulated by clients. 254 * 255 * @return 256 * the elements of this enumeration that are based on universal time. 257 */ 258 public static List<ScanTimeType> utSubset() 259 { 260 return new ArrayList<ScanTimeType>(UT_ELEMENTS); 261 } 262 }