move registry api to new module

This commit is contained in:
dfsek
2021-11-09 23:49:49 -07:00
parent 614431af2f
commit 9715171aba
11 changed files with 10 additions and 5 deletions

View File

@@ -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")

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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.");
}
}