public interface IonStruct extends IonContainer
struct
value.
WARNING: This interface should not be implemented or extended by code outside of this library.
Note that this cannot extend Map
because that interface
requires unique keys, while Ion's structs allow duplicate field names.
EMPTY_ARRAY
Modifier and Type | Method and Description |
---|---|
ValueFactory |
add(String fieldName)
Provides a factory that when invoked constructs a new value and
add s it to this struct using the given
fieldName . |
void |
add(String fieldName,
IonValue child)
Adds a new field to this struct.
|
void |
add(SymbolToken fieldName,
IonValue child)
Adds a new field to this struct using a given name and/or SID.
|
IonStruct |
clone()
Creates a copy of this value and all of its children.
|
IonStruct |
cloneAndRemove(String... fieldNames)
Clones this struct, excluding certain fields.
|
IonStruct |
cloneAndRetain(String... fieldNames)
Clones this struct, including only certain fields.
|
boolean |
containsKey(Object fieldName)
Determines whether this struct contains one or more fields
for the specified field name (i.e., key).
|
boolean |
containsValue(Object value)
Determines whether this struct contains one or more fields with
the specified value.
|
IonValue |
get(String fieldName)
Gets the value of a field in this struct.
|
ValueFactory |
put(String fieldName)
Provides a factory that when invoked constructs a new value and
put s it into this struct using the given
fieldName . |
void |
put(String fieldName,
IonValue child)
Puts a new field in this struct, replacing all existing fields
with the same name.
|
void |
putAll(Map<? extends String,? extends IonValue> m)
Copies all of the mappings from the specified map to this struct.
|
IonValue |
remove(String fieldName)
Removes a field by name, returning a value that was previously
associated with the field, or
null if this struct contained no
such field. |
boolean |
removeAll(String... fieldNames)
Removes from this struct all fields with names in the given list.
|
boolean |
retainAll(String... fieldNames)
Retains only the fields in this struct that have one of the given names.
|
int |
size()
Gets the number of fields in this struct.
|
clear, isEmpty, iterator, makeNull, remove
accept, addTypeAnnotation, clearTypeAnnotations, equals, getContainer, getFieldName, getFieldNameSymbol, getSymbolTable, getSystem, getType, getTypeAnnotations, getTypeAnnotationSymbols, hashCode, hasTypeAnnotation, isNullValue, isReadOnly, makeReadOnly, removeFromContainer, removeTypeAnnotation, setTypeAnnotations, setTypeAnnotationSymbols, topLevelValue, toPrettyString, toString, toString, writeTo
forEach, spliterator
int size() throws NullValueException
{a:1,a:2}
is 2.size
in interface IonContainer
NullValueException
- if this.isNullValue()
.boolean containsKey(Object fieldName)
fieldName
- field name whose presence in this struct is to be testedtrue
if this struct contains a field for the
specified field nameClassCastException
- if the specified field name is not a
String
NullPointerException
- if the specified field name is
null
boolean containsValue(Object value)
value
- value whose presence in this struct is to be testedtrue
if this struct contains a field for the
specified valueClassCastException
- if the specified value is not an
IonValue
NullPointerException
- if the specified value is null
IonValue get(String fieldName)
get("a")
on the struct:
{ a:1, b:2, a:3 }will return either 1 or 3.
fieldName
- the desired field.null
if it doesn't
exist in this struct, or if this is null.struct
.NullPointerException
- if the fieldName
is null
.void put(String fieldName, IonValue child) throws ContainedValueException
child == null
then all existing fields
with the given name will be removed.
If this is null.struct
and child != null
then this
becomes a single-field struct.
The effect of this method is such that if
put(fieldName, child)
succeeds, then
get(fieldName) == child
will be true afterwards.
fieldName
- the name of the new field.child
- the value of the new field.NullPointerException
- if fieldName
is null
.ContainedValueException
- if child
is already part of a container.IllegalArgumentException
- if element
is an IonDatagram
.ValueFactory put(String fieldName)
put
s it into this struct using the given
fieldName
.
These two lines are equivalent:
str.put("f").newInt(3); str.put("f", str.getSystem().newInt(3));
NullPointerException
- if fieldName
is null
.put(String, IonValue)
void putAll(Map<? extends String,? extends IonValue> m)
put(k, v)
on this struct once for each
mapping from key k
to value v
in the specified map.
The behavior of this operation is undefined if the specified map is
modified while the operation is in progress.
If a key in the map maps to null
, then all fields with that name
will be removed from this struct.
NullPointerException
- if the given map is null.ContainedValueException
- if any values in the map are already
part of an IonContainer
(even this one).void add(String fieldName, IonValue child) throws ContainedValueException
null.struct
, then it becomes a single-field
struct.
If a field with the given name already exists in this struct, this call will result in repeated fields.
fieldName
- the name of the new field.child
- the value of the new field.NullPointerException
- if fieldName
or child
is null
.ContainedValueException
- if child
is already part of a container.IllegalArgumentException
- if element
is an IonDatagram
.void add(SymbolToken fieldName, IonValue child) throws ContainedValueException
null.struct
, then it becomes a single-field
struct.
If a field with the given name already exists in this struct, this call will result in repeated fields.
This is an "expert method": correct use requires deep understanding of the Ion binary format. You almost certainly don't want to use it.
fieldName
- the name of the new field.child
- the value of the new field.NullPointerException
- if fieldName
or child
is null
.ContainedValueException
- if child
is already part of a container.IllegalArgumentException
- if element
is an IonDatagram
.ValueFactory add(String fieldName)
add
s it to this struct using the given
fieldName
.
These two lines are equivalent:
str.add("f").newInt(3); str.add("f", str.getSystem().newInt(3));
NullPointerException
- if fieldName
is null
.add(String, IonValue)
IonValue remove(String fieldName)
null
if this struct contained no
such field.
Because Ion structs may have repeated fields, additional fields with the given name may still exist after this method returns.
If this struct is an Ion null value or empty, then this method returns null and has no effect.
fieldName
- must not be null.null
if there was no such field.boolean removeAll(String... fieldNames)
If this struct is an Ion null value or empty,
then this method returns false
and has no effect.
fieldNames
- the names of the fields to remove.NullPointerException
- if fieldNames
, or any element within it, is null
.boolean retainAll(String... fieldNames)
fieldNames
.
If this struct is an Ion null value or empty,
then this method returns false
and has no effect.
fieldNames
- the names of the fields to retain.NullPointerException
- if fieldNames
, or any element within it, is null
.IonStruct clone() throws UnknownSymbolException
IonValue
IonValue.isReadOnly()
.
The cloned value will be created in the context of the same
ValueFactory
as this instance; if you want a copy using a
different factory, then use ValueFactory.clone(IonValue)
instead.
clone
in interface IonContainer
clone
in interface IonValue
UnknownSymbolException
- if any part of this value has unknown text but known Sid for
its field name, annotation or symbol.IonStruct cloneAndRemove(String... fieldNames) throws UnknownSymbolException
fieldNames
- the names of the fields to remove.
A null field name causes removal of fields with unknown names.UnknownSymbolException
- if any part of the cloned value would have unknown text but known SID
for its field name, annotation or symbol.IonValue.clone()
IonStruct cloneAndRetain(String... fieldNames) throws UnknownSymbolException
fieldNames
- the names of the fields to retain.
Nulls are not allowed.NullPointerException
- if fieldNames
, or any element within it, is null
.UnknownSymbolException
- if any part of the cloned value would have unknown text but known SID
for its field name, annotation or symbol.IonValue.clone()