package speiger.src.coreengine.utils.io.settings;

import java.util.List;
import java.util.function.Consumer;

import speiger.src.collections.objects.lists.ObjectArrayList;

public abstract class BaseSetting<T extends ISetting<T>> implements ISetting<T>
{
	protected final String id;
	List<Consumer<T>> listeners = new ObjectArrayList<Consumer<T>>();
	
	public BaseSetting(String id)
	{
		this.id = id;
	}

	@Override
	public T addListener(Consumer<T> listener)
	{
		listeners.add(listener);
		return (T)this;
	}
	
	protected void notifyListeners()
	{
		if(listeners.isEmpty())
		{
			return;
		}
		T value = (T)this;
		for(int i = 0,m=listeners.size();i<m;i++)
		{
			listeners.get(i).accept(value);
		}
	}
}
