@@ -18,25 +18,27 @@ public interface FileStore<T> extends Store<T> {
18
18
*
19
19
* @param file the file
20
20
* @param serializer the serializer instance
21
+ * @param token the type token of the stored object
21
22
* @param object the initial value of the store
22
23
* @param <T> the stored object type
23
24
* @return a new simple {@code FileStore}
24
25
*/
25
- static <T > FileStore <T > of (File file , Serializer <T > serializer , T object ) {
26
- return new SimpleFileStore <>(file , serializer , new TypeToken <>() {} , object );
26
+ static <T > FileStore <T > of (File file , Serializer <T > serializer , TypeToken < T > token , T object ) {
27
+ return new SimpleFileStore <>(file , serializer , token , object );
27
28
}
28
29
29
30
/**
30
31
* Creates a new {@code FileStore}.
31
32
*
32
33
* @param path the path of the file
33
34
* @param serializer the serializer instance
35
+ * @param token the type token of the stored object
34
36
* @param object the initial value of the store
35
37
* @param <T> the stored object type
36
38
* @return a new simple {@code FileStore}
37
39
*/
38
- static <T > FileStore <T > of (String path , Serializer <T > serializer , T object ) {
39
- return of (new File (path ), serializer , object );
40
+ static <T > FileStore <T > of (String path , Serializer <T > serializer , TypeToken < T > token , T object ) {
41
+ return of (new File (path ), serializer , token , object );
40
42
}
41
43
42
44
/**
@@ -46,51 +48,60 @@ static <T> FileStore<T> of(String path, Serializer<T> serializer, T object) {
46
48
*
47
49
* @param file the file
48
50
* @param serializer the serializer instance
51
+ * @param token the type token of the stored object
49
52
* @param <T> the stored object type
50
53
* @return a new simple {@code FileStore}
51
54
*/
52
- static <T > FileStore <T > of (File file , Serializer <T > serializer ) {
53
- return of (file , serializer , null );
55
+ static <T > FileStore <T > of (File file , Serializer <T > serializer , TypeToken < T > token ) {
56
+ return of (file , serializer , token , null );
54
57
}
55
58
56
-
57
59
/**
58
60
* Creates a new {@code FileStore}.
59
61
* <p>
60
62
* <strong>Attention</strong>, the initial value is null.
61
63
*
62
64
* @param path the path of the file
63
65
* @param serializer the serializer instance
66
+ * @param token the type token of the stored object
64
67
* @param <T> the stored object type
65
68
* @return a new simple {@code FileStore}
66
69
*/
67
- static <T > FileStore <T > of (String path , Serializer <T > serializer ) {
68
- return of (new File (path ), serializer , null );
70
+ static <T > FileStore <T > of (String path , Serializer <T > serializer , TypeToken < T > token ) {
71
+ return of (new File (path ), serializer , token , null );
69
72
}
70
73
74
+ /**
75
+ * {@inheritDoc}
76
+ * <p>
77
+ * If the parent directories of the file don't exist, they are created.
78
+ */
79
+ @ Override
80
+ void save ();
81
+
71
82
/**
72
83
* Returns the file where the object is stored.
73
84
*/
74
85
File getFile ();
75
86
76
87
/**
77
- * Set the file where the object is stored.
88
+ * Sets the file where the object is stored.
78
89
*
79
90
* @param file the file
80
91
*/
81
92
void setFile (File file );
82
93
83
94
/**
84
- * @return If the file exists.
85
- */
86
- boolean doesFileExist ();
87
-
88
- /**
89
- * Set the file where the object is stored.
95
+ * Sets the file where the object is stored.
90
96
*
91
97
* @param path the path of the file
92
98
*/
93
99
default void setFile (String path ) {
94
100
setFile (new File (path ));
95
101
}
102
+
103
+ @ Override
104
+ default boolean exists () {
105
+ return getFile ().exists ();
106
+ }
96
107
}
0 commit comments