This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Storage interface and LocalStorage object
- Loading branch information
1 parent
339f855
commit 682d7fa
Showing
7 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
application-main/src/main/java/com/zyneonstudios/application/utils/LocalStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.zyneonstudios.application.utils; | ||
|
||
import java.util.HashMap; | ||
import java.util.UUID; | ||
|
||
public class LocalStorage implements Storage { | ||
|
||
private final UUID uuid; | ||
private final HashMap<String, Object> map = new HashMap<>(); | ||
|
||
public LocalStorage(UUID uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public LocalStorage() { | ||
this.uuid = UUID.randomUUID(); | ||
} | ||
|
||
@Override | ||
public Object get(String path) { | ||
return map.get(path); | ||
} | ||
|
||
@Override @Deprecated | ||
public boolean getBool(String path) { | ||
return getBoolean(path); | ||
} | ||
|
||
@Override | ||
public Boolean getBoolean(String path) { | ||
return (Boolean)map.get(path); | ||
} | ||
|
||
@Override @Deprecated | ||
public double getDoub(String path) { | ||
return getDouble(path); | ||
} | ||
|
||
@Override | ||
public Double getDouble(String path) { | ||
return (Double)map.get(path); | ||
} | ||
|
||
@Override @Deprecated | ||
public int getInt(String path) { | ||
return getInteger(path); | ||
} | ||
|
||
@Override | ||
public Integer getInteger(String path) { | ||
return (Integer)map.get(path); | ||
} | ||
|
||
@Override | ||
public String getString(String path) { | ||
return map.get(path).toString(); | ||
} | ||
|
||
public UUID getUuid() { | ||
return uuid; | ||
} | ||
|
||
public String getId() { | ||
return uuid.toString(); | ||
} | ||
|
||
public void delete(String path) { | ||
map.remove(path); | ||
} | ||
|
||
public void clear() { | ||
map.clear(); | ||
} | ||
|
||
public void set(String path, Object value) { | ||
delete(path); | ||
map.put(path,value); | ||
} | ||
|
||
public void setBoolean(String path, boolean value) { | ||
set(path,value); | ||
} | ||
|
||
public void setDouble(String path, double value) { | ||
set(path,value); | ||
} | ||
|
||
public void setInteger(String path, int value) { | ||
set(path,value); | ||
} | ||
|
||
public void setString(String path, String value) { | ||
set(path,value); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
application-main/src/main/java/com/zyneonstudios/application/utils/Storage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.zyneonstudios.application.utils; | ||
|
||
public interface Storage { | ||
|
||
default Object get(String path) { | ||
return null; | ||
} | ||
|
||
default boolean getBool(String path) { | ||
return false; | ||
} | ||
|
||
default Boolean getBoolean(String path) { | ||
return null; | ||
} | ||
|
||
default double getDoub(String path) { | ||
return -1; | ||
} | ||
|
||
default Double getDouble(String path) { | ||
return null; | ||
} | ||
|
||
default int getInt(String path) { | ||
return -1; | ||
} | ||
|
||
default Integer getInteger(String path) { | ||
return null; | ||
} | ||
|
||
default String getString(String path) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters