Add DataTracker and TrackedData
All checks were successful
/ build (17, ubuntu-latest) (pull_request) Successful in 4m49s
All checks were successful
/ build (17, ubuntu-latest) (pull_request) Successful in 4m49s
This commit is contained in:
parent
ee67f7e075
commit
c976468d2b
@ -32,7 +32,7 @@ jobs:
|
||||
if: ${{ runner.os != 'Windows' }}
|
||||
run: chmod +x ./gradlew
|
||||
- name: build
|
||||
run: ./gradlew build --no-daemon
|
||||
run: ./gradlew build --no-daemon --max-workers 1
|
||||
#- name: test
|
||||
# run: ./gradlew test --no-daemon
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
package fr.altarik.toolbox.core.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DataTracker {
|
||||
|
||||
private final Map<TrackedData, String> trackedData;
|
||||
|
||||
public DataTracker() {
|
||||
this.trackedData = new HashMap<>();
|
||||
}
|
||||
|
||||
public void startTracking(TrackedData data) {
|
||||
trackedData.put(data, data.defaultValue());
|
||||
}
|
||||
|
||||
public String getOrDefault(TrackedData data) {
|
||||
return Objects.requireNonNull(trackedData.get(data));
|
||||
}
|
||||
|
||||
public void set(TrackedData data, String value) {
|
||||
String v = trackedData.get(data);
|
||||
if(v != null) {
|
||||
trackedData.putIfAbsent(data, value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Data " + data.name() + " is not tracked, please initialize it with DataTracker#startTracking(TrackedData, String) first");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void saveToDb() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package fr.altarik.toolbox.core.data;
|
||||
|
||||
public record TrackedData(String name, String defaultValue) {
|
||||
|
||||
}
|
@ -8,6 +8,6 @@ loader_version=0.14.14
|
||||
fabric_version=0.75.1+1.19.3
|
||||
|
||||
maven_group=fr.altarik.toolbox
|
||||
maven_version=4.0.0-SNAPSHOT
|
||||
maven_version=4.1.0-SNAPSHOT
|
||||
repo_username=Altarik
|
||||
repo_password=password
|
||||
|
@ -10,4 +10,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
rootProject.name = 'Toolbox'
|
||||
include(':Tasks', ':Database', ':Pagination', ':Core')
|
||||
include(':Tasks')
|
||||
include(':Database')
|
||||
include(':Pagination')
|
||||
include(':Core')
|
||||
|
Loading…
Reference in New Issue
Block a user