2 * Reactor - AbstractState.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.reactor.states;
20 import net.pterodactylus.reactor.State;
23 * Abstract implementation of a {@link State} that knows about the basic
24 * attributes of a {@link State}.
26 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28 public abstract class AbstractState implements State {
30 /** The time of this state. */
31 private final long time;
33 /** Whether the state was successfully retrieved. */
34 private final boolean success;
36 /** The optional exception that occured while retrieving the state. */
37 private final Throwable exception;
40 * Creates a new successful state.
42 protected AbstractState() {
47 * Creates a new state.
50 * {@code true} if the state is successful, {@code false}
53 protected AbstractState(boolean success) {
58 * Creates a new non-successful state with the given exception.
61 * The exception that occured while retrieving the state
63 protected AbstractState(Throwable exception) {
64 this(false, exception);
68 * Creates a new state.
71 * {@code true} if the state is successful, {@code false}
74 * The exception that occured while retrieving the state
76 protected AbstractState(boolean success, Throwable exception) {
77 this.time = System.currentTimeMillis();
78 this.success = success;
79 this.exception = exception;
98 public boolean success() {
106 public Throwable exception() {