public final class TextTemplate extends Object implements TextRepresentable, Iterable<Object>
Text.Builder
. Elements will be appended to the result builder in the
order that they are specified in of(Object...)
.Modifier and Type | Class and Description |
---|---|
static class |
TextTemplate.Arg
Represents a variable element within a TextTemplate.
|
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CLOSE_ARG
Default "close" String for how arguments are contained within the
template.
|
static String |
DEFAULT_OPEN_ARG
Default "open" String for how arguments are contained within the
template.
|
static TextTemplate |
EMPTY
Empty representation of a
TextTemplate . |
Modifier and Type | Method and Description |
---|---|
Text.Builder |
apply()
Applies an empty map of parameters to this TextTemplate and returns the
result in a
Text.Builder . |
Text.Builder |
apply(Map<String,?> params)
Applies the specified parameters to this TextTemplate and returns the
result in a
Text.Builder . |
static TextTemplate.Arg.Builder |
arg(String name)
Constructs a new
TextTemplate.Arg to be supplied to of(Object...) . |
TextTemplate |
concat(TextTemplate other)
Concatenates the specified
TextTemplate to this template and
returns the result. |
boolean |
equals(Object obj) |
Map<String,TextTemplate.Arg> |
getArguments()
Returns the arguments contained within the TextTemplate.
|
String |
getCloseArgString()
Returns the string used for containing Args within the template.
|
List<Object> |
getElements()
Returns the elements contained in this TextTemplate.
|
String |
getOpenArgString()
Returns the string used for containing Args within the template.
|
int |
hashCode() |
Iterator<Object> |
iterator() |
static TextTemplate |
of()
Returns the empty representation of a TextTemplate.
|
static TextTemplate |
of(Object... elements)
Constructs a new TextTemplate for the given elements.
|
static TextTemplate |
of(String openArg,
String closeArg,
Object[] elements)
Constructs a new TextTemplate for the given elements.
|
String |
toString() |
Text |
toText()
Gets the textual representation of this instance for its usage in other
Text objects. |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
applyTo
forEach, spliterator
public static final String DEFAULT_OPEN_ARG
public static final String DEFAULT_CLOSE_ARG
public static final TextTemplate EMPTY
TextTemplate
. This is returned if the
array supplied to of(Object...)
is empty.public List<Object> getElements()
public Map<String,TextTemplate.Arg> getArguments()
public String getOpenArgString()
public String getCloseArgString()
public TextTemplate concat(TextTemplate other)
TextTemplate
to this template and
returns the result. In the event that the two templates' open/close
argument containers vary, this template's argument containers will be
used.other
- To concatenatepublic Text.Builder apply()
Text.Builder
.TextTemplateArgumentException
- if required parameters are missingpublic Text.Builder apply(Map<String,?> params)
Text.Builder
.params
- Parameters to applyTextTemplateArgumentException
- if required parameters are missingpublic static TextTemplate of(String openArg, String closeArg, Object[] elements)
apply(Map)
.
The provided elements may be of any type.
In the case that an element is a TextElement
,
TextElement.applyTo(Text.Builder)
will be used to append the
element to the builder.
In the case that an element is an TextTemplate.Arg
the argument will be
replaced with the TextElement
provided by the corresponding
parameter supplied by apply(Map)
In the case that an element is any other type, the parameter value's
Object.toString()
method will be used to create a Text
object.
elements
- Elements to append to builderopenArg
- String to use for beginning of Arg containerscloseArg
- String to use for end of Arg containerspublic static TextTemplate of(Object... elements)
apply(Map)
.
The provided elements may be of any type.
In the case that an element is a TextElement
,
TextElement.applyTo(Text.Builder)
will be used to append the
element to the builder.
In the case that an element is an TextTemplate.Arg
the argument will be
replaced with the TextElement
provided by the corresponding
parameter supplied by apply(Map)
In the case that an element is any other type, the parameter value's
Object.toString()
method will be used to create a Text
object.
elements
- Elements to append to builderpublic static TextTemplate of()
public static TextTemplate.Arg.Builder arg(String name)
TextTemplate.Arg
to be supplied to of(Object...)
.
This argument expects a TextElement
parameter.name
- name of argumentpublic Text toText()
TextRepresentable
Text
objects. This may but does not need to include
hover texts
or other actions
. This
method is basically the toString()
equivalent
for Text
s.toText
in interface TextRepresentable