55
66import java .io .Serializable ;
77
8+ import static com .flickr4java .flickr .contacts .OnlineStatus .OnlineStatusType .AWAY_TYPE ;
9+ import static com .flickr4java .flickr .contacts .OnlineStatus .OnlineStatusType .OFFLINE_TYPE ;
10+ import static com .flickr4java .flickr .contacts .OnlineStatus .OnlineStatusType .ONLINE_TYPE ;
11+ import static com .flickr4java .flickr .contacts .OnlineStatus .OnlineStatusType .UNKNOWN_TYPE ;
12+
813/**
914 * Class representing the various types of online statuses.
10- *
15+ *
1116 * @author Anthony Eden
1217 */
13- public class OnlineStatus implements Serializable {
14- private static final long serialVersionUID = 12L ;
15-
16- public static final int OFFLINE_TYPE = 0 ;
17-
18- public static final int AWAY_TYPE = 1 ;
19-
20- public static final int ONLINE_TYPE = 2 ;
21-
22- public static final int UNKNOWN_TYPE = 100 ;
18+ public enum OnlineStatus implements Serializable {
2319
24- public static final OnlineStatus OFFLINE = new OnlineStatus (OFFLINE_TYPE );
20+ OFFLINE (OFFLINE_TYPE ),
21+ AWAY (AWAY_TYPE ),
22+ ONLINE (ONLINE_TYPE ),
23+ UNKNOWN (UNKNOWN_TYPE );
2524
26- public static final OnlineStatus AWAY = new OnlineStatus (AWAY_TYPE );
27-
28- public static final OnlineStatus ONLINE = new OnlineStatus (ONLINE_TYPE );
29-
30- public static final OnlineStatus UNKNOWN = new OnlineStatus (UNKNOWN_TYPE );
25+ private static final long serialVersionUID = 12L ;
3126
32- private int type ;
27+ private final int type ;
3328
3429 private OnlineStatus (int type ) {
3530 this .type = type ;
3631 }
3732
3833 /**
3934 * Get the int value for the online status. This method is useful in switch statements.
40- *
35+ *
4136 * @return The int value for the online status
4237 */
4338 public int getType () {
@@ -46,31 +41,29 @@ public int getType() {
4641
4742 /**
4843 * Get an OnlineStatus object for a given int value.
49- *
50- * @param type
51- * The int value
44+ *
45+ * @param type The int value
5246 * @return The OnlineStatus object
5347 */
5448 public static OnlineStatus fromType (int type ) {
5549 switch (type ) {
56- case OFFLINE_TYPE :
57- return OFFLINE ;
58- case AWAY_TYPE :
59- return AWAY ;
60- case ONLINE_TYPE :
61- return ONLINE ;
62- case UNKNOWN_TYPE :
63- return UNKNOWN ;
64- default :
65- throw new IllegalArgumentException ("Unsupported online type: " + type );
50+ case OFFLINE_TYPE :
51+ return OFFLINE ;
52+ case AWAY_TYPE :
53+ return AWAY ;
54+ case ONLINE_TYPE :
55+ return ONLINE ;
56+ case UNKNOWN_TYPE :
57+ return UNKNOWN ;
58+ default :
59+ throw new IllegalArgumentException ("Unsupported online type: " + type );
6660 }
6761 }
6862
6963 /**
7064 * Get the OnlineStatus value for a given int represented as a String
71- *
72- * @param type
73- * The int represented as a String
65+ *
66+ * @param type The int represented as a String
7467 * @return The OnlineStatus object
7568 */
7669 public static OnlineStatus fromType (String type ) {
@@ -80,4 +73,11 @@ public static OnlineStatus fromType(String type) {
8073 return fromType (Integer .parseInt (type ));
8174 }
8275 }
76+
77+ static class OnlineStatusType {
78+ static final int OFFLINE_TYPE = 0 ;
79+ static final int AWAY_TYPE = 1 ;
80+ static final int ONLINE_TYPE = 2 ;
81+ static final int UNKNOWN_TYPE = 100 ;
82+ }
8383}
0 commit comments