Rename project to “Rhynodge.”
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / states / FileState.java
1 /*
2  * Rhynodge - FileState.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.rhynodge.states;
19
20 import net.pterodactylus.rhynodge.State;
21
22 /**
23  * A {@link State} that contains information about a file.
24  *
25  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
26  */
27 public class FileState extends AbstractState {
28
29         /** Whether the file exists. */
30         private final boolean exists;
31
32         /** Whether the file is readable. */
33         private final boolean readable;
34
35         /** The size of the file. */
36         private final long size;
37
38         /** The modification time of the file. */
39         private final long modificationTime;
40
41         /**
42          * Creates a new file state that signals that an exceptio occured during
43          * retrieval.
44          *
45          * @param exception
46          *            The exception that occured
47          */
48         public FileState(Throwable exception) {
49                 super(exception);
50                 exists = false;
51                 readable = false;
52                 size = -1;
53                 modificationTime = -1;
54         }
55
56         /**
57          * Creates a new file state.
58          *
59          * @param exists
60          *            {@code true} if the file exists, {@code false} otherwise
61          * @param readable
62          *            {@code true} if the file is readable, {@code false} otherwise
63          * @param size
64          *            The size of the file (in bytes)
65          * @param modificationTime
66          *            The modification time of the file (in milliseconds since Jan
67          *            1, 1970 UTC)
68          */
69         public FileState(boolean exists, boolean readable, long size, long modificationTime) {
70                 this.exists = exists;
71                 this.readable = readable;
72                 this.size = size;
73                 this.modificationTime = modificationTime;
74         }
75
76         //
77         // ACCESSORS
78         //
79
80         /**
81          * Returns whether the file exists.
82          *
83          * @return {@code true} if the file exists, {@code false} otherwise
84          */
85         public boolean exists() {
86                 return exists;
87         }
88
89         /**
90          * Returns whether the file is readable.
91          *
92          * @return {@code true} if the file is readable, {@code false} otherwise
93          */
94         public boolean readable() {
95                 return readable;
96         }
97
98         /**
99          * Returns the size of the file.
100          *
101          * @return The size of the file (in bytes)
102          */
103         public long size() {
104                 return size;
105         }
106
107         /**
108          * Returns the modification time of the file.
109          *
110          * @return The modification time of the file (in milliseconds since Jan 1,
111          *         1970 UTC)
112          */
113         public long modificationTime() {
114                 return modificationTime;
115         }
116
117         //
118         // OBJECT METHODS
119         //
120
121         /**
122          * {@inheritDoc}
123          */
124         @Override
125         public String toString() {
126                 return String.format("%s[exists=%s,readable=%s,size=%s,modificationTime=%d(%5$tc)", getClass().getSimpleName(), exists(), readable(), size(), modificationTime());
127         }
128
129 }