//# 0 errors, 144 messages
//#
/*
    //#ServerState.java:1:1: class: com.dmdirc.ServerState
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * 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 {
    //#ServerState.java:31: method: ServerState[] com.dmdirc.ServerState.values()
    //#input(ServerState[] values()): $VALUES
    //#input(ServerState[] values()): $VALUES.length
    //#input(ServerState[] values()): $VALUES[0..7]
    //#output(ServerState[] values()): new ServerState[](values#1) num objects
    //#output(ServerState[] values()): return_value.length
    //#output(ServerState[] values()): return_value[0..7]
    //#output(ServerState[] values()): return_value
    //#new obj(ServerState[] values()): new ServerState[](values#1)
    //#pre[1] (ServerState[] values()): (soft) init'ed($VALUES[0..7])
    //#post(ServerState[] values()): return_value == &new ServerState[](values#1)
    //#post(ServerState[] values()): new ServerState[](values#1) num objects == 1
    //#post(ServerState[] values()): return_value.length == 7
    //#post(ServerState[] values()): return_value[0..7] == One-of{$VALUES[0..7], undefined}
    //#ServerState.java:31: end of method: ServerState[] com.dmdirc.ServerState.values()
    //#ServerState.java:31: method: ServerState com.dmdirc.ServerState.valueOf(String)
    //#input(ServerState valueOf(String)): __Descendant_Table[com/dmdirc/ServerState]
    //#input(ServerState valueOf(String)): __Descendant_Table[others]
    //#input(ServerState valueOf(String)): name
    //#output(ServerState valueOf(String)): return_value
    //#presumption(ServerState valueOf(String)): java.lang.Enum:valueOf(...).__Tag@31 == com/dmdirc/ServerState
    //#post(ServerState valueOf(String)): init'ed(return_value)
    //#ServerState.java:31: end of method: ServerState com.dmdirc.ServerState.valueOf(String)

    /** Indicates the client is in the process of connecting. */
    CONNECTING(
    //#ServerState.java:34: method: com.dmdirc.ServerState.com.dmdirc.ServerState__static_init
    //#output(com.dmdirc.ServerState__static_init): $VALUES
    //#output(com.dmdirc.ServerState__static_init): CLOSING
    //#output(com.dmdirc.ServerState__static_init): CONNECTED
    //#output(com.dmdirc.ServerState__static_init): CONNECTING
    //#output(com.dmdirc.ServerState__static_init): DISCONNECTED
    //#output(com.dmdirc.ServerState__static_init): DISCONNECTING
    //#output(com.dmdirc.ServerState__static_init): RECONNECT_WAIT
    //#output(com.dmdirc.ServerState__static_init): TRANSIENTLY_DISCONNECTED
    //#output(com.dmdirc.ServerState__static_init): __Descendant_Table[com/dmdirc/ServerState]
    //#output(com.dmdirc.ServerState__static_init): __Dispatch_Table.canTransitionTo(Lcom/dmdirc/ServerState;)Z
    //#output(com.dmdirc.ServerState__static_init): __Dispatch_Table.isDisconnected()Z
    //#output(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#1) num objects
    //#output(com.dmdirc.ServerState__static_init): CONNECTING.__Tag
    //#output(com.dmdirc.ServerState__static_init): CONNECTING.transitions
    //#output(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#11) num objects
    //#output(com.dmdirc.ServerState__static_init): RECONNECT_WAIT.__Tag
    //#output(com.dmdirc.ServerState__static_init): RECONNECT_WAIT.transitions
    //#output(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#13) num objects
    //#output(com.dmdirc.ServerState__static_init): CLOSING.__Tag
    //#output(com.dmdirc.ServerState__static_init): CLOSING.transitions
    //#output(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#3) num objects
    //#output(com.dmdirc.ServerState__static_init): CONNECTED.__Tag
    //#output(com.dmdirc.ServerState__static_init): CONNECTED.transitions
    //#output(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#5) num objects
    //#output(com.dmdirc.ServerState__static_init): TRANSIENTLY_DISCONNECTED.__Tag
    //#output(com.dmdirc.ServerState__static_init): TRANSIENTLY_DISCONNECTED.transitions
    //#output(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#7) num objects
    //#output(com.dmdirc.ServerState__static_init): DISCONNECTED.__Tag
    //#output(com.dmdirc.ServerState__static_init): DISCONNECTED.transitions
    //#output(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#9) num objects
    //#output(com.dmdirc.ServerState__static_init): DISCONNECTING.__Tag
    //#output(com.dmdirc.ServerState__static_init): DISCONNECTING.transitions
    //#output(com.dmdirc.ServerState__static_init): new ServerState[](ServerState__static_init#15) num objects
    //#output(com.dmdirc.ServerState__static_init): $VALUES.length
    //#output(com.dmdirc.ServerState__static_init): $VALUES[0]
    //#output(com.dmdirc.ServerState__static_init): $VALUES[1]
    //#output(com.dmdirc.ServerState__static_init): $VALUES[2]
    //#output(com.dmdirc.ServerState__static_init): $VALUES[3]
    //#output(com.dmdirc.ServerState__static_init): $VALUES[4]
    //#output(com.dmdirc.ServerState__static_init): $VALUES[5]
    //#output(com.dmdirc.ServerState__static_init): $VALUES[6]
    //#new obj(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#1)
    //#new obj(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#11)
    //#new obj(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#13)
    //#new obj(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#3)
    //#new obj(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#5)
    //#new obj(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#7)
    //#new obj(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#9)
    //#new obj(com.dmdirc.ServerState__static_init): new ServerState[](ServerState__static_init#15)
    //#post(com.dmdirc.ServerState__static_init): $VALUES == &new ServerState[](ServerState__static_init#15)
    //#post(com.dmdirc.ServerState__static_init): CLOSING == &new ServerState(ServerState__static_init#13)
    //#post(com.dmdirc.ServerState__static_init): $VALUES[6] == &new ServerState(ServerState__static_init#13)
    //#post(com.dmdirc.ServerState__static_init): CONNECTED == &new ServerState(ServerState__static_init#3)
    //#post(com.dmdirc.ServerState__static_init): $VALUES[1] == &new ServerState(ServerState__static_init#3)
    //#post(com.dmdirc.ServerState__static_init): CONNECTING == &new ServerState(ServerState__static_init#1)
    //#post(com.dmdirc.ServerState__static_init): $VALUES[0] == &new ServerState(ServerState__static_init#1)
    //#post(com.dmdirc.ServerState__static_init): DISCONNECTED == &new ServerState(ServerState__static_init#7)
    //#post(com.dmdirc.ServerState__static_init): $VALUES[3] == &new ServerState(ServerState__static_init#7)
    //#post(com.dmdirc.ServerState__static_init): DISCONNECTING == &new ServerState(ServerState__static_init#9)
    //#post(com.dmdirc.ServerState__static_init): $VALUES[4] == &new ServerState(ServerState__static_init#9)
    //#post(com.dmdirc.ServerState__static_init): RECONNECT_WAIT == &new ServerState(ServerState__static_init#11)
    //#post(com.dmdirc.ServerState__static_init): $VALUES[5] == &new ServerState(ServerState__static_init#11)
    //#post(com.dmdirc.ServerState__static_init): TRANSIENTLY_DISCONNECTED == &new ServerState(ServerState__static_init#5)
    //#post(com.dmdirc.ServerState__static_init): $VALUES[2] == &new ServerState(ServerState__static_init#5)
    //#post(com.dmdirc.ServerState__static_init): __Descendant_Table[com/dmdirc/ServerState] == &__Dispatch_Table
    //#post(com.dmdirc.ServerState__static_init): __Dispatch_Table.canTransitionTo(Lcom/dmdirc/ServerState;)Z == &canTransitionTo
    //#post(com.dmdirc.ServerState__static_init): __Dispatch_Table.isDisconnected()Z == &isDisconnected
    //#post(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#1) num objects == 1
    //#post(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#11) num objects == 1
    //#post(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#13) num objects == 1
    //#post(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#3) num objects == 1
    //#post(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#5) num objects == 1
    //#post(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#7) num objects == 1
    //#post(com.dmdirc.ServerState__static_init): new ServerState(ServerState__static_init#9) num objects == 1
    //#post(com.dmdirc.ServerState__static_init): new ServerState[](ServerState__static_init#15) num objects == 1
    //#post(com.dmdirc.ServerState__static_init): CONNECTING.__Tag == com/dmdirc/ServerState
    //#post(com.dmdirc.ServerState__static_init): RECONNECT_WAIT.__Tag == com/dmdirc/ServerState
    //#post(com.dmdirc.ServerState__static_init): CLOSING.__Tag == com/dmdirc/ServerState
    //#post(com.dmdirc.ServerState__static_init): CONNECTED.__Tag == com/dmdirc/ServerState
    //#post(com.dmdirc.ServerState__static_init): TRANSIENTLY_DISCONNECTED.__Tag == com/dmdirc/ServerState
    //#post(com.dmdirc.ServerState__static_init): DISCONNECTED.__Tag == com/dmdirc/ServerState
    //#post(com.dmdirc.ServerState__static_init): DISCONNECTING.__Tag == com/dmdirc/ServerState
    //#post(com.dmdirc.ServerState__static_init): init'ed(CONNECTING.transitions)
    //#post(com.dmdirc.ServerState__static_init): init'ed(RECONNECT_WAIT.transitions)
    //#post(com.dmdirc.ServerState__static_init): init'ed(CLOSING.transitions)
    //#post(com.dmdirc.ServerState__static_init): init'ed(CONNECTED.transitions)
    //#post(com.dmdirc.ServerState__static_init): init'ed(TRANSIENTLY_DISCONNECTED.transitions)
    //#post(com.dmdirc.ServerState__static_init): init'ed(DISCONNECTED.transitions)
    //#post(com.dmdirc.ServerState__static_init): init'ed(DISCONNECTING.transitions)
    //#post(com.dmdirc.ServerState__static_init): $VALUES.length == 7
    //#unanalyzed(com.dmdirc.ServerState__static_init): Effects-of-calling:java.lang.Enum
    //#unanalyzed(com.dmdirc.ServerState__static_init): Effects-of-calling:java.util.Arrays:asList
            "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;
    //#ServerState.java:76: end of method: com.dmdirc.ServerState.com.dmdirc.ServerState__static_init

    /** 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) {
    //#ServerState.java:88: method: void com.dmdirc.ServerState.com.dmdirc.ServerState(String, int, String[])
    //#input(void com.dmdirc.ServerState(String, int, String[])): Param_1
    //#input(void com.dmdirc.ServerState(String, int, String[])): Param_2
    //#input(void com.dmdirc.ServerState(String, int, String[])): this
    //#input(void com.dmdirc.ServerState(String, int, String[])): transitions
    //#output(void com.dmdirc.ServerState(String, int, String[])): this.transitions
    //#post(void com.dmdirc.ServerState(String, int, String[])): init'ed(this.transitions)
        this.transitions = Arrays.asList(transitions);
    }
    //#ServerState.java:90: end of method: void com.dmdirc.ServerState.com.dmdirc.ServerState(String, int, String[])

    /**
     * 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());
    //#ServerState.java:101: method: bool com.dmdirc.ServerState.canTransitionTo(ServerState)
    //#ServerState.java:101: Warning: method not available - call not analyzed
    //#    call on String com.dmdirc.ServerState:name()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.ServerState
    //#    method: bool canTransitionTo(ServerState)
    //#    unanalyzed callee: String com.dmdirc.ServerState:name()
    //#input(bool canTransitionTo(ServerState)): state
    //#input(bool canTransitionTo(ServerState)): this
    //#input(bool canTransitionTo(ServerState)): this.transitions
    //#output(bool canTransitionTo(ServerState)): return_value
    //#pre[1] (bool canTransitionTo(ServerState)): state != null
    //#pre[3] (bool canTransitionTo(ServerState)): this.transitions != null
    //#post(bool canTransitionTo(ServerState)): init'ed(return_value)
    //#ServerState.java:101: end of method: bool com.dmdirc.ServerState.canTransitionTo(ServerState)
    }

    /**
     * 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;
    //#ServerState.java:111: method: bool com.dmdirc.ServerState.isDisconnected()
    //#input(bool isDisconnected()): DISCONNECTED
    //#input(bool isDisconnected()): TRANSIENTLY_DISCONNECTED
    //#input(bool isDisconnected()): this
    //#output(bool isDisconnected()): return_value
    //#post(bool isDisconnected()): init'ed(return_value)
    //#ServerState.java:111: end of method: bool com.dmdirc.ServerState.isDisconnected()
    }
}    //#ServerState.java:: end of class: com.dmdirc.ServerState
