Class DDF
Each node contains references to its parant and children, if any, as well as data type and possibly a value if a leaf node.
Most of the types are self-explanatory, but strings may be "safe" or "unsafe". Safe strings are understood to be Unicode that can be safely converted between UTF-8 and UTF-16. Unsafe strings are represented as Java String objects but have an unknown character encoding so the individual code points above 127 are essentially undefined and cannot be assumed to represent the "correct" value. They may only be compared with other values that are understood to represent the same range of values.
The method names do not align to normal Java conventions for compatibility with the other version(s) of the same API.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a node to the end of a struct or list and returns it.Adds a node to a list after a specified node.Adds a node to a list prior to a specified node.Adds a new empty node to a structure, possibly creating nested structures based on dotted path notation (existing nodes matching the path segments are not altered other than to convert them to structures).asList()Expose an immutable list representing a structure or list node.asMap()Expose an immutable map representing a structure node.(package private) DDFcopy()Performs a deep copy of the node and all children, if any.static DDFParses a seralized DDF from an input stream.destroy()Destroys a node's content, resets it to a null object and clears its name.private StringBuilderdump(StringBuilder builder, long indent) Helper method to dump to a string for debugging.empty()Converts this node to an empty type/value.(package private) static voidencode(OutputStream os, byte[] bytes) A simple encoder for non-ASCII characters.booleanfloating()Get the floating point value of this node.floating(double val) Converts this node to an floating point type/value.Converts this node to a floating point type/value based on the converted form of the input.Access a (possibly nested) structure member via dotted path notation, also allowing access to list elements via "[n]" array notation.inthashCode()private static inthexchar(int b) Converts a byte into a hex character.integer()Get the integer value of this node.integer(int val) Converts this node to an integer type/value.Converts this node to an integer type/value based on the converted form of the input.booleanisempty()Returns true iff the node is empty.booleanisfloat()Returns true iff the node is a floating point.booleanisint()Returns true iff the node is an integer.booleanislist()Returns true iff the node is a list/array.booleanislong()Returns true iff the node is a long integer.booleanisnull()Returns true iff the node is null.booleanisstring()Returns true iff the node is a string.booleanisstruct()Returns true iff the node is a structure.booleanReturns true iff the node is an unsafe string.iterator()list()Converts this node to a list/array.Get the long integer value of this node.longinteger(long val) Converts this node to a long integer type/value.longinteger(String val) Converts this node to a long integer type/value based on the converted form of the input.name()Get the node name.Set the node name.parent()Get the parent node.remove()Isolate this object from its surrounding nodes and return it.Serialize this object to a provided stream.string()Get the string value of this node.string(double val) Converts this node to a string type/value based on the converted form of the input.string(int val) Converts this node to a string type/value based on the converted form of the input.string(long val) Converts this node to a string type/value based on the converted form of the input.Converts this node to a string type/value.Converts this node to a structure.toString()byte[]Get the byte array value of this node if an unsafe string.unsafe_string(byte[] val) Converts this node to an unsafe string type/value.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
name
Name of node. -
parent
Parent node. -
type
Node type. -
value
Reference to the value, which depends on the type.
-
-
Constructor Details
-
DDF
public DDF()Constructor. -
DDF
Constructor.For compatibility, the name is constrained to no more than 255 characters.
- Parameters:
n- node name
-
DDF
Constructor.For compatibility, the name is constrained to no more than 255 characters.
- Parameters:
n- node nameval- string value, assumed to be "safe" Unicode
-
DDF
Constructor.For compatibility, the name is constrained to no more than 255 characters.
- Parameters:
n- node nameval- byte array value, handled without knowledge of the encoding
-
DDF
Constructor.For compatibility, the name is constrained to no more than 255 characters.
- Parameters:
n- node nameval- integer value
-
DDF
Constructor.For compatibility, the name is constrained to no more than 255 characters.
- Parameters:
n- node nameval- long integer value
-
DDF
Constructor.For compatibility, the name is constrained to no more than 255 characters.
- Parameters:
n- node nameval- floating value
-
-
Method Details
-
destroy
Destroys a node's content, resets it to a null object and clears its name.This is primarily for tree maintenance, given the lack of need for explicit memory management.
- Returns:
- this object
-
copy
Performs a deep copy of the node and all children, if any.- Returns:
- the copy
-
name
Get the node name.- Returns:
- the name
-
name
Set the node name.For compatibility, the name is constrained to no more than 255 characters.
The name will not be set if the node is already a child of a structure.
- Parameters:
n- the new name- Returns:
- this object
-
isnull
public boolean isnull()Returns true iff the node is null.- Returns:
- true iff the node is null
-
isempty
public boolean isempty()Returns true iff the node is empty.- Returns:
- true iff the node is empty
-
isstring
public boolean isstring()Returns true iff the node is a string.- Returns:
- true iff the node is a string
-
isunsafestring
public boolean isunsafestring()Returns true iff the node is an unsafe string.- Returns:
- true iff the node is an unsafe string
-
isint
public boolean isint()Returns true iff the node is an integer.- Returns:
- true iff the node is an integer
-
islong
public boolean islong()Returns true iff the node is a long integer.- Returns:
- true iff the node is a long integer
-
isfloat
public boolean isfloat()Returns true iff the node is a floating point.- Returns:
- true iff the node is a floating point
-
isstruct
public boolean isstruct()Returns true iff the node is a structure.- Returns:
- true iff the node is a structure
-
islist
public boolean islist()Returns true iff the node is a list/array.- Returns:
- true iff the node is a list/array.
-
string
Get the string value of this node.The string value of a non-string value is null.
- Returns:
- the string value or null
-
unsafe_string
@Nullable public byte[] unsafe_string()Get the byte array value of this node if an unsafe string.- Returns:
- the byte array value or null
-
integer
Get the integer value of this node.Integers are coerced from other types based on numeric conversions or the count of a structure or list.
- Returns:
- the integer value or null
-
longinteger
Get the long integer value of this node.Longs are coerced from other types based on numeric conversions or the count of a structure or list.
- Returns:
- the long integer value or null
-
floating
Get the floating point value of this node.Doubles are coerced from other types based on numeric conversions or the count of a structure or list.
- Returns:
- the floating point value or null
-
empty
Converts this node to an empty type/value.All children should be considered disposed of, though in Java this is circumventable by means of maintaining references to them.
- Returns:
- this object
-
string
Converts this node to a string type/value.- Parameters:
val- the value to inject- Returns:
- this object
-
unsafe_string
Converts this node to an unsafe string type/value.- Parameters:
val- the value to inject- Returns:
- this object
-
string
Converts this node to a string type/value based on the converted form of the input.- Parameters:
val- input value- Returns:
- this object
-
string
Converts this node to a string type/value based on the converted form of the input.- Parameters:
val- input value- Returns:
- this object
-
string
Converts this node to a string type/value based on the converted form of the input.- Parameters:
val- input value- Returns:
- this object
-
integer
Converts this node to an integer type/value.- Parameters:
val- value to inject- Returns:
- this object
-
integer
Converts this node to an integer type/value based on the converted form of the input.A conversion error will assign zero as the value.
- Parameters:
val- value to inject- Returns:
- this object
-
longinteger
Converts this node to a long integer type/value.- Parameters:
val- value to inject- Returns:
- this object
-
longinteger
Converts this node to a long integer type/value based on the converted form of the input.A conversion error will assign zero as the value.
- Parameters:
val- value to inject- Returns:
- this object
-
floating
Converts this node to an floating point type/value.- Parameters:
val- value to inject- Returns:
- this object
-
floating
Converts this node to a floating point type/value based on the converted form of the input.A conversion error will assign zero as the value.
- Parameters:
val- value to inject- Returns:
- this object
-
structure
Converts this node to a structure.- Returns:
- this object
-
list
Converts this node to a list/array.- Returns:
- this object
-
add
Adds a node to the end of a struct or list and returns it.If this node is not a struct or list or the child is a null node, then it is returned with no further action.
If this node is a struct with an existing member by the same name, the input replaces that member.
- Parameters:
child- the child to add- Returns:
- the child
-
addbefore
Adds a node to a list prior to a specified node.If this node is not a list, does not contain the second parameter, or either parameter is a null node, then the first parameter is returned with no further action.
- Parameters:
child- the child to addbefore- the node to insert the child before- Returns:
- the child
-
addafter
Adds a node to a list after a specified node.If this node is not a list, does not contain the second parameter, or either parameter is a null node, then the first parameter is returned with no further action.
- Parameters:
child- the child to addafter- the node to insert the child after- Returns:
- the child
-
remove
Isolate this object from its surrounding nodes and return it.- Returns:
- this object
-
parent
Get the parent node.- Returns:
- parent node
-
asMap
Expose an immutable map representing a structure node.- Returns:
- immutable map, or null if the node is not a structure
-
asList
Expose an immutable list representing a structure or list node.- Returns:
- immutable list, or null if the node is not a structure or list
-
addmember
Adds a new empty node to a structure, possibly creating nested structures based on dotted path notation (existing nodes matching the path segments are not altered other than to convert them to structures).The input path MUST contain at least one non-empty path segment.
This node will be converted to a structure if not already one unless it starts out as null.
- Parameters:
path- dotted path to use- Returns:
- the last node added to the nested tree, or a null node if unable to do so
-
getmember
Access a (possibly nested) structure member via dotted path notation, also allowing access to list elements via "[n]" array notation.Failure to navigate the tree at any point will cause a null node to be returned.
- Parameters:
path- dotted path to use- Returns:
- the matching node, or a null node
-
iterator
-
equals
-
hashCode
public int hashCode() -
toString
The string output is for debugging purposes and should not be used when serializing.
-
dump
Helper method to dump to a string for debugging.- Parameters:
builder- string builder to useindent- size of indent- Returns:
- the first parameter
-
serialize
Serialize this object to a provided stream.- Parameters:
os- output stream- Returns:
- the output stream
- Throws:
IOException- if an error occurs
-
deserialize
Parses a seralized DDF from an input stream.- Parameters:
is- input stream- Returns:
- the parsed object
- Throws:
IOException- if an error occurs
-
encode
A simple encoder for non-ASCII characters.Made this package-accessible for unit testing.
- Parameters:
os- output streambytes- bytes to encode- Throws:
IOException- if an error occurs
-
hexchar
private static int hexchar(int b) Converts a byte into a hex character.- Parameters:
b- input byte- Returns:
- the hex character equivalent (capitalized)
-