package projectzombie.util;

import java.util.ArrayList;

class NamedListObject<T> {
	String id;
	T object;
	
	public NamedListObject(String id, T object) {
		this.object = object;
		this.id = id;
	}
}

public class NamedList<T>
{
	private ArrayList<NamedListObject<T>> objects;
	
	public T get(String id)
	{
		for(NamedListObject<T> o : objects) {
			if(o.id.contentEquals(id)) {
				return o.object;
			}
		}
		
		return null;
	}
	
	public void set(String id, T object)
	{
		for(NamedListObject<T> o : objects) {
			if(o.id.contentEquals(id)) {
				o.object = object;
				return;
			}
		}
		
		objects.add(new NamedListObject<T>(id, object));
	}
	
	public T remove(String id)
	{
		for(int i=0;i<objects.size();i++) {
			NamedListObject<T> o = objects.get(i);
			if(o.id.contentEquals(id)) {
				objects.remove(i);
				return o.object;
			}
		}
		
		return null;
	}
}
