package de.tud.kom.socom.components.game; import java.util.List; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONString; import de.tud.kom.socom.util.JSONUtils; import de.tud.kom.socom.util.LoggerFactory; /** * * @author rhaban * */ public class GameContext implements JSONString { // public access List<String> previous = null; List<String> next = null; String contextident; String name; String description; boolean autogenerated; public GameContext(String contextid) { this.contextident = contextid; this.autogenerated = false; } public GameContext(String contextident, String name, boolean autogenerated, List<String> pre, List<String> next) { this.previous = pre; this.next = next; this.name = name; this.contextident = contextident; this.autogenerated = autogenerated; } public GameContext(String contextident, String name, boolean autogenerated, List<String> pre, List<String> next, String description) { this.previous = pre; this.next = next; this.name = name; this.contextident = contextident; this.autogenerated = autogenerated; this.description = description; } public GameContext(String contextident, String name, boolean autogenerated, String description) { this.name = name; this.contextident = contextident; this.autogenerated = autogenerated; this.description = description; } public String getIdent() { return contextident; } public String getName() { return name; } public List<String> getPrevious() { return previous; } public void addPrevious(String id) { previous.add(id); } public List<String> getNext() { return next; } public void addNext(String id) { next.add(id); } @Override public String toJSONString() { JSONObject json = getJSONObject(); return JSONUtils.JSONToString(json); } public JSONObject getJSONObject() { JSONObject json = new JSONObject(); try { json.put("ident", contextident); json.put("name", name); if(description!=null) json.put("description", description); if (previous != null || next != null) { json.put("previous", previous); json.put("next", next); } json.put("autogenerated", autogenerated); } catch (JSONException e) { LoggerFactory.getLogger().equals(e); } return json; } }