public JsonObject asJson() { JsonObject json = new JsonObject(); json.add("name", name); json.add("protocol", protocol); return json; }
public void afOutputConfiguration() { final JsonObject app = this.fetchConfigFor(this); final JsonObject config = new JsonObject(); config.add(this.afId(), app); System.out.println(config.toString(Stringify.HJSON)); }
/** * Sets the value of the member with the specified name to the JSON representation of the * specified <code>float</code> value. If this object does not contain a member with this name, a * new member is added at the end of the object. If this object contains multiple members with * this name, only the last one is changed. * <p> * This method should <strong>only be used to modify existing objects</strong>. To fill a new * object with members, the method <code>add(name, value)</code> should be preferred which is much * faster (as it does not need to search for existing members). * </p> * * @param name * the name of the member to add * @param value * the value of the member to add * @return the object itself, to enable method chaining */ public JsonObject set(String name, float value) { set(name, valueOf(value)); return this; }
/** * Appends a new member to the end of this object, with the specified name and the JSON * representation of the specified <code>float</code> value. * <p> * This method <strong>does not prevent duplicate names</strong>. Calling this method with a name * that already exists in the object will append another member with the same name. In order to * replace existing members, use the method <code>set(name, value)</code> instead. However, * <strong> <em>add</em> is much faster than <em>set</em></strong> (because it does not need to * search for existing members). Therefore <em>add</em> should be preferred when constructing new * objects. * </p> * * @param name * the name of the member to add * @param value * the value of the member to add * @return the object itself, to enable method chaining */ public JsonObject add(String name, float value) { add(name, valueOf(value)); return this; }
JsonValue fetchJson(final JsonValue json, final String path) { if (json instanceof JsonObject) { final JsonObject jo = (JsonObject) json; final int ix = path.indexOf("."); if (-1 == ix) { return jo.get(path); } else { final String hd = path.substring(0, ix); final String tl = path.substring(ix + 1); return this.fetchJson(jo.get(hd), tl); } } else { return null; } }
/** * Returns an unmodifiable JsonObject for the specified one. This method allows to provide * read-only access to a JsonObject. * <p> * The returned JsonObject is backed by the given object and reflect changes that happen to it. * Attempts to modify the returned JsonObject result in an * <code>UnsupportedOperationException</code>. * </p> * * @param object * the JsonObject for which an unmodifiable JsonObject is to be returned * @return an unmodifiable view of the specified JsonObject */ public static JsonObject unmodifiableObject(JsonObject object) { return new JsonObject(object, true); }
/** * Returns the value of the member with the specified name in this object. If this object contains * multiple members with the given name, this method will return the last one. * * @param name * the name of the member whose value is to be returned * @return the value of the last member with the specified name, or <code>null</code> if this * object does not contain a member with that name */ public JsonValue get(String name) { if (name==null) { throw new NullPointerException("name is null"); } int index=indexOf(name); return index!=-1 ? values.get(index) : null; }
private synchronized void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException { inputStream.defaultReadObject(); table=new HashIndexTable(); updateHashIndex(); }
/** * Appends a new member to the end of this object, with the specified name and the JSON * representation of the specified <code>int</code> value. * <p> * This method <strong>does not prevent duplicate names</strong>. Calling this method with a name * that already exists in the object will append another member with the same name. In order to * replace existing members, use the method <code>set(name, value)</code> instead. However, * <strong> <em>add</em> is much faster than <em>set</em></strong> (because it does not need to * search for existing members). Therefore <em>add</em> should be preferred when constructing new * objects. * </p> * * @param name * the name of the member to add * @param value * the value of the member to add * @return the object itself, to enable method chaining */ public JsonObject add(String name, int value) { add(name, valueOf(value)); return this; }
/** * Returns the <code>String</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one is picked. If this * member's value does not represent a JSON string, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public String getString(String name, String defaultValue) { JsonValue value=get(name); return value!=null ? value.asString() : defaultValue; }
/** * Sets the value of the member with the specified name to the JSON representation of the * specified <code>double</code> value. If this object does not contain a member with this name, a * new member is added at the end of the object. If this object contains multiple members with * this name, only the last one is changed. * <p> * This method should <strong>only be used to modify existing objects</strong>. To fill a new * object with members, the method <code>add(name, value)</code> should be preferred which is much * faster (as it does not need to search for existing members). * </p> * * @param name * the name of the member to add * @param value * the value of the member to add * @return the object itself, to enable method chaining */ public JsonObject set(String name, double value) { set(name, valueOf(value)); return this; }
/** * Returns an unmodifiable JsonObject for the specified one. This method allows to provide * read-only access to a JsonObject. * <p> * The returned JsonObject is backed by the given object and reflect changes that happen to it. * Attempts to modify the returned JsonObject result in an * <code>UnsupportedOperationException</code>. * </p> * * @param object * the JsonObject for which an unmodifiable JsonObject is to be returned * @return an unmodifiable view of the specified JsonObject */ public static JsonObject unmodifiableObject(JsonObject object) { return new JsonObject(object, true); }
/** * Returns the value of the member with the specified name in this object. If this object contains * multiple members with the given name, this method will return the last one. * * @param name * the name of the member whose value is to be returned * @return the value of the last member with the specified name, or <code>null</code> if this * object does not contain a member with that name */ public JsonValue get(String name) { if (name==null) { throw new NullPointerException("name is null"); } int index=indexOf(name); return index!=-1 ? values.get(index) : null; }
private JsonObject(JsonObject object, boolean unmodifiable) { if (object==null) throw new NullPointerException("object is null"); if (unmodifiable) { names=Collections.unmodifiableList(object.names); values=Collections.unmodifiableList(object.values); } else { names=new ArrayList<String>(object.names); values=new ArrayList<JsonValue>(object.values); } table=new HashIndexTable(); updateHashIndex(); }
public JsonObject asJson() { JsonObject json = new JsonObject(); json.add("name", name); json.add("id", uuid.toString()); return json; }
/** * Appends a new member to the end of this object, with the specified name and the JSON * representation of the specified string. * <p> * This method <strong>does not prevent duplicate names</strong>. Calling this method with a name * that already exists in the object will append another member with the same name. In order to * replace existing members, use the method <code>set(name, value)</code> instead. However, * <strong> <em>add</em> is much faster than <em>set</em></strong> (because it does not need to * search for existing members). Therefore <em>add</em> should be preferred when constructing new * objects. * </p> * * @param name * the name of the member to add * @param value * the value of the member to add * @return the object itself, to enable method chaining */ public JsonObject add(String name, String value) { add(name, valueOf(value)); return this; }
public void afOutputConfiguration() { JsonObject app = this.fetchConfigFor(this); JsonObject config = new JsonObject(); config.add(this.afId(), app); System.out.println(config.toString(Stringify.HJSON)); }