2 * Rhynodge - 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.rhynodge.states;
20 import net.pterodactylus.rhynodge.State;
22 import com.fasterxml.jackson.annotation.JsonProperty;
23 import com.fasterxml.jackson.annotation.JsonTypeInfo;
26 * Abstract implementation of a {@link State} that knows about the basic
27 * attributes of a {@link State}.
29 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31 @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
32 public abstract class AbstractState implements State {
34 /** The time of this state. */
36 private final long time;
38 /** Whether the state was successfully retrieved. */
39 private final boolean success;
40 private final boolean empty;
42 /** The optional exception that occured while retrieving the state. */
43 private final Throwable exception;
45 /** The number of consecutive failures. */
47 private int failCount;
50 * Creates a new successful state.
52 protected AbstractState() {
57 * Creates a new state.
60 * {@code true} if the state is successful, {@code false}
63 protected AbstractState(boolean success) {
64 this(success, true, null);
67 protected AbstractState(boolean success, boolean empty) {
68 this(success, empty, null);
72 * Creates a new non-successful state with the given exception.
75 * The exception that occured while retrieving the state
77 protected AbstractState(Throwable exception) {
78 this(false, true, exception);
82 * Creates a new state.
85 * {@code true} if the state is successful, {@code false}
88 * The exception that occured while retrieving the state
90 protected AbstractState(boolean success, boolean empty, Throwable exception) {
91 this.time = System.currentTimeMillis();
92 this.success = success;
94 this.exception = exception;
113 public boolean success() {
118 public boolean isEmpty() {
126 public int failCount() {
134 public void setFailCount(int failCount) {
135 this.failCount = failCount;
142 public Throwable exception() {