File Source: ServerState.java
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc;
24
25 import java.util.Arrays;
26 import java.util.List;
27
28 /**
29 * An enumeration of possible states for servers.
30 */
/*
P/P * Method: ServerState valueOf(String)
*
* Postconditions:
* init'ed(return_value)
*/
31 public enum ServerState {
32
33 /** Indicates the client is in the process of connecting. */
/*
P/P * Method: com.dmdirc.ServerState__static_init
*
* Postconditions:
* $VALUES == &new ServerState[](ServerState__static_init#15)
* CLOSING == &new ServerState(ServerState__static_init#13)
* $VALUES[6] == &new ServerState(ServerState__static_init#13)
* CONNECTED == &new ServerState(ServerState__static_init#3)
* $VALUES[1] == &new ServerState(ServerState__static_init#3)
* CONNECTING == &new ServerState(ServerState__static_init#1)
* $VALUES[0] == &new ServerState(ServerState__static_init#1)
* DISCONNECTED == &new ServerState(ServerState__static_init#7)
* $VALUES[3] == &new ServerState(ServerState__static_init#7)
* DISCONNECTING == &new ServerState(ServerState__static_init#9)
* ...
*/
34 CONNECTING(
35 "CONNECTED", // Connection attempt succeeded
36 "TRANSIENTLY_DISCONNECTED", // Connection attempt failed
37 "DISCONNECTING", // User ordered a disconnection
38 "CLOSING" // DMDirc is closing
39 ),
40
41 /** Indicates the client has connected to the server. */
42 CONNECTED(
43 "DISCONNECTING", // User ordered a disconnection
44 "TRANSIENTLY_DISCONNECTED", // Server caused a disconnection
45 "CLOSING" // DMDirc is closing
46 ),
47
48 /** Indicates that we've been temporarily disconnected. */
49 TRANSIENTLY_DISCONNECTED(
50 "CONNECTING", // User forced a connect attempt
51 "RECONNECT_WAIT", // Waiting for auto-reconnect
52 "CLOSING" // DMDirc is closing
53 ),
54
55 /** Indicates that the user has told us to disconnect. */
56 DISCONNECTED(
57 "CONNECTING", // User forced a connect attempt
58 "CLOSING" // DMDirc is closing
59 ),
60
61 /** In the process of disconnecting. */
62 DISCONNECTING(
63 "DISCONNECTED", // Socket closed
64 "CLOSING" // DMDirc is closing
65 ),
66
67 /** Indicates we're waiting for the auto-reconnect timer to fire. */
68 RECONNECT_WAIT(
69 "CONNECTING", // User forced a connect attempt
70 "TRANSIENTLY_DISCONNECTED", // Reconnect timer expired
71 "DISCONNECTED", // User forced a disconnect
72 "CLOSING" // DMDirc is closing
73 ),
74
75 /** Indicates that the server frame and its children are closing. */
76 CLOSING;
77
78 /** The allowed transitions from this state. */
79 private final List<String> transitions;
80
81 /**
82 * Creates a new instance of ServerState.
83 *
84 * @since 0.6.3m1
85 * @param transitions The names of the states to which a transition is
86 * allowed from this state
87 */
/*
P/P * Method: void com.dmdirc.ServerState(String, int, String[])
*
* Postconditions:
* init'ed(this.transitions)
*/
88 ServerState(final String ... transitions) {
89 this.transitions = Arrays.asList(transitions);
90 }
91
92 /**
93 * Determines whether a transition from this state to the specified state
94 * would be legal.
95 *
96 * @since 0.6.3m1
97 * @param state The state that is being transitioned to
98 * @return True if the transition is allowed, false otherwise.
99 */
100 public boolean canTransitionTo(final ServerState state) {
/*
P/P * Method: bool canTransitionTo(ServerState)
*
* Preconditions:
* state != null
* this.transitions != null
*
* Postconditions:
* init'ed(return_value)
*/
101 return transitions.contains(state.name());
102 }
103
104 /**
105 * Determines where the current state is a disconnected one.
106 *
107 * @return True if the state is one of the disconnected states, false otherwise
108 * @since 0.6.3m1
109 */
110 public boolean isDisconnected() {
/*
P/P * Method: bool isDisconnected()
*
* Postconditions:
* init'ed(return_value)
*/
111 return this == ServerState.DISCONNECTED || this == ServerState.TRANSIENTLY_DISCONNECTED;
112 }
113 }
SofCheck Inspector Build Version : 2.17854
| ServerState.java |
2009-Jun-25 01:54:24 |
| ServerState.class |
2009-Sep-02 17:04:12 |