List of usage examples for com.google.gson JsonPrimitive JsonPrimitive
public JsonPrimitive(Character c)
From source file:Change.java
License:Open Source License
@Override public void completed(boolean success) { if (success) { Logger.getLogger(Change.class.getName()).log(Level.INFO, "Change Connection completed!"); JsonPrimitive value = new JsonPrimitive(42); peer.addState(state, value, this, 1000, this, 5000); } else {/*from w ww . ja v a 2s . c o m*/ Logger.getLogger(Change.class.getName()).log(Level.SEVERE, "Connection failed!"); } }
From source file:Change.java
License:Open Source License
@Override public void onResponse(boolean completed, JsonObject response) { Logger.getLogger(Change.class.getName()).log(Level.INFO, "completed: {0} response: {1}", new Object[] { completed, response }); int initialValue = 55; ChangeResponder changeResponder = new ChangeResponder(peer, state, initialValue); JsonPrimitive counter = new JsonPrimitive(initialValue); peer.change(state, counter, changeResponder, 5000); }
From source file:Change.java
License:Open Source License
@Override public JsonElement onStateSet(String path, JsonElement value) throws JsonRpcException { try {//from w w w. j a v a 2 s .c o m int newValue = value.getAsInt(); if (newValue % 10 != 0) { newValue = ((newValue + 5) / 10) * 10; return new JsonPrimitive(newValue); } else { return null; } } catch (ClassCastException | IllegalStateException e) { throw new JsonRpcException(JsonRpcException.INVALID_PARAMS, e.getMessage()); } }
From source file:Change.java
License:Open Source License
@Override public void onResponse(boolean completed, JsonObject response) { try {/*from w w w . ja va 2 s. com*/ Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(ChangeResponder.class.getName()).log(Level.SEVERE, null, ex); } counter++; if (counter < initialValue + 10) { JsonPrimitive jsonCounter = new JsonPrimitive(counter); peer.change(state, jsonCounter, this, 5000); } else { this.peer.removeState(state, null, 5000); } }
From source file:AddState.java
License:Open Source License
@Override public JsonElement onStateSet(String path, JsonElement value) throws JsonRpcException { try {//from ww w . j av a 2 s . c o m int newValue = value.getAsInt(); if (newValue % 10 != 0) { newValue = ((newValue + 5) / 10) * 10; Logger.getLogger(AddState.class.getName()).log(Level.INFO, "setting state to: {0}", new Object[] { newValue }); return new JsonPrimitive(newValue); } else { return null; } } catch (ClassCastException | IllegalStateException e) { throw new JsonRpcException(JsonRpcException.INVALID_PARAMS, e.getMessage()); } }
From source file:AddState.java
License:Open Source License
@Override public void onResponse(boolean completed, JsonObject response) { if (completed) { Logger.getLogger(AddState.class.getName()).log(Level.INFO, "Authentication completed!"); StateHandler stateHandler = new StateHandler(); JsonPrimitive value = new JsonPrimitive(42); String[] fetchGroups = new String[] { "admin", "public" }; //String[] fetchGroups = new String[] {"public", "users", "john"}; String[] setGroups = new String[] { "admin", "bob" }; peer.addState("theState", value, setGroups, fetchGroups, stateHandler, 1000, stateHandler, 5000); } else {// www .j a va 2 s . c o m Logger.getLogger(AddState.class.getName()).log(Level.SEVERE, "Authentication failed!"); } }
From source file:RunnerRepository.java
License:Apache License
public static void addLook(String[] look) { getLooks().add(look[0], new JsonPrimitive(look[1])); writeJSon(); }
From source file:RunnerRepository.java
License:Apache License
public static void addEditor(String[] editor) { getEditors().add(editor[0], new JsonPrimitive(editor[1])); writeJSon(); }
From source file:RunnerRepository.java
License:Apache License
public static void addPlugin(String pluginfilename) { if (getPlugins().isJsonArray()) { getPlugins().getAsJsonArray().add(new JsonPrimitive(pluginfilename)); } else {/*from ww w . j a va2 s . c om*/ JsonPrimitive primitive = new JsonPrimitive(pluginfilename); JsonArray array = new JsonArray(); array.add(primitive); inifile.add("plugins", array); } writeJSon(); }
From source file:RunnerRepository.java
License:Apache License
public static void saveMainLayout() { JsonObject lay = getLayouts();// w w w.j av a 2 s . c o m lay.add("mainsize", new JsonPrimitive(window.getSize().getWidth() + " " + window.getSize().getHeight())); lay.add("mainlocation", new JsonPrimitive(window.getLocation().getX() + " " + window.getLocation().getY())); lay.add("mainvsplitlocation", new JsonPrimitive(window.mainpanel.p1.splitPane.getDividerLocation())); lay.add("mainh1splitlocation", new JsonPrimitive(window.mainpanel.p1.splitPane3.getDividerLocation())); lay.add("mainh2splitlocation", new JsonPrimitive(window.mainpanel.p1.splitPane2.getDividerLocation())); writeJSon(); }