import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class YourServiceImpl extends RemoteServiceServlet implements
		YourService {

	private static List<YourDataObject> items;
	
	static {
		items = new ArrayList<YourDataObject>();
		YourDataObject item1 = new YourDataObject();
		item1.setId(1);
		item1.setName("Item 1");
		items.add(item1);		

		YourDataObject item2 = new YourDataObject();
		item2.setId(2);
		item2.setName("Item 2");
		items.add(item2);		
		
		YourDataObject item3 = new YourDataObject();
		item3.setId(3);
		item3.setName("Item 3");
		items.add(item3);		
	}
	
	@Override
	public YourDataObject add(YourDataObject data) {
		items.add(data);
		return data;
	}

	@Override
	public List<YourDataObject> fetch() {
		return items;
	}

	@Override
	public void remove(YourDataObject data) {
		items.remove(getById(data.getId()));
	}

	@Override
	public YourDataObject update(YourDataObject data) {
		items.remove(getById(data.getId()));
		items.add(data);
		return data;
	}
	
	private YourDataObject getById(int id) {
		for (YourDataObject item : items) {
			if (item.getId() == id) {
				return item;
			}
		}
		return null;
	}

}
