2 * Rhynodge - FailedState.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.rhynodge.states;
20 import net.pterodactylus.rhynodge.State;
23 * {@link State} implementation that signals failure.
25 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
27 public class FailedState extends AbstractState {
29 /** A failed state instance without an exception. */
30 public static final State INSTANCE = new FailedState();
33 * Creates a new failed state.
35 public FailedState() {
40 * Creates a new failed state with the given exception
43 * The exception of the state
45 public FailedState(Throwable exception) {
50 public boolean isEmpty() {
59 * Returns a failed state for the given state. The failed state will be
60 * unsuccessful ({@link #success()} returns false) and it will contain the
61 * same {@link #exception()} as the given state.
64 * The state to copy the exception from
65 * @return A failed state
67 public static FailedState from(State state) {
68 if (state instanceof FailedState) {
69 return (FailedState) state;
71 return new FailedState(state.exception());
82 public String toString() {
83 return String.format("%s[exception=%s]", getClass().getSimpleName(), exception());