Code example for TreeMap

Methods: get, remove

0
		throw new RuntimeException(className + " is not a supported class.");
	} 
	 
	@SuppressWarnings("unchecked") 
	private TreeMap<Long, AbstractModelObject> getTypeMap(String className) {
		TreeMap<Long, AbstractModelObject> resultMap = (TreeMap<Long, AbstractModelObject>) dataStore.get(className);
		return resultMap;
	} 
	 
	TreeMap<String, TreeMap<Long, ? extends AbstractModelObject>> dataStore = new TreeMap<String, TreeMap<Long, ? extends AbstractModelObject>>(); {
		dataStore.put(Area.class.getName(), areas);
		dataStore.put(Project.class.getName(), projects);
		dataStore.put(ContextOrLocation.class.getName(), contexts);
		dataStore.put(Task.class.getName(), tasks);
		dataStore.put(Reminder.class.getName(), reminders);
	} 
 
	// ------------------------------------------------------------------------------------------------------- 
	 
	private static class Insert implements TransactionWithQuery { 
		private static final long serialVersionUID = 1L;
		private String className;
 
		public Insert(String className) {
			this.className = className;
		} 
 
		@Override 
		public Object executeAndQuery(Object prevalentSystem, Date executionTime)
				throws Exception { 
			PrevaylerDatabase dao = (PrevaylerDatabase) prevalentSystem;
			Class<?> intoClass = dao.getClass(className);
			AbstractModelObject result = null;
			try { 
				result = (AbstractModelObject) intoClass.newInstance();
				long resultID = dao.nextID.getNextValue();
				result.setId(resultID);
				TreeMap<Long, AbstractModelObject> resultMap = dao.getTypeMap(className);
				resultMap.put(resultID, result);
			} catch (IllegalAccessException e) {
				throw new RuntimeException(e);
			} catch (InstantiationException e) {
				throw new RuntimeException(e);
			} 
			return result;
		} 
	} 
	 
	/* (non-Javadoc) 
	 * @see es.strid.model.dao.IDatabase#insert(java.lang.String) 
	 */ 
	public AbstractModelObject insert(String className) {
		TransactionWithQuery insertCommand = new Insert(className);
		try { 
			return (AbstractModelObject) prevayler.execute(insertCommand);
		} catch (Exception e) {
			throw new RuntimeException(e);
		} 
	} 
 
	private static class Delete implements Transaction { 
		private static final long serialVersionUID = 1L;
		private String className;
		private Long id;
 
		public Delete(String className, Long id) {
			this.className = className;
			this.id = id;
		} 
 
		@Override 
		public void executeOn(Object prevalentSystem, Date executionTime) {
			PrevaylerDatabase dao = (PrevaylerDatabase) prevalentSystem;
			TreeMap<Long, AbstractModelObject> collection = dao.getTypeMap(className);
			AbstractModelObject removedObject = collection.remove(id);
			if (removedObject == null) {
				throw new RuntimeException(className + ", ID=" + id + " does not exist");
			} 
		} 
	}