package speiger.src.coreengine.rendering.shader.uniform;

import java.util.Objects;

import speiger.src.collections.objects.maps.interfaces.Object2ObjectMap;

public class GlobalUniforms {
	private Object2ObjectMap<String, IUniform> uniforms = Object2ObjectMap.builder().map();
	
	public <T extends IUniform> T register(String uniformId, T uniform) {
		uniforms.putIfAbsent(Objects.requireNonNull(uniformId), Objects.requireNonNull(uniform));
		return uniform;
	}
	
	public boolean contains(String name) {
		return uniforms.containsKey(name);
	}
	
	@SuppressWarnings("unchecked")
	public <T extends IUniform> T get(String name) {
		return (T)uniforms.get(name);
	}
	
	@SuppressWarnings("unchecked")
	public <T extends IUniform> T getOrDefault(String name, T defaultValue) {
		return (T)uniforms.getOrDefault(name, defaultValue);
	}
	
	public Object2ObjectMap<String, IUniform> getAll() {
		return uniforms.unmodifiable();
	}
}