package org.cass; import java.io.*; /** A class containing the default attributes of the three SMEI cameras, as well as a set of utilities specific to cameras. @author Zachary Vaughan @version 1.0, 06/30/2006 @see Mode Mode */ public final class Camera implements Serializable { /** The unique instance representing Camera 1. */ public static final Camera C1 = new Camera(1, Mode.M2); /** The unique instance representing Camera 2. */ public static final Camera C2 = new Camera(2, Mode.M2); /** The unique instance representing Camera 3. */ public static final Camera C3 = new Camera(3, Mode.M1); /** Gets the Camera instance represented by the given integer. The integer can only be one of 1, 2 or 3. Any other value will result in an IllegalArgumentException. @param i the integer to interpret. @throws IllegalArgumentException if the integer is not one of 1, 2 or 3. @return the corresponding Camera instance of the given number. */ public static Camera getCamera(int i) { if(i == 1) return C1; if(i == 2) return C2; if(i == 3) return C3; throw new IllegalArgumentException("Invalid camera number."); } /** Gets the Camera instance represented by the given string argument. The string argument can be any string beginning with optional whitespace followed by at least two characters, the first of which must be either an uppercase or lowercase "C" and followed by the number representing the desired camera ID. The only possible allowed values for these initial two characters, therefore, are as follows: @param s the string to parse. @throws NullPointerException if s is null. @throws IllegalArgumentException if the given string is not formatted correctly. @return the unique Camera instance for the given string argument. */ public static Camera parseCamera(String s) { s = s.trim().toLowerCase(); if(s.startsWith("c1")) return C1; if(s.startsWith("c2")) return C2; if(s.startsWith("c3")) return C3; throw new IllegalArgumentException("Invalid camera string format."); } private int id; private transient Mode dmode; private Camera(int id, Mode dmode) { this.id = id; this.dmode = dmode; } /** Gets the unique ID associated with this camera, either 1, 2 or 3. @return the unique ID. */ public int getID() { return id; } /** Gets the default Mode instance associated with this camera. @return the default Mode instance. */ public Mode getDefaultMode() { return dmode; } /** Gets the String representation of this camera. The string consists of a lowercase "c" followed by the ID of this Camera. @return the string representation. */ public String toString() { return "c" + id; } private Object readResolve() throws ObjectStreamException { switch(id) { case 1: return C1; case 2: return C2; case 3: return C3; default: throw new InvalidObjectException("Invalid camera ID."); } } }