java.lang.Object
de.monticore.symboltable.serialization.json.JsonObject
All Implemented Interfaces:
JsonElement
Direct Known Subclasses:
TraceableJsonObject

public class JsonObject extends Object implements JsonElement
Json Objects contain members in form of name-value pairs. The name is a (unique) String, and the value any JsonElement.
  • Field Details

  • Constructor Details

    • JsonObject

      public JsonObject()
  • Method Details

    • isJsonObject

      public boolean isJsonObject()
      As this is a Json object, return true
      Specified by:
      isJsonObject in interface JsonElement
      Returns:
    • getAsJsonObject

      public JsonObject getAsJsonObject()
      As this is a Json object, return "this"
      Specified by:
      getAsJsonObject in interface JsonElement
      Returns:
    • getMembers

      public Map<String,JsonElement> getMembers()
      A map with all members of this object
      Returns:
      attributes
    • setMembers

      public void setMembers(Map<String,JsonElement> members)
      Parameters:
      members - the attributes to set
    • sizeMembers

      public int sizeMembers()
      Returns:
      See Also:
    • hasMembers

      public boolean hasMembers()
      Returns:
      See Also:
    • hasMember

      public boolean hasMember(String name)
      Parameters:
      name -
      Returns:
      See Also:
    • getMember

      public JsonElement getMember(String name)
      Parameters:
      name -
      Returns:
      See Also:
    • putMember

      public JsonElement putMember(String name, JsonElement value)
      Parameters:
      name -
      value -
      Returns:
      See Also:
    • removeMember

      public JsonElement removeMember(String name)
      Parameters:
      name -
      Returns:
      See Also:
    • getMemberNames

      public Set<String> getMemberNames()
      Returns:
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • hasStringMember

      public boolean hasStringMember(String name)
      Checks whether there exists a member with the corresponding name and checks whether it is of type String.
      Parameters:
      name - The name of the possible JSON element
      Returns:
      true if the correctly typed member available, false otherwise
    • getStringMember

      public String getStringMember(String name)
      This method returns the value of a String member of this object, if it exists, Otherwise, raises an error and returns null.
      Parameters:
      name -
      Returns:
    • getStringMemberOpt

      public Optional<String> getStringMemberOpt(String name)
      This method returns an Optional of a String member of this object, if it exists, Otherwise, returns an empty optional.
      Parameters:
      name -
      Returns:
    • hasArrayMember

      public boolean hasArrayMember(String name)
      Checks whether there exists a member with the corresponding name and checks whether it is of type JSON-Array.
      Parameters:
      name - The name of the possible JSON element
      Returns:
      true if the correctly typed member available, false otherwise
    • getArrayMember

      public List<JsonElement> getArrayMember(String name)
      This method returns the value of an Array member of this object, if it exists, Otherwise, raises an error and returns null.
      Parameters:
      name -
      Returns:
    • getArrayMemberOpt

      public Optional<List<JsonElement>> getArrayMemberOpt(String name)
      This method returns an Optional of an Array member of this object, if it exists, Otherwise, returns an empty optional.
      Parameters:
      name -
      Returns:
    • hasBooleanMember

      public boolean hasBooleanMember(String name)
      Checks whether there exists a member with the corresponding name and checks whether it is of type JSON-Boolean.
      Parameters:
      name - The name of the possible JSON element
      Returns:
      true if the correctly typed member available, false otherwise
    • getBooleanMember

      public boolean getBooleanMember(String name)
      This method returns the value of a Boolean member of this object, if it exists, Otherwise, raises an error and returns null.
      Parameters:
      name -
      Returns:
    • getBooleanMemberOpt

      public Optional<Boolean> getBooleanMemberOpt(String name)
      This method returns an Optional of a Boolean member of this object, if it exists, Otherwise, returns an empty optional.
      Parameters:
      name -
      Returns:
    • hasObjectMember

      public boolean hasObjectMember(String name)
      Checks whether there exists a member with the corresponding name and checks whether it is of type JSON-Object.
      Parameters:
      name - The name of the possible JSON element
      Returns:
      true if the correctly typed member available, false otherwise
    • getObjectMember

      public JsonObject getObjectMember(String name)
      This method returns the value of an Object member of this object, if it exists, Otherwise, raises an error and returns null.
      Parameters:
      name -
      Returns:
    • getObjectMemberOpt

      public Optional<JsonObject> getObjectMemberOpt(String name)
      This method returns an Optional of an Object member of this object, if it exists, Otherwise, returns an empty optional.
      Parameters:
      name -
      Returns:
    • hasIntegerMember

      public boolean hasIntegerMember(String name)
      Checks whether there exists a member with the corresponding name and checks whether it is of type JSON-Integer.
      Parameters:
      name - The name of the possible JSON element
      Returns:
      true if the correctly typed member available, false otherwise
    • getIntegerMember

      public int getIntegerMember(String name)
      This method returns the value of an Integer member of this object, if it exists, Otherwise, raises an error and returns null.
      Parameters:
      name -
      Returns:
    • getIntegerMemberOpt

      public Optional<Integer> getIntegerMemberOpt(String name)
      This method returns an Optional of an Integer member of this object, if it exists, Otherwise, returns an empty optional.
      Parameters:
      name -
      Returns:
    • hasDoubleMember

      public boolean hasDoubleMember(String name)
      Checks whether there exists a member with the corresponding name and checks whether it is of type JSON-Double.
      Parameters:
      name - The name of the possible JSON element
      Returns:
      true if the correctly typed member available, false otherwise
    • getDoubleMember

      public double getDoubleMember(String name)
      This method returns the value of an Double member of this object, if it exists, Otherwise, raises an error and returns null.
      Parameters:
      name -
      Returns:
    • getDoubleMemberOpt

      public Optional<Double> getDoubleMemberOpt(String name)
      This method returns an Optional of an Double member of this object, if it exists, Otherwise, returns an empty optional.
      Parameters:
      name -
      Returns:
    • hasFloatMember

      public boolean hasFloatMember(String name)
      Checks whether there exists a member with the corresponding name and checks whether it is of type JSON-Float.
      Parameters:
      name - The name of the possible JSON element
      Returns:
      true if the correctly typed member available, false otherwise
    • getFloatMember

      public float getFloatMember(String name)
      This method returns the value of an Float member of this object, if it exists, Otherwise, raises an error and returns null.
      Parameters:
      name -
      Returns:
    • getFloatMemberOpt

      public Optional<Float> getFloatMemberOpt(String name)
      This method returns an Optional of an Double member of this object, if it exists, Otherwise, returns an empty optional.
      Parameters:
      name -
      Returns:
    • hasLongMember

      public boolean hasLongMember(String name)
      Checks whether there exists a member with the corresponding name and checks whether it is of type JSON-Long.
      Parameters:
      name - The name of the possible JSON element
      Returns:
      true if the correctly typed member available, false otherwise
    • getLongMember

      public long getLongMember(String name)
      This method returns the value of an Long member of this object, if it exists, Otherwise, raises an error and returns null.
      Parameters:
      name -
      Returns:
    • getLongMemberOpt

      public Optional<Long> getLongMemberOpt(String name)
      This method returns an Optional of an Long member of this object, if it exists, Otherwise, returns an empty optional.
      Parameters:
      name -
      Returns:
    • print

      public String print(IndentPrinter p)
      Specified by:
      print in interface JsonElement