2 * Rhynodge - FileState.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 * A {@link State} that contains information about a file.
25 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
27 public class FileState extends AbstractState {
29 /** Whether the file exists. */
30 private final boolean exists;
32 /** Whether the file is readable. */
33 private final boolean readable;
35 /** The size of the file. */
36 private final long size;
38 /** The modification time of the file. */
39 private final long modificationTime;
42 * Creates a new file state that signals that an exceptio occured during
46 * The exception that occured
48 public FileState(Throwable exception) {
53 modificationTime = -1;
57 * Creates a new file state.
60 * {@code true} if the file exists, {@code false} otherwise
62 * {@code true} if the file is readable, {@code false} otherwise
64 * The size of the file (in bytes)
65 * @param modificationTime
66 * The modification time of the file (in milliseconds since Jan
69 public FileState(boolean exists, boolean readable, long size, long modificationTime) {
71 this.readable = readable;
73 this.modificationTime = modificationTime;
81 public boolean isEmpty() {
86 * Returns whether the file exists.
88 * @return {@code true} if the file exists, {@code false} otherwise
90 public boolean exists() {
95 * Returns whether the file is readable.
97 * @return {@code true} if the file is readable, {@code false} otherwise
99 public boolean readable() {
104 * Returns the size of the file.
106 * @return The size of the file (in bytes)
113 * Returns the modification time of the file.
115 * @return The modification time of the file (in milliseconds since Jan 1,
118 public long modificationTime() {
119 return modificationTime;
130 public String toString() {
131 return String.format("%s[exists=%s,readable=%s,size=%s,modificationTime=%d(%5$tc)", getClass().getSimpleName(), exists(), readable(), size(), modificationTime());