JSArray
so that it can
store named objects.
Objects defined by scripting languages can be used
to configure instances of NamedObjectFactory
.
For this use, the configuration may include lists
of values.
The types of the values that can be inserted into
this object are NamedObjectOps
, JSObject
,
JSArray
, Boolean
, Number
,
and String
.
The class NJSUtilities.JSON
can be used to create instances
of NJSObject
and NJSArray
by reading from various
sources, and instances of these two classes in turn can be used to
configure a named-object factory, which can then create a named
object.
This class is similar to an array list, but with some run-time type
checking. Entries in the list can be other instances of JSArray
(instances of NJSArray
are preferred) or instances of
JSObject
(instances of NJSObject
are preferred), in
addition to strings, numbers, and boolean values, allowing trees or
directed graphs to be constructed. Iterators will list the values
in the order in which they were inserted.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.util.JSArray
JSArray.ConversionException
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add any allowed object.boolean
add
(NamedObjectOps object) Add an instance ofNamedObjectOps
.Set any allowed object at a specified index.Methods inherited from class org.bzdev.util.JSArray
add, add, add, add, add, addObject, forEach, get, get, identity, iterator, parallelStream, setObject, size, spliterator, stream, toArray, toArray, toBooleanArray, toBooleanMatrix, toDoubleArray, toDoubleMatrix, toIntArray, toIntMatrix, toKeyMapList, toKeyMapList, toLongArray, toLongMatrix, toMatrix, toMatrix
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.util.JSOps
nextIdentity
-
Constructor Details
-
NJSArray
public NJSArray()Constructor. -
NJSArray
Constructor sharing a JSArray's tables.- Parameters:
jsa
- the JSArray
-
-
Method Details
-
add
Add an instance ofNamedObjectOps
.- Parameters:
object
- the named object to append to this array/list- Returns:
true
(as specified byCollection.add(E)
).
-
set
public Object set(int index, Object object) throws IllegalArgumentException, IndexOutOfBoundsException Set any allowed object at a specified index. This is used byNJSArray
.- Overrides:
set
in classJSArray
- Parameters:
index
- the indexobject
- the object to append to this array/list- Returns:
- the previous object stored at the specified index
- Throws:
IndexOutOfBoundsException
- if index < 0 or index ≥ size()IllegalArgumentException
- if the object has the wrong type
-
add
Add any allowed object. The object's type must be assignable- Overrides:
add
in classJSArray
- Parameters:
object
- the object to append to this array/list- Returns:
true
(as specified byCollection.add(E)
).- Throws:
IllegalArgumentException
- if the object has the wrong type
-