remove RegistryFactory

This commit is contained in:
dfsek
2021-12-16 22:14:23 -07:00
parent fb1b440e72
commit 1852d9103f
3 changed files with 0 additions and 89 deletions

View File

@@ -15,7 +15,6 @@ import java.util.Map;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.meta.RegistryFactory;
import com.dfsek.terra.api.registry.meta.RegistryHolder;
import com.dfsek.terra.api.tectonic.LoaderHolder;
import com.dfsek.terra.api.tectonic.LoaderRegistrar;

View File

@@ -1,39 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.registry.meta;
import com.dfsek.tectonic.api.loader.type.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,49 +0,0 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.registry;
import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.tectonic.api.loader.ConfigLoader;
import com.dfsek.tectonic.api.loader.type.TypeLoader;
import java.lang.reflect.AnnotatedType;
import java.util.function.Function;
import com.dfsek.terra.api.registry.OpenRegistry;
import com.dfsek.terra.api.registry.meta.RegistryFactory;
import com.dfsek.terra.api.util.generic.Lazy;
public class RegistryFactoryImpl implements RegistryFactory {
@Override
public <T> OpenRegistry<T> create() {
return new OpenRegistryImpl<>();
}
@Override
public <T> OpenRegistry<T> create(Function<OpenRegistry<T>, TypeLoader<T>> loader) {
return new OpenRegistryImpl<>() {
private final Lazy<TypeLoader<T>> loaderCache = Lazy.lazy(() -> loader.apply(this));
@Override
public T load(AnnotatedType type, Object o, ConfigLoader configLoader) throws LoadException {
return loaderCache.value().load(type, o, configLoader);
}
};
}
}