Skip to content

Commit 5a21c37

Browse files
committed
Add isLoaded() and isSaved() to HashStore
A use case of `isSaved()` could be to throw an exception of the hash store is expected to be saved after usage when it isn't.
1 parent 8ed7a66 commit 5a21c37

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

hash-utils/src/main/java/net/minecraftforge/util/hash/HashStore.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class HashStore {
2828
private final Map<String, String> oldHashes = new HashMap<>();
2929
private final Map<String, String> newHashes = new HashMap<>();
3030
private @Nullable File target;
31+
private boolean saved;
3132

3233
public static HashStore fromFile(File path) {
3334
File parent = path.getAbsoluteFile().getParentFile();
@@ -106,6 +107,10 @@ public HashStore load(File file) {
106107
return this;
107108
}
108109

110+
public boolean isLoaded() {
111+
return this.target != null;
112+
}
113+
109114
public boolean exists() {
110115
return this.target != null && this.target.exists();
111116
}
@@ -193,11 +198,16 @@ public void save(File file) {
193198

194199
try {
195200
Files.write(file.toPath(), buf.toString().getBytes(StandardCharsets.UTF_8));
201+
this.saved = true;
196202
} catch (IOException e) {
197203
sneak(e);
198204
}
199205
}
200206

207+
public boolean isSaved() {
208+
return this.saved;
209+
}
210+
201211
private String getPath(File file) {
202212
String path = file.getAbsolutePath();
203213

0 commit comments

Comments
 (0)