diff --git a/Core/src/main/java/fr/altarik/toolbox/core/Registry.java b/Core/src/main/java/fr/altarik/toolbox/core/Registry.java new file mode 100644 index 0000000..85d37ac --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/Registry.java @@ -0,0 +1,51 @@ +package fr.altarik.toolbox.core; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Objects; + +public abstract class Registry { + + protected final HashMap registry = new HashMap<>(); + + /** + * Return a set view of the keys contained in the registry. + * @return An iterator view of the keys contained in the registry + */ + public Iterator keySet() { + return registry.keySet().iterator(); + } + + /** + * Returns true if this registry contains the key. + * @param key the key whose presence in the registry is to be tested + * @return Returns true if this registry contains the key, false otherwise + */ + public boolean containsKey(T key) { + return registry.containsKey(key); + } + + /** + * Returns the containing value represented by a specific key, or {@code null} if the registry do not contain the key + * @param key the key whose associated value is to be returned + * @return The value to which the specified key is represented, or {@code null} if the registry do not contain the key + */ + public @Nullable U getValue(T key) { + return registry.get(key); + } + + /** + * If the specified key is not already associated with a value, associate it with the given value. + * @param key Key to which the specified value is to be associated + * @param value value to be associated with the specified key + * @throws NullPointerException if key or value is null + */ + public void register(@NotNull T key, @NotNull U value) { + registry.putIfAbsent(Objects.requireNonNull(key), Objects.requireNonNull(value)); + } + +} + diff --git a/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java b/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java index aa9bcb9..2e625c5 100644 --- a/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java +++ b/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java @@ -1,8 +1,6 @@ package fr.altarik.toolbox.core.data; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; +import java.util.*; public class DataTracker { @@ -13,7 +11,13 @@ public class DataTracker { } public void startTracking(TrackedData data) { - trackedData.put(data, data.defaultValue()); + String v = trackedData.get(data); + if(v == null) { + trackedData.put(data, data.defaultValue()); + } else { + throw new IllegalArgumentException("Data " + data.name() + " has already been initialized"); + } + } public String getOrDefault(TrackedData data) { @@ -23,15 +27,18 @@ public class DataTracker { public void set(TrackedData data, String value) { String v = trackedData.get(data); if(v != null) { - trackedData.putIfAbsent(data, value); + trackedData.put(data, value); } else { throw new IllegalArgumentException("Data " + data.name() + " is not tracked, please initialize it with DataTracker#startTracking(TrackedData, String) first"); } } - public void saveToDb() { - + public Iterator getTrackedDataIterator() { + return trackedData.keySet().iterator(); } + public Iterator getTrackedDataValueIterator() { + return trackedData.values().iterator(); + } } diff --git a/Core/src/main/resources/fabric.mod.json b/Core/src/main/resources/fabric.mod.json index 65236f7..2701d84 100644 --- a/Core/src/main/resources/fabric.mod.json +++ b/Core/src/main/resources/fabric.mod.json @@ -2,8 +2,8 @@ "schemaVersion": 1, "id": "toolbox-core", "version": "${version}", - "name": "Core", - "description": "", + "name": "Altarik Toolbox Core", + "description": "Dependency of some of altarik toolbox mods", "authors": [ "Altarik" ], diff --git a/Database/src/main/resources/fabric.mod.json b/Database/src/main/resources/fabric.mod.json index 6f9451d..586895e 100644 --- a/Database/src/main/resources/fabric.mod.json +++ b/Database/src/main/resources/fabric.mod.json @@ -2,8 +2,8 @@ "schemaVersion": 1, "id": "toolbox-database", "version": "${version}", - "name": "Database", - "description": "", + "name": "Altarik Toolbox Database", + "description": "A set of sql tools", "authors": [ "Altarik" ], @@ -24,6 +24,7 @@ "fabricloader": "^0.14.12", "fabric-api": "*", "minecraft": "1.19.3", - "java": ">=17" + "java": ">=17", + "toolbox-core": "${version}" } } diff --git a/Pagination/src/main/resources/fabric.mod.json b/Pagination/src/main/resources/fabric.mod.json index 68cc742..99cc965 100644 --- a/Pagination/src/main/resources/fabric.mod.json +++ b/Pagination/src/main/resources/fabric.mod.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "id": "toolbox-pagination", "version": "${version}", - "name": "Pagination", + "name": "Altarik Toolbox Pagination", "description": "A mod to use to paginate long result to player in chat", "authors": [ "Altarik" diff --git a/Tasks/src/main/resources/fabric.mod.json b/Tasks/src/main/resources/fabric.mod.json index 217672b..853c737 100644 --- a/Tasks/src/main/resources/fabric.mod.json +++ b/Tasks/src/main/resources/fabric.mod.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "id": "toolbox-task", "version": "${version}", - "name": "Task", + "name": "Altarik Toolbox Task", "description": "A mod to use as a dependency for others to schedule tasks", "authors": [ "Altarik" diff --git a/gradle.properties b/gradle.properties index edaf432..9dcf69e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -org.gradle.jvmargs=-Xmx2G +org.gradle.jvmargs=-Xmx3G junit_version=5.9.0 @@ -8,5 +8,5 @@ loader_version=0.14.14 fabric_version=0.75.1+1.19.3 maven_group=fr.altarik.toolbox -maven_version=4.1.0-SNAPSHOT +maven_version=4.3.0-SNAPSHOT repo_username=Altarik