public final class JsonTable extends Object
The JSON table has the following structure:
"<name>" : { "attributes": ["<attr1>", "<attr2>", "<attr3>", ... "<attrn>"], "objects": [ "<object1>": [<v11>, <v12>, <v13>, ... <v1n>], "<object2>": [<v21>, <v22>, <v23>, ... <v2n>], "<object3>": [<v31>, <v32>, <v33>, ... <v3n>], : "<objectm>": [<vm1>, <vm2>, <vm3>, ... <vmn>] ] }Note that each value is a primitive item or an array of primitive items.
Constructor and Description |
---|
JsonTable(String name,
List<String> attributes)
Create a table with the specified name and the given set
of attributes.
|
Modifier and Type | Method and Description |
---|---|
void |
addObject(String objectName)
Add an object (i.e. row) to this table.
|
void |
addValue(String objectName,
String attribute,
Object value)
Add the specified value to the given object/attribute.
|
boolean |
contains(String objectName)
Check if this table contains the specified object.
|
List<String> |
getAttributes()
Return the attributes (i.e. columns) of this table.
|
String |
getName()
Return name of this table.
|
Set<String> |
getObjects()
Return the objects (i.e. rows) of this table.
|
Object |
getValue(String objectName,
String attribute)
Return (first) value of the specified object for the given attribute.
|
List<Object> |
getValues(String objectName,
String attribute)
Return the values of the specified object for the given attribute.
|
String |
toString() |
public JsonTable(String name, List<String> attributes)
name
- Table name. Non-null.attributes
- List of attributes (i.e. columns). Non-null.IllegalArgumentException
- If name or attributes is null.public String getName()
public List<String> getAttributes()
public Set<String> getObjects()
public boolean contains(String objectName)
objectName
- Name of object to check. Non-null.IllegalArgumentException
- If objectName is null.public void addObject(String objectName)
objectName
- Name of object to add. Non-null.IllegalArgumentException
- If object Name is null,
or the object already exists in this table.public void addValue(String objectName, String attribute, Object value)
objectName
- Name of object (i.e. row) to add value to. Non-null.attribute
- Attribute (i.e. column) to add value to. Non-null.value
- Value to add. Null for no-value.IllegalArgumentException
- If objectName or attribute is null or
not present in the table.public List<Object> getValues(String objectName, String attribute)
objectName
- Name of object to get values for.attribute
- Attribute to get values for.IllegalArgumentException
- If objectName or attribute is null or
not present in the table.public Object getValue(String objectName, String attribute)
objectName
- Name of object to get values for.attribute
- Attribute to get values for.IllegalArgumentException
- If objectName or attribute is null or
not present in the table.Copyright © 2024 Petroware AS - https://petroware.no