package io.domisum.lib.auxiliumlib.config;

import io.domisum.lib.auxiliumlib.annotations.API;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

@API
public class ConfigObjectRegistry<T extends ConfigObject>
{
	
	// REGISTRY
	private final Map<String, T> configObjects;
	
	
	// INIT
	ConfigObjectRegistry(Map<String, T> configObjectsById)
	{
		configObjects = Map.copyOf(configObjectsById);
	}
	
	
	// REGISTRY
	@API
	public T get(String id)
	{
		T configObject = configObjects.get(id);
		if(configObject == null)
			throw new IllegalArgumentException("this registry doesn't contain an entry for id '"+id+"'");
		return configObject;
	}
	
	@API
	public boolean contains(String id)
	{
		return configObjects.containsKey(id);
	}
	
	@API
	public Collection<T> getAll()
	{
		return new ArrayList<>(configObjects.values());
	}
	
}

@@ -167,16 +167,43 @@
 til.Map;
+%0Aimport java.util.Optional;
 %0A%0A@API%0Ap
@@ -688,32 +688,175 @@
 ect;%0A%09%7D%0A%09%0A%09@API%0A
+%09public Optional%3CT%3E getOptional(String id)%0A%09%7B%0A%09%09T configObject = configObjects.get(id);%0A%09%09return Optional.ofNullable(configObject);%0A%09%7D%0A%09%0A%09@API%0A
 %09public boolean 

Add ConfigObjectRegistry#getOptional