From 915582ae1dd7f79f502e52c15b91fed1430c68b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 2 Jan 2013 11:07:05 +0100 Subject: [PATCH] Add a file state. --- .../pterodactylus/reactor/states/FileState.java | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/main/java/net/pterodactylus/reactor/states/FileState.java diff --git a/src/main/java/net/pterodactylus/reactor/states/FileState.java b/src/main/java/net/pterodactylus/reactor/states/FileState.java new file mode 100644 index 0000000..b0c439e --- /dev/null +++ b/src/main/java/net/pterodactylus/reactor/states/FileState.java @@ -0,0 +1,117 @@ +/* + * Reactor - FileState.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.reactor.states; + +import net.pterodactylus.reactor.State; + +/** + * A {@link State} that contains information about a file. + * + * @author David ‘Bombe’ Roden + */ +public class FileState extends AbstractState { + + /** Whether the file exists. */ + private final boolean exists; + + /** Whether the file is readable. */ + private final boolean readable; + + /** The size of the file. */ + private final long size; + + /** The modification time of the file. */ + private final long modificationTime; + + /** + * Creates a new file state that signals that an exceptio occured during + * retrieval. + * + * @param exception + * The exception that occured + */ + public FileState(Throwable exception) { + super(exception); + exists = false; + readable = false; + size = -1; + modificationTime = -1; + } + + /** + * Creates a new file state. + * + * @param exists + * {@code true} if the file exists, {@code false} otherwise + * @param readable + * {@code true} if the file is readable, {@code false} otherwise + * @param size + * The size of the file (in bytes) + * @param modificationTime + * The modification time of the file (in milliseconds since Jan + * 1, 1970 UTC) + */ + public FileState(boolean exists, boolean readable, long size, long modificationTime) { + this.exists = exists; + this.readable = readable; + this.size = size; + this.modificationTime = modificationTime; + } + + // + // ACCESSORS + // + + /** + * Returns whether the file exists. + * + * @return {@code true} if the file exists, {@code false} otherwise + */ + public boolean exists() { + return exists; + } + + /** + * Returns whether the file is readable. + * + * @return {@code true} if the file is readable, {@code false} otherwise + */ + public boolean readable() { + return readable; + } + + /** + * Returns the size of the file. + * + * @return The size of the file (in bytes) + */ + public long size() { + return size; + } + + /** + * Returns the modification time of the file. + * + * @return The modification time of the file (in milliseconds since Jan 1, + * 1970 UTC) + */ + public long modificationTime() { + return modificationTime; + } + +} -- 2.7.4