This is an automated email from the ASF dual-hosted git repository. ddekany pushed a commit to branch 2.3-gae in repository https://gitbox.apache.org/repos/asf/freemarker.git
commit 6ea15af5114666a459c434314d58574d3e200c03 Author: ddekany <[email protected]> AuthorDate: Wed Oct 23 20:55:09 2019 +0200 Added a new SimpleHash constructor, where the caller can provide the Map instance used as the backing storage, thus allows controlling the ordering, and other technical aspects (like the initial capacity) of the underlying Map. --- src/main/java/freemarker/template/SimpleHash.java | 22 ++++++++++++++++++++++ src/manual/en_US/book.xml | 8 ++++++++ 2 files changed, 30 insertions(+) diff --git a/src/main/java/freemarker/template/SimpleHash.java b/src/main/java/freemarker/template/SimpleHash.java index c059c67..f32ebb2 100644 --- a/src/main/java/freemarker/template/SimpleHash.java +++ b/src/main/java/freemarker/template/SimpleHash.java @@ -115,6 +115,28 @@ public class SimpleHash extends WrappingTemplateModel implements TemplateHashMod } /** + * Creates an instance that will use the specified {@link Map} directly as its backing store; beware, the + * {@link Map} will be possibly modified by {@link SimpleHash}, even if you only read the {@link SimpleHash}. + * That's because when a value is read, it's replaced with the corresponding {@link TemplateModel}. + * + * <p>The goal of this constructor is to allow you to control technical aspects, like the initial capacity, and + * ordering of the underlying {@link Map} implementation. The iteration order of the {@link SimpleHash} will be + * the same as of the underlying {@link Map}. + * + * @param directMap The map that the instance will use directly as backing storage; possibly will be modified, + * even when you only read the {@link SimpleHash}! Must allow any kind of object as value, + * including {@code null}! Supporting {@code null} keys is not needed. + * + * @param overloadDistinction To avoid ambiguity with other overloads; the value is unused. + * + * @since 2.3.30 + */ + public SimpleHash(Map<String, Object> directMap, ObjectWrapper wrapper, int overloadDistinction) { + super(wrapper); + this.map = directMap; + } + + /** * Creates a new hash by shallow-coping (possibly cloning) the underlying map; in many applications you should use * {@link DefaultMapAdapter} instead. * diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml index 2aa541d..53557df 100644 --- a/src/manual/en_US/book.xml +++ b/src/manual/en_US/book.xml @@ -28783,6 +28783,14 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting> <para>Bug fixed: AST traversal API now can properly traverse the inside of lambda expressions (such as the parameter list)</para> </listitem> + + <listitem> + <para>Added a new <literal>SimpleHash</literal> constructor, + where the caller can provide the <literal>Map</literal> instance + used as the backing storage, thus allows controlling the + ordering, and other technical aspects (like the initial + capacity) of the underlying <literal>Map</literal>.</para> + </listitem> </itemizedlist> </section> </section>
