A simple implementation of the
TemplateSequenceModel interface, using its own underlying
storing the list items. If you are wrapping an already existing
array, you should certainly
DefaultArrayAdapter (see comparison below).
This class is thread-safe if you don't call modifying methods (like
#add(Object)) after you have made the
object available for multiple threads (assuming you have published it safely to the other threads; see JSR-133 Java
Memory Model). These methods aren't called by FreeMarker, so it's usually not a concern.
DefaultArrayAdapter - Which to use when?
array that exists regardless of FreeMarker, only you need to access it from templates,
DefaultMapAdapter should be the default choice, as it can be unwrapped to the originally wrapped object
(important when passing it to Java methods from the template). It also has more predictable performance (no spikes).
For a sequence that's made specifically to be used from templates, creating an empty
filling it with
SimpleSequence#add(Object) is usually the way to go, as the resulting sequence is
significantly faster to read from templates than a
DefaultListAdapter (though it's somewhat slower to read
from a plain Java method to which it had to be passed adapted to a
It also matters if for how many times will the same
List entry be read from the template(s) later,
on average. If, on average, you read each entry for more than 4 times,
SimpleSequence will be most
certainly faster, but if for 2 times or less (and especially if not at all) then
be faster. Before choosing based on performance though, pay attention to the behavioral differences;
SimpleSequence will shallow-copy the original
List at construction time, so it won't reflect
List content changes after the
SimpleSequence construction, also
SimpleSequence can't be
unwrapped to the original wrapped instance.