Package de.marhali.json5
Class Json5Object
- java.lang.Object
-
- de.marhali.json5.Json5Element
-
- de.marhali.json5.Json5Object
-
public final class Json5Object extends Json5Element
A class representing an object type in Json5. An object consists of name-value pairs where names are strings, and values are any other type ofJson5Element. This allows for a creating a tree of Json5Elements. The member elements of this object are maintained in order they were added. This class does not supportnullvalues. Ifnullis provided as value argument to any of the methods, it is converted to aJson5Null.Json5Objectdoes not implement theMapinterface, but aMapview of it can be obtained withasMap().See the
Json5documentation for details on how to convertJson5Objectand generally anyJson5Elementfrom and to Json5.
-
-
Field Summary
-
Fields inherited from class de.marhali.json5.Json5Element
comment
-
-
Constructor Summary
Constructors Constructor Description Json5Object()Creates a new instance of aJson5Object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.String property, Json5Element value)Adds a member, which is a name-value pair, to self.voidaddProperty(java.lang.String property, java.lang.Boolean value)Convenience method to add a boolean member.voidaddProperty(java.lang.String property, java.lang.Character value)Convenience method to add a char member.voidaddProperty(java.lang.String property, java.lang.Number value)Convenience method to add a number member.voidaddProperty(java.lang.String property, java.lang.Number value, int radix)voidaddProperty(java.lang.String property, java.lang.String value)Convenience method to add a string member.voidaddProperty(java.lang.String property, java.time.Instant value)Convenience method to add aInstantmember.java.util.Map<java.lang.String,Json5Element>asMap()Returns a mutableMapview of thisJson5Object.Json5ObjectdeepCopy()Creates a deep copy of this element and all its children.java.util.Set<java.util.Map.Entry<java.lang.String,Json5Element>>entrySet()Returns a set of members of this object.booleanequals(java.lang.Object o)Json5Elementget(java.lang.String memberName)Returns the member with the specified name.Json5ArraygetAsJson5Array(java.lang.String memberName)Convenience method to get the specified member as aJson5Array.Json5ObjectgetAsJson5Object(java.lang.String memberName)Convenience method to get the specified member as aJson5Object.Json5PrimitivegetAsJson5Primitive(java.lang.String memberName)Convenience method to get the specified member as aJson5Primitive.booleanhas(java.lang.String memberName)Convenience method to check if a member with the specified name is present in this object.inthashCode()booleanisEmpty()Returns true if the number of key/value pairs in the object is zero.java.util.Set<java.lang.String>keySet()Returns a set of members key values.Json5Elementremove(java.lang.String property)Removes thepropertyfrom this object.intsize()Returns the number of key/value pairs in the object.-
Methods inherited from class de.marhali.json5.Json5Element
getAsBigDecimal, getAsBigInteger, getAsBinaryString, getAsBoolean, getAsByte, getAsDouble, getAsFloat, getAsHexString, getAsInstant, getAsInt, getAsJson5Array, getAsJson5Null, getAsJson5Object, getAsJson5Primitive, getAsLong, getAsNumber, getAsOctalString, getAsRadixNumber, getAsShort, getAsString, getComment, hasComment, isJson5Array, isJson5Null, isJson5Object, isJson5Primitive, setComment, toString, toString
-
-
-
-
Constructor Detail
-
Json5Object
public Json5Object()
Creates a new instance of aJson5Object.
-
-
Method Detail
-
deepCopy
public Json5Object deepCopy()
Creates a deep copy of this element and all its children.- Specified by:
deepCopyin classJson5Element- Returns:
- Deep copy
-
add
public void add(java.lang.String property, Json5Element value)Adds a member, which is a name-value pair, to self. The name must be a String, but the value can be an arbitraryJson5Element, thereby allowing you to build a full tree ofJson5Elementsrooted at this node.- Parameters:
property- name of the member.value- the member object.
-
remove
public Json5Element remove(java.lang.String property)
Removes thepropertyfrom this object.- Parameters:
property- name of the member that should be removed.- Returns:
- the
Json5Elementobject that is being removed, ornullif no member with this name exists.
-
addProperty
public void addProperty(java.lang.String property, java.lang.Character value)Convenience method to add a char member. The specified value is converted to aJson5Primitiveof Character.- Parameters:
property- name of the member.value- the char value associated with the member.
-
addProperty
public void addProperty(java.lang.String property, java.lang.String value)Convenience method to add a string member. The specified value is converted to aJson5Primitiveof String.- Parameters:
property- name of the member.value- the string value associated with the member.
-
addProperty
public void addProperty(java.lang.String property, java.lang.Number value)Convenience method to add a number member. The specified value is converted to aJson5Primitiveof Number.- Parameters:
property- name of the member.value- the number value associated with the member.
-
addProperty
public void addProperty(java.lang.String property, java.lang.Number value, int radix)
-
addProperty
public void addProperty(java.lang.String property, java.time.Instant value)Convenience method to add aInstantmember. The specified value is converted to aJson5PrimitiveofInstant.- Parameters:
property- name of the member.value- theInstantvalue associated with the member.
-
addProperty
public void addProperty(java.lang.String property, java.lang.Boolean value)Convenience method to add a boolean member. The specified value is converted to aJson5Primitiveof Boolean.- Parameters:
property- name of the member.value- the boolean value associated with the member.
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.String,Json5Element>> entrySet()
Returns a set of members of this object. The set is ordered, and the order is in which the elements were added.- Returns:
- a set of members of this object.
-
keySet
public java.util.Set<java.lang.String> keySet()
Returns a set of members key values.- Returns:
- a set of member keys as Strings
-
size
public int size()
Returns the number of key/value pairs in the object.- Returns:
- the number of key/value pairs in the object.
-
isEmpty
public boolean isEmpty()
Returns true if the number of key/value pairs in the object is zero.- Returns:
- true if the number of key/value pairs in the object is zero.
-
has
public boolean has(java.lang.String memberName)
Convenience method to check if a member with the specified name is present in this object.- Parameters:
memberName- name of the member that is being checked for presence.- Returns:
- true if there is a member with the specified name, false otherwise.
-
get
public Json5Element get(java.lang.String memberName)
Returns the member with the specified name.- Parameters:
memberName- name of the member that is being requested.- Returns:
- the member matching the name, or
nullif no such member exists.
-
getAsJson5Primitive
public Json5Primitive getAsJson5Primitive(java.lang.String memberName)
Convenience method to get the specified member as aJson5Primitive.- Parameters:
memberName- name of the member being requested.- Returns:
- the
Json5Primitivecorresponding to the specified member, ornullif no member with this name exists. - Throws:
java.lang.ClassCastException- if the member is not of typeJson5Primitive.
-
getAsJson5Array
public Json5Array getAsJson5Array(java.lang.String memberName)
Convenience method to get the specified member as aJson5Array.- Parameters:
memberName- name of the member being requested.- Returns:
- the
Json5Arraycorresponding to the specified member, ornullif no member with this name exists. - Throws:
java.lang.ClassCastException- if the member is not of typeJson5Array.
-
getAsJson5Object
public Json5Object getAsJson5Object(java.lang.String memberName)
Convenience method to get the specified member as aJson5Object.- Parameters:
memberName- name of the member being requested.- Returns:
- the
Json5Objectcorresponding to the specified member, ornullif no member with this name exists. - Throws:
java.lang.ClassCastException- if the member is not of typeJson5Object.
-
asMap
public java.util.Map<java.lang.String,Json5Element> asMap()
Returns a mutableMapview of thisJson5Object. Changes to theMapare visible in thisJson5Objectand the other way around.The
Mapdoes not permitnullkeys or values. UnlikeJson5Object'snullhandling, aNullPointerExceptionis thrown when trying to addnull. UseJson5Nullfor Json5 null values.- Returns:
- mutable
Mapview
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classJson5Element
-
hashCode
public int hashCode()
- Overrides:
hashCodein classJson5Element
-
-