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 javax.annotation.Nonnull;
22 import net.pterodactylus.rhynodge.State;
25 * A {@link State} that contains information about a file.
27 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29 public class FileState extends AbstractState {
31 /** Whether the file exists. */
32 private final boolean exists;
34 /** Whether the file is readable. */
35 private final boolean readable;
37 /** The size of the file. */
38 private final long size;
40 /** The modification time of the file. */
41 private final long modificationTime;
44 * Creates a new file state that signals that an exceptio occured during
48 * The exception that occured
50 public FileState(Throwable exception) {
55 modificationTime = -1;
59 * Creates a new file state.
62 * {@code true} if the file exists, {@code false} otherwise
64 * {@code true} if the file is readable, {@code false} otherwise
66 * The size of the file (in bytes)
67 * @param modificationTime
68 * The modification time of the file (in milliseconds since Jan
71 public FileState(boolean exists, boolean readable, long size, long modificationTime) {
73 this.readable = readable;
75 this.modificationTime = modificationTime;
83 public boolean isEmpty() {
88 * Returns whether the file exists.
90 * @return {@code true} if the file exists, {@code false} otherwise
92 public boolean exists() {
97 * Returns whether the file is readable.
99 * @return {@code true} if the file is readable, {@code false} otherwise
101 public boolean readable() {
106 * Returns the size of the file.
108 * @return The size of the file (in bytes)
115 * Returns the modification time of the file.
117 * @return The modification time of the file (in milliseconds since Jan 1,
120 public long modificationTime() {
121 return modificationTime;
126 protected String plainText() {
138 public String toString() {
139 return String.format("%s[exists=%s,readable=%s,size=%s,modificationTime=%d(%5$tc)", getClass().getSimpleName(), exists(), readable(), size(), modificationTime());