mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-24 09:06:39 +00:00
move registry api to new module
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
dependencies {
|
||||
"shadedApi"(project(":common:api:util"))
|
||||
"shadedApi"(project(":common:api:noise"))
|
||||
"shadedApi"(project(":common:api:registry"))
|
||||
|
||||
"shadedApi"("com.dfsek:Paralithic:0.5.0")
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.dfsek.terra.api.registry;
|
||||
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
|
||||
|
||||
public interface CheckedRegistry<T> extends Registry<T> {
|
||||
/**
|
||||
* Add a value to this registry, checking whether it is present first.
|
||||
*
|
||||
* @param identifier Identifier to assign value.
|
||||
* @param value Value to register.
|
||||
*
|
||||
* @throws DuplicateEntryException If an entry with the same identifier is already present.
|
||||
*/
|
||||
void register(String identifier, T value) throws DuplicateEntryException;
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.dfsek.terra.api.registry;
|
||||
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
|
||||
|
||||
public interface OpenRegistry<T> extends Registry<T> {
|
||||
/**
|
||||
* Add a value to this registry.
|
||||
*
|
||||
* @param identifier Identifier to assign value.
|
||||
* @param value Value to register.
|
||||
*/
|
||||
boolean register(String identifier, T value);
|
||||
|
||||
/**
|
||||
* Add a value to this registry, checking whether it is present first.
|
||||
*
|
||||
* @param identifier Identifier to assign value.
|
||||
* @param value Value to register.
|
||||
*
|
||||
* @throws DuplicateEntryException If an entry with the same identifier is already present.
|
||||
*/
|
||||
void registerChecked(String identifier, T value) throws DuplicateEntryException;
|
||||
|
||||
/**
|
||||
* Clears all entries from the registry.
|
||||
*/
|
||||
void clear();
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.dfsek.terra.api.registry;
|
||||
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
public interface Registry<T> extends TypeLoader<T> {
|
||||
/**
|
||||
* Get a value from the registry.
|
||||
*
|
||||
* @param identifier Identifier of value.
|
||||
*
|
||||
* @return Value matching the identifier, {@code null} if no value is present.
|
||||
*/
|
||||
T get(String identifier);
|
||||
|
||||
/**
|
||||
* Check if the registry contains a value.
|
||||
*
|
||||
* @param identifier Identifier of value.
|
||||
*
|
||||
* @return Whether the registry contains the value.
|
||||
*/
|
||||
boolean contains(String identifier);
|
||||
|
||||
/**
|
||||
* Perform the given action for every value in the registry.
|
||||
*
|
||||
* @param consumer Action to perform on value.
|
||||
*/
|
||||
void forEach(Consumer<T> consumer);
|
||||
|
||||
/**
|
||||
* Perform an action for every key-value pair in the registry.
|
||||
*
|
||||
* @param consumer Action to perform on pair.
|
||||
*/
|
||||
void forEach(BiConsumer<String, T> consumer);
|
||||
|
||||
/**
|
||||
* Get the entries of this registry as a {@link Set}.
|
||||
*
|
||||
* @return Set containing all entries.
|
||||
*/
|
||||
Collection<T> entries();
|
||||
|
||||
/**
|
||||
* Get all the keys in this registry.
|
||||
*
|
||||
* @return Keys in registry
|
||||
*/
|
||||
Set<String> keys();
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.dfsek.terra.api.registry.exception;
|
||||
|
||||
/**
|
||||
* Thrown when a duplicate entry is found in a registry.
|
||||
*/
|
||||
public class DuplicateEntryException extends RuntimeException {
|
||||
private static final long serialVersionUID = -7199021672428288780L;
|
||||
|
||||
public DuplicateEntryException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DuplicateEntryException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.dfsek.terra.api.registry.meta;
|
||||
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* Helpers to avoid creating entire registry implementations for simple overrides.
|
||||
*/
|
||||
public interface RegistryFactory {
|
||||
/**
|
||||
* Create a generic OpenRegistry.
|
||||
*
|
||||
* @param <T> Type of registry.
|
||||
*
|
||||
* @return New OpenRegistry
|
||||
*/
|
||||
<T> OpenRegistry<T> create();
|
||||
|
||||
/**
|
||||
* Create an OpenRegistry with custom {@link TypeLoader}
|
||||
*
|
||||
* @param loader Function to create loader.
|
||||
* @param <T> Type of registry.
|
||||
*
|
||||
* @return New OpenRegistry.
|
||||
*/
|
||||
<T> OpenRegistry<T> create(Function<OpenRegistry<T>, TypeLoader<T>> loader);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.dfsek.terra.api.registry.meta;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
|
||||
public interface RegistryHolder {
|
||||
default <T> Registry<T> getRegistry(Class<T> clazz) {
|
||||
return getRegistry((Type) clazz);
|
||||
}
|
||||
|
||||
default <T> Registry<T> getRegistry(TypeKey<T> type) {
|
||||
return getRegistry(type.getType());
|
||||
}
|
||||
|
||||
<T> Registry<T> getRegistry(Type type);
|
||||
|
||||
default <T> CheckedRegistry<T> getCheckedRegistry(Class<T> clazz) throws IllegalStateException {
|
||||
return getCheckedRegistry((Type) clazz);
|
||||
}
|
||||
|
||||
default <T> CheckedRegistry<T> getCheckedRegistry(TypeKey<T> type) throws IllegalStateException {
|
||||
return getCheckedRegistry(type.getType());
|
||||
}
|
||||
|
||||
default <T> CheckedRegistry<T> getCheckedRegistry(Type type) throws IllegalStateException {
|
||||
throw new IllegalStateException("Cannot get checked registry.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user