diff --git a/src/nodash/core/spheres/NoHashInterface.java b/src/nodash/core/spheres/NoHashInterface.java deleted file mode 100644 index c4322e4..0000000 --- a/src/nodash/core/spheres/NoHashInterface.java +++ /dev/null @@ -1,13 +0,0 @@ -package nodash.core.spheres; - -import nodash.models.NoUser; - -public interface NoHashInterface { - public void setup(); - public void saveToFile(); - public void addNewNoUser(NoUser user); - public void insertHash(String hash); - public void removeHash(String hash); - public boolean checkHash(String hash); - public int size(); -} diff --git a/src/nodash/core/spheres/NoHashSphere.java b/src/nodash/core/spheres/NoHashSphereDefault.java similarity index 69% rename from src/nodash/core/spheres/NoHashSphere.java rename to src/nodash/core/spheres/NoHashSphereDefault.java index 95db4f2..fb7a55d 100644 --- a/src/nodash/core/spheres/NoHashSphere.java +++ b/src/nodash/core/spheres/NoHashSphereDefault.java @@ -34,11 +34,11 @@ import nodash.core.NoCore; import nodash.exceptions.NoDashFatalException; import nodash.models.NoUser; -public final class NoHashSphere { - private static Set database = Collections.newSetFromMap(new ConcurrentHashMap()); +public final class NoHashSphereDefault implements NoHashSphereInterface { + private Set database = Collections.newSetFromMap(new ConcurrentHashMap()); @SuppressWarnings("unchecked") - public static void setup() { + public void setup() { if (NoCore.config.saveDatabase) { File file = new File(NoCore.config.databaseFilename); if (file.exists()) { @@ -46,7 +46,7 @@ public final class NoHashSphere { byte[] data = Files.readAllBytes(file.toPath()); ByteArrayInputStream bais = new ByteArrayInputStream(data); ObjectInputStream ois = new ObjectInputStream(bais); - NoHashSphere.database = (Set) ois.readObject(); + this.database = (Set) ois.readObject(); ois.close(); bais.close(); } catch (IOException e){ @@ -58,10 +58,10 @@ public final class NoHashSphere { } } - public static synchronized void saveToFile() throws IOException { + public synchronized void saveToFile() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(NoHashSphere.database); + oos.writeObject(this.database); byte[] data = baos.toByteArray(); oos.close(); baos.close(); @@ -69,27 +69,27 @@ public final class NoHashSphere { Files.write(file.toPath(), data, StandardOpenOption.CREATE); } - public static synchronized void addNewNoUser(NoUser user) throws IOException { + public synchronized void addNewNoUser(NoUser user) throws IOException { String hash = user.createHashString(); - NoHashSphere.database.add(hash); - NoHashSphere.saveToFile(); + this.database.add(hash); + this.saveToFile(); } - public static synchronized void insertHash(String hash) throws IOException { - NoHashSphere.database.add(hash); - NoHashSphere.saveToFile(); + public synchronized void insertHash(String hash) throws IOException { + this.database.add(hash); + this.saveToFile(); } - public static synchronized void removeHash(String hash) throws IOException { - NoHashSphere.database.remove(hash); - NoHashSphere.saveToFile(); + public synchronized void removeHash(String hash) throws IOException { + this.database.remove(hash); + this.saveToFile(); } - public static synchronized boolean checkHash(String hash) { - return NoHashSphere.database.contains(hash); + public synchronized boolean checkHash(String hash) { + return this.database.contains(hash); } - public static synchronized int size() { - return NoHashSphere.database.size(); + public synchronized int size() { + return this.database.size(); } } diff --git a/src/nodash/core/spheres/NoHashSphereInterface.java b/src/nodash/core/spheres/NoHashSphereInterface.java new file mode 100644 index 0000000..145cbaa --- /dev/null +++ b/src/nodash/core/spheres/NoHashSphereInterface.java @@ -0,0 +1,15 @@ +package nodash.core.spheres; + +import java.io.IOException; + +import nodash.models.NoUser; + +public interface NoHashSphereInterface { + public void setup(); + public void saveToFile() throws IOException; + public void addNewNoUser(NoUser user) throws IOException; + public void insertHash(String hash) throws IOException; + public void removeHash(String hash) throws IOException; + public boolean checkHash(String hash); + public int size(); +}