mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-08-29 13:20:32 +00:00
create simple property API
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
package com.dfsek.terra.api.properties;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Context {
|
||||||
|
private final Map<Class<? extends Properties>, Properties> map = new HashMap<>();
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends Properties> T get(Class<T> clazz) {
|
||||||
|
return (T) map.computeIfAbsent(clazz, k -> {
|
||||||
|
throw new IllegalArgumentException("No properties registered for class " + clazz.getCanonicalName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Context put(Properties properties) {
|
||||||
|
if(map.containsKey(properties.getClass())) throw new IllegalArgumentException("Property for class " + properties.getClass().getCanonicalName() + " already registered.");
|
||||||
|
map.put(properties.getClass(), properties);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.dfsek.terra.api.properties;
|
||||||
|
|
||||||
|
public interface Properties {
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.dfsek.terra.api.properties;
|
||||||
|
|
||||||
|
public interface PropertyHolder {
|
||||||
|
Context getContext();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user