123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
- * Copyright (c) 2006-2015 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc;
-
- import java.util.Arrays;
- import java.util.List;
-
- /**
- * An enumeration of possible states for servers.
- */
- public enum ServerState {
-
- /** Indicates the client is in the process of connecting. */
- CONNECTING(
- "CONNECTED", // Connection attempt succeeded
- "TRANSIENTLY_DISCONNECTED", // Connection attempt failed
- "DISCONNECTING", // User ordered a disconnection
- "CLOSING" // DMDirc is closing
- ),
- /** Indicates the client has connected to the server. */
- CONNECTED(
- "DISCONNECTING", // User ordered a disconnection
- "TRANSIENTLY_DISCONNECTED", // Server caused a disconnection
- "CLOSING" // DMDirc is closing
- ),
- /** Indicates that we've been temporarily disconnected. */
- TRANSIENTLY_DISCONNECTED(
- "CONNECTING", // User forced a connect attempt
- "RECONNECT_WAIT", // Waiting for auto-reconnect
- "CLOSING" // DMDirc is closing
- ),
- /** Indicates that the user has told us to disconnect. */
- DISCONNECTED(
- "CONNECTING", // User forced a connect attempt
- "CLOSING" // DMDirc is closing
- ),
- /** In the process of disconnecting. */
- DISCONNECTING(
- "DISCONNECTED", // Socket closed
- "CLOSING" // DMDirc is closing
- ),
- /** Indicates we're waiting for the auto-reconnect timer to fire. */
- RECONNECT_WAIT(
- "CONNECTING", // User forced a connect attempt
- "TRANSIENTLY_DISCONNECTED", // Reconnect timer expired
- "DISCONNECTED", // User forced a disconnect
- "CLOSING" // DMDirc is closing
- ),
- /** Indicates that the server frame and its children are closing. */
- CLOSING;
- /** The allowed transitions from this state. */
- private final List<String> transitions;
-
- /**
- * Creates a new instance of ServerState.
- *
- * @since 0.6.3m1
- * @param transitions The names of the states to which a transition is allowed from this state
- */
- ServerState(final String... transitions) {
- this.transitions = Arrays.asList(transitions);
- }
-
- /**
- * Determines whether a transition from this state to the specified state would be legal.
- *
- * @since 0.6.3m1
- * @param state The state that is being transitioned to
- *
- * @return True if the transition is allowed, false otherwise.
- */
- public boolean canTransitionTo(final ServerState state) {
- return transitions.contains(state.name());
- }
-
- /**
- * Determines where the current state is a disconnected one.
- *
- * @return True if the state is one of the disconnected states, false otherwise
- *
- * @since 0.6.3m1
- */
- public boolean isDisconnected() {
- return this == ServerState.DISCONNECTED || this == ServerState.TRANSIENTLY_DISCONNECTED;
- }
-
- }
|