package speiger.src.coreengine.utils.collections.registries.simple;

import speiger.src.coreengine.assets.AssetLocation;

public class SimpleRegistryWithDefault<T extends IRegistryEntry<T>> extends SimpleRegistry<T> {
	AssetLocation defaultKey;
	T defaultValue;
	
	public SimpleRegistryWithDefault(int capacity, AssetLocation defaultValue) {
		super(capacity);
		this.defaultKey = defaultValue;
	}
	
	@Override
	public T register(T value) {
		T result = super.register(value);
		if(defaultKey != null && result.getName().matches(defaultKey)) { defaultValue = result; }
		return result;
	}
	
	@Override
	public T getValue(AssetLocation name) {
		T value = super.getValue(name);
		return value == null ? defaultValue : value;
	}
}
