public abstract class AbstractStructuredOutput extends Object implements StructuredOutput
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractStructuredOutput.Element
Used by internal bookkeeping, to close elements property
|
protected static class |
AbstractStructuredOutput.ElementType
Types used by internal bookkeeping
|
class |
AbstractStructuredOutput.TagBuilder
Used to fluently create a
beginObject(String, Attribute...) . |
Modifier and Type | Field and Description |
---|---|
protected List<AbstractStructuredOutput.Element> |
nesting |
Constructor and Description |
---|
AbstractStructuredOutput() |
Modifier and Type | Method and Description |
---|---|
<E> StructuredOutput |
array(String name,
Collection<E> array,
BiConsumer<StructuredOutput,E> arrayConsumer)
Outputs the given collection as array while using the given arrayConsumer to generate the array
contents.
|
StructuredOutput |
array(String name,
String elementName,
Collection<?> array)
Outputs the given collection as array.
|
StructuredOutput |
beginArray(String name)
Starts an array with is added to the current object as "name".
|
StructuredOutput |
beginObject(String name)
Starts a new object with the given name.
|
StructuredOutput |
beginObject(String name,
Attribute... attributes)
Starts a new object with the given name and attributes
|
AbstractStructuredOutput.TagBuilder |
buildObject(String name)
Creates a new object using the returned tag builder
|
StructuredOutput |
endArray()
Ends the currently open array.
|
protected abstract void |
endArray(String name)
Must be implemented by subclasses to end an array.
|
StructuredOutput |
endObject()
Ends the currently open object.
|
protected abstract void |
endObject(String name)
Must be implemented by subclasses to end an object.
|
void |
endResult()
Finishes (closes) the result
|
protected AbstractStructuredOutput.ElementType |
getCurrentType()
Returns the type of the current element.
|
boolean |
isCurrentObjectEmpty()
Determines whether the current element is empty
|
StructuredOutput |
nullsafeProperty(String name,
Object data)
Adds a property to the current object.
|
StructuredOutput |
property(String name,
Object data)
Adds a property to the current object.
|
protected abstract void |
startArray(String name)
Must be implemented by subclasses to start a new array.
|
protected abstract void |
startObject(String name,
Attribute... attributes)
Must be implemented by subclasses to start a new object.
|
protected abstract void |
writeProperty(String name,
Object value)
Must be implemented by subclasses to generate a property.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
beginResult, beginResult
protected List<AbstractStructuredOutput.Element> nesting
protected AbstractStructuredOutput.ElementType getCurrentType()
public boolean isCurrentObjectEmpty()
public StructuredOutput beginArray(String name)
StructuredOutput
beginArray
in interface StructuredOutput
name
- the name of the arraypublic StructuredOutput array(@Nonnull String name, @Nonnull String elementName, @Nonnull Collection<?> array)
StructuredOutput
This will create a property with the given name and the given array as value
array
in interface StructuredOutput
name
- the name of the propertyelementName
- the name used to generate inner elements (if required, e.g. XML)array
- the array to outputpublic <E> StructuredOutput array(@Nonnull String name, @Nonnull Collection<E> array, BiConsumer<StructuredOutput,E> arrayConsumer)
StructuredOutput
array
in interface StructuredOutput
E
- the type of elements in arrayname
- the name of the array property to createarray
- the collection to generate inner elementsarrayConsumer
- the consumer which creates the array content per child element in arrayprotected abstract void startArray(String name)
name
- the name of the array property.protected abstract void startObject(String name, Attribute... attributes)
name
- the name of the objectattributes
- the attributes of the objectprotected abstract void endArray(String name)
name
- the name of the array property to closeprotected abstract void endObject(String name)
name
- the name of the object to closeprotected abstract void writeProperty(String name, Object value)
name
- the name of the propertyvalue
- the value of the propertypublic StructuredOutput beginObject(String name)
StructuredOutput
beginObject
in interface StructuredOutput
name
- the name of the element to startpublic StructuredOutput beginObject(String name, Attribute... attributes)
StructuredOutput
beginObject
in interface StructuredOutput
name
- the name of the object to createattributes
- the attributes to add to the object@CheckReturnValue public AbstractStructuredOutput.TagBuilder buildObject(@Nonnull String name)
name
- the name of the object to createpublic StructuredOutput endArray()
StructuredOutput
endArray
in interface StructuredOutput
public StructuredOutput endObject()
StructuredOutput
endObject
in interface StructuredOutput
public void endResult()
StructuredOutput
endResult
in interface StructuredOutput
public StructuredOutput property(String name, Object data)
StructuredOutput
property
in interface StructuredOutput
name
- the name of the propertydata
- the value of the propertypublic StructuredOutput nullsafeProperty(@Nonnull String name, @Nullable Object data)
StructuredOutput
This will create a property with the specified data as value or empty string if the value is null.
nullsafeProperty
in interface StructuredOutput
name
- the name of the propertydata
- the value of the propertyCopyright © 2018. All rights reserved.