package org.minimalj.frontend.impl.json;

import java.util.Collections;
import java.util.List;
import java.util.Map;

public class JsonInput {

	public static final String SHOW_DEFAULT_PAGE = "showDefaultPage";
	public static final String CHANGED_VALUE = "changedValue";
	public static final String ACTIVATED_ACTION = "activatedAction";
	public static final String TABLE_ACTION = "tableAction";
	public static final String CLOSE_DIALOG = "closeDialog";
	
	private final Map<String, Object> input;

	public JsonInput(String json) {
		this((Map<String, Object>) new JsonReader().read(json));
	}
	
	public JsonInput(Map<String, Object> input) {
		this.input = input;
	}
	
	public Map<String, Object> get(String name) {
		return get(input, name);
	}

	public List<Object> getList(String name) {
		return getList(input, name);
	}

	public Object getObject(String name) {
		return input.get(name);
	}
	
	public boolean containsObject(String name) {
		return input.containsKey(name);
	}

	public static Map<String, Object> get(Map<String, Object> object, String name) {
		if (!object.containsKey(name)) {
			return Collections.emptyMap();
		} else {
			return (Map<String, Object>) object.get(name);
		}
	}
	
	public static List<Object> getList(Map<String, Object> object, String name) {
		if (!object.containsKey(name)) {
			return Collections.emptyList();
		} else {
			return (List<Object>) object.get(name);
		}
	}

}

@@ -69,31 +69,8 @@
 ns;%0A
-import java.util.List;%0A
 impo
@@ -87,16 +87,16 @@
 il.Map;%0A
+
 %0Apublic 
@@ -721,87 +721,8 @@
 %09%7D%0A%0A
-%09public List%3CObject%3E getList(String name) %7B%0A%09%09return getList(input, name);%0A%09%7D%0A%0A
 %09pub
@@ -1026,32 +1026,32 @@
 p();%0A%09%09%7D else %7B%0A
+
 %09%09%09return (Map%3CS
@@ -1094,220 +1094,8 @@
 %7D%0A%09%7D
-%0A%09%0A%09public static List%3CObject%3E getList(Map%3CString, Object%3E object, String name) %7B%0A%09%09if (!object.containsKey(name)) %7B%0A%09%09%09return Collections.emptyList();%0A%09%09%7D else %7B%0A%09%09%09return (List%3CObject%3E) object.get(name);%0A%09%09%7D%0A%09%7D
 %0A%0A%7D%0A

remove getList (not used)