Renamed interface and base implementation, changed methods from static
This commit is contained in:
@@ -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();
|
|
||||||
}
|
|
||||||
@@ -34,11 +34,11 @@ import nodash.core.NoCore;
|
|||||||
import nodash.exceptions.NoDashFatalException;
|
import nodash.exceptions.NoDashFatalException;
|
||||||
import nodash.models.NoUser;
|
import nodash.models.NoUser;
|
||||||
|
|
||||||
public final class NoHashSphere {
|
public final class NoHashSphereDefault implements NoHashSphereInterface {
|
||||||
private static Set<String> database = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
private Set<String> database = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void setup() {
|
public void setup() {
|
||||||
if (NoCore.config.saveDatabase) {
|
if (NoCore.config.saveDatabase) {
|
||||||
File file = new File(NoCore.config.databaseFilename);
|
File file = new File(NoCore.config.databaseFilename);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@@ -46,7 +46,7 @@ public final class NoHashSphere {
|
|||||||
byte[] data = Files.readAllBytes(file.toPath());
|
byte[] data = Files.readAllBytes(file.toPath());
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||||
NoHashSphere.database = (Set<String>) ois.readObject();
|
this.database = (Set<String>) ois.readObject();
|
||||||
ois.close();
|
ois.close();
|
||||||
bais.close();
|
bais.close();
|
||||||
} catch (IOException e){
|
} 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();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||||
oos.writeObject(NoHashSphere.database);
|
oos.writeObject(this.database);
|
||||||
byte[] data = baos.toByteArray();
|
byte[] data = baos.toByteArray();
|
||||||
oos.close();
|
oos.close();
|
||||||
baos.close();
|
baos.close();
|
||||||
@@ -69,27 +69,27 @@ public final class NoHashSphere {
|
|||||||
Files.write(file.toPath(), data, StandardOpenOption.CREATE);
|
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();
|
String hash = user.createHashString();
|
||||||
NoHashSphere.database.add(hash);
|
this.database.add(hash);
|
||||||
NoHashSphere.saveToFile();
|
this.saveToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void insertHash(String hash) throws IOException {
|
public synchronized void insertHash(String hash) throws IOException {
|
||||||
NoHashSphere.database.add(hash);
|
this.database.add(hash);
|
||||||
NoHashSphere.saveToFile();
|
this.saveToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void removeHash(String hash) throws IOException {
|
public synchronized void removeHash(String hash) throws IOException {
|
||||||
NoHashSphere.database.remove(hash);
|
this.database.remove(hash);
|
||||||
NoHashSphere.saveToFile();
|
this.saveToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized boolean checkHash(String hash) {
|
public synchronized boolean checkHash(String hash) {
|
||||||
return NoHashSphere.database.contains(hash);
|
return this.database.contains(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized int size() {
|
public synchronized int size() {
|
||||||
return NoHashSphere.database.size();
|
return this.database.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
15
src/nodash/core/spheres/NoHashSphereInterface.java
Normal file
15
src/nodash/core/spheres/NoHashSphereInterface.java
Normal file
@@ -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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user