FREEMARKER-55: replacing list by array for varg entries
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/207d94ef Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/207d94ef Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/207d94ef Branch: refs/heads/3 Commit: 207d94ef8d123b43cf9ff3aed9b0c77f0dff7ecc Parents: 045c980 Author: Woonsan Ko <[email protected]> Authored: Thu Jan 4 11:41:38 2018 -0500 Committer: Woonsan Ko <[email protected]> Committed: Thu Jan 4 11:41:38 2018 -0500 ---------------------------------------------------------------------- .../freemarker/core/util/_ArrayUtilsTest.java | 76 +++++++++++++ .../freemarker/core/util/_ArrayUtils.java | 109 +++++++++++++++++++ ...aBoundFormElementTemplateDirectiveModel.java | 8 +- ...stractHtmlElementTemplateDirectiveModel.java | 53 ++++----- ...tHtmlInputElementTemplateDirectiveModel.java | 30 ++--- .../model/form/FormTemplateDirectiveModel.java | 44 ++++---- .../model/form/InputTemplateDirectiveModel.java | 28 ++--- 7 files changed, 254 insertions(+), 94 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/207d94ef/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/_ArrayUtilsTest.java ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/_ArrayUtilsTest.java b/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/_ArrayUtilsTest.java new file mode 100644 index 0000000..b849bca --- /dev/null +++ b/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/_ArrayUtilsTest.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.freemarker.core.util; + +import java.util.Arrays; + +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +public class _ArrayUtilsTest { + + @Test + public void testAddAll() { + Object [] arr = _ArrayUtils.addAll(null); + assertTrue(arr.length == 0); + + arr = _ArrayUtils.addAll(null, null); + assertNull(arr); + + Object[] arr1 = { "a", "b", "c" }; + Object[] arr2 = { "1", "2", "3" }; + Object[] arrAll = { "a", "b", "c", "1", "2", "3" }; + + arr = _ArrayUtils.addAll(arr1, null); + assertNotSame(arr1, arr); + assertArrayEquals(arr1, arr); + + arr = _ArrayUtils.addAll(null, arr2); + assertNotSame(arr2, arr); + assertArrayEquals(arr2, arr); + + arr = _ArrayUtils.addAll(arr1, arr2); + assertArrayEquals(arrAll, arr); + } + + @Test + public void testClone() { + assertArrayEquals(null, _ArrayUtils.clone((Object[]) null)); + Object[] original1 = new Object[0]; + Object[] cloned1 = _ArrayUtils.clone(original1); + assertTrue(Arrays.equals(original1, cloned1)); + assertTrue(original1 != cloned1); + + final StringBuilder builder = new StringBuilder("pick"); + original1 = new Object[]{builder, "a", new String[]{"stick"}}; + cloned1 = _ArrayUtils.clone(original1); + assertTrue(Arrays.equals(original1, cloned1)); + assertTrue(original1 != cloned1); + assertSame(original1[0], cloned1[0]); + assertSame(original1[1], cloned1[1]); + assertSame(original1[2], cloned1[2]); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/207d94ef/freemarker-core/src/main/java/org/apache/freemarker/core/util/_ArrayUtils.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_ArrayUtils.java b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_ArrayUtils.java new file mode 100644 index 0000000..a060f99 --- /dev/null +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_ArrayUtils.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.freemarker.core.util; + +import java.lang.reflect.Array; + +/** + * Don't use this; used internally by FreeMarker, might changes without notice. + */ +public class _ArrayUtils { + + private _ArrayUtils() { + } + + // Note: Copied from Commons Lang's ArrayUtils (v3.7). + /** + * <p>Adds all the elements of the given arrays into a new array. + * <p>The new array contains all of the element of {@code array1} followed + * by all of the elements {@code array2}. When an array is returned, it is always + * a new array. + * + * <pre> + * ArrayUtils.addAll(null, null) = null + * ArrayUtils.addAll(array1, null) = cloned copy of array1 + * ArrayUtils.addAll(null, array2) = cloned copy of array2 + * ArrayUtils.addAll([], []) = [] + * ArrayUtils.addAll([null], [null]) = [null, null] + * ArrayUtils.addAll(["a", "b", "c"], ["1", "2", "3"]) = ["a", "b", "c", "1", "2", "3"] + * </pre> + * + * @param <T> the component type of the array + * @param array1 the first array whose elements are added to the new array, may be {@code null} + * @param array2 the second array whose elements are added to the new array, may be {@code null} + * @return The new array, {@code null} if both arrays are {@code null}. + * The type of the new array is the type of the first array, + * unless the first array is null, in which case the type is the same as the second array. + * @since 2.1 + * @throws IllegalArgumentException if the array types are incompatible + */ + public static <T> T[] addAll(final T[] array1, final T... array2) { + if (array1 == null) { + return clone(array2); + } else if (array2 == null) { + return clone(array1); + } + final Class<?> type1 = array1.getClass().getComponentType(); + @SuppressWarnings("unchecked") // OK, because array is of type T + final T[] joinedArray = (T[]) Array.newInstance(type1, array1.length + array2.length); + System.arraycopy(array1, 0, joinedArray, 0, array1.length); + try { + System.arraycopy(array2, 0, joinedArray, array1.length, array2.length); + } catch (final ArrayStoreException ase) { + // Check if problem was due to incompatible types + /* + * We do this here, rather than before the copy because: + * - it would be a wasted check most of the time + * - safer, in case check turns out to be too strict + */ + final Class<?> type2 = array2.getClass().getComponentType(); + if (!type1.isAssignableFrom(type2)) { + throw new IllegalArgumentException("Cannot store " + type2.getName() + " in an array of " + + type1.getName(), ase); + } + throw ase; // No, so rethrow original + } + return joinedArray; + } + + // Note: Copied from Commons Lang's ArrayUtils (v3). + // Clone + //----------------------------------------------------------------------- + /** + * <p>Shallow clones an array returning a typecast result and handling + * {@code null}. + * + * <p>The objects in the array are not cloned, thus there is no special + * handling for multi-dimensional arrays. + * + * <p>This method returns {@code null} for a {@code null} input array. + * + * @param <T> the component type of the array + * @param array the array to shallow clone, may be {@code null} + * @return the cloned array, {@code null} if {@code null} input + */ + public static <T> T[] clone(final T[] array) { + if (array == null) { + return null; + } + return array.clone(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/207d94ef/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractDataBoundFormElementTemplateDirectiveModel.java ---------------------------------------------------------------------- diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractDataBoundFormElementTemplateDirectiveModel.java b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractDataBoundFormElementTemplateDirectiveModel.java index d416fd4..3cb36d6 100644 --- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractDataBoundFormElementTemplateDirectiveModel.java +++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractDataBoundFormElementTemplateDirectiveModel.java @@ -21,8 +21,6 @@ package org.apache.freemarker.spring.model.form; import java.io.IOException; import java.io.Writer; -import java.util.Arrays; -import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -55,15 +53,15 @@ abstract class AbstractDataBoundFormElementTemplateDirectiveModel extends Abstra private static final String ID_PARAM_NAME = ID_ATTR_NAME; - protected static List<StringToIndexMap.Entry> NAMED_ARGS_ENTRY_LIST = Arrays.asList( + protected static StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES = { new StringToIndexMap.Entry(ID_PARAM_NAME, ID_PARAM_IDX) - ); + }; private static final ArgumentArrayLayout ARGS_LAYOUT = ArgumentArrayLayout.create( 1, false, - StringToIndexMap.of(NAMED_ARGS_ENTRY_LIST.toArray(new StringToIndexMap.Entry[NAMED_ARGS_ENTRY_LIST.size()])), + StringToIndexMap.of(NAMED_ARGS_ENTRIES), true ); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/207d94ef/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlElementTemplateDirectiveModel.java ---------------------------------------------------------------------- diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlElementTemplateDirectiveModel.java b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlElementTemplateDirectiveModel.java index 87b2394..0e64e8c 100644 --- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlElementTemplateDirectiveModel.java +++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlElementTemplateDirectiveModel.java @@ -21,10 +21,8 @@ package org.apache.freemarker.spring.model.form; import java.io.IOException; import java.io.Writer; -import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -40,7 +38,7 @@ import org.apache.freemarker.core.model.TemplateModel; import org.apache.freemarker.core.model.TemplateStringModel; import org.apache.freemarker.core.util.CallableUtils; import org.apache.freemarker.core.util.StringToIndexMap; -import org.apache.freemarker.core.util._CollectionUtils; +import org.apache.freemarker.core.util._ArrayUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.servlet.support.RequestContext; @@ -51,8 +49,8 @@ import org.springframework.web.servlet.support.RequestContext; abstract class AbstractHtmlElementTemplateDirectiveModel extends AbstractDataBoundFormElementTemplateDirectiveModel { - private static final int NAMED_ARGS_OFFSET = AbstractDataBoundFormElementTemplateDirectiveModel.NAMED_ARGS_ENTRY_LIST - .size() + 1; + private static final int NAMED_ARGS_OFFSET = AbstractDataBoundFormElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES.length + + 1; private static final int CSS_CLASS_PARAM_IDX = NAMED_ARGS_OFFSET; private static final String CSS_CLASS_PARAM_NAME = "cssClass"; @@ -107,36 +105,33 @@ abstract class AbstractHtmlElementTemplateDirectiveModel private static final int CSSERRORCLASS_PARAM_IDX = NAMED_ARGS_OFFSET + 16; private static final String CSSERRORCLASS_PARAM_NAME = "cssErrorClass"; - @SuppressWarnings("unchecked") - protected static List<StringToIndexMap.Entry> NAMED_ARGS_ENTRY_LIST = - _CollectionUtils.mergeImmutableLists(false, - AbstractDataBoundFormElementTemplateDirectiveModel.NAMED_ARGS_ENTRY_LIST, - Arrays.asList( - new StringToIndexMap.Entry(CSS_CLASS_PARAM_NAME, CSS_CLASS_PARAM_IDX), - new StringToIndexMap.Entry(CSS_STYLE_PARAM_NAME, CSS_STYLE_PARAM_IDX), - new StringToIndexMap.Entry(LANG_PARAM_NAME, LANG_PARAM_IDX), - new StringToIndexMap.Entry(TITLE_PARAM_NAME, TITLE_PARAM_IDX), - new StringToIndexMap.Entry(DIR_PARAM_NAME, DIR_PARAM_IDX), - new StringToIndexMap.Entry(TABINDEX_PARAM_NAME, TABINDEX_PARAM_IDX), - new StringToIndexMap.Entry(ONCLICK_PARAM_NAME, ONCLICK_PARAM_IDX), - new StringToIndexMap.Entry(ONDBLCLICK_PARAM_NAME, ONDBLCLICK_PARAM_IDX), - new StringToIndexMap.Entry(ONMOUSEDOWN_PARAM_NAME, ONMOUSEDOWN_PARAM_IDX), - new StringToIndexMap.Entry(ONMOUSEUP_PARAM_NAME, ONMOUSEUP_PARAM_IDX), - new StringToIndexMap.Entry(ONMOUSEOVER_PARAM_NAME, ONMOUSEOVER_PARAM_IDX), - new StringToIndexMap.Entry(ONMOUSEMOVE_PARAM_NAME, ONMOUSEMOVE_PARAM_IDX), - new StringToIndexMap.Entry(ONMOUSEOUT_PARAM_NAME, ONMOUSEOUT_PARAM_IDX), - new StringToIndexMap.Entry(ONKEYPRESS_PARAM_NAME, ONKEYPRESS_PARAM_IDX), - new StringToIndexMap.Entry(ONKEYUP_PARAM_NAME, ONKEYUP_PARAM_IDX), - new StringToIndexMap.Entry(ONKEYDOWN_PARAM_NAME, ONKEYDOWN_PARAM_IDX), - new StringToIndexMap.Entry(CSSERRORCLASS_PARAM_NAME, CSSERRORCLASS_PARAM_IDX) - ) + protected static StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES = + _ArrayUtils.addAll( + AbstractDataBoundFormElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES, + new StringToIndexMap.Entry(CSS_CLASS_PARAM_NAME, CSS_CLASS_PARAM_IDX), + new StringToIndexMap.Entry(CSS_STYLE_PARAM_NAME, CSS_STYLE_PARAM_IDX), + new StringToIndexMap.Entry(LANG_PARAM_NAME, LANG_PARAM_IDX), + new StringToIndexMap.Entry(TITLE_PARAM_NAME, TITLE_PARAM_IDX), + new StringToIndexMap.Entry(DIR_PARAM_NAME, DIR_PARAM_IDX), + new StringToIndexMap.Entry(TABINDEX_PARAM_NAME, TABINDEX_PARAM_IDX), + new StringToIndexMap.Entry(ONCLICK_PARAM_NAME, ONCLICK_PARAM_IDX), + new StringToIndexMap.Entry(ONDBLCLICK_PARAM_NAME, ONDBLCLICK_PARAM_IDX), + new StringToIndexMap.Entry(ONMOUSEDOWN_PARAM_NAME, ONMOUSEDOWN_PARAM_IDX), + new StringToIndexMap.Entry(ONMOUSEUP_PARAM_NAME, ONMOUSEUP_PARAM_IDX), + new StringToIndexMap.Entry(ONMOUSEOVER_PARAM_NAME, ONMOUSEOVER_PARAM_IDX), + new StringToIndexMap.Entry(ONMOUSEMOVE_PARAM_NAME, ONMOUSEMOVE_PARAM_IDX), + new StringToIndexMap.Entry(ONMOUSEOUT_PARAM_NAME, ONMOUSEOUT_PARAM_IDX), + new StringToIndexMap.Entry(ONKEYPRESS_PARAM_NAME, ONKEYPRESS_PARAM_IDX), + new StringToIndexMap.Entry(ONKEYUP_PARAM_NAME, ONKEYUP_PARAM_IDX), + new StringToIndexMap.Entry(ONKEYDOWN_PARAM_NAME, ONKEYDOWN_PARAM_IDX), + new StringToIndexMap.Entry(CSSERRORCLASS_PARAM_NAME, CSSERRORCLASS_PARAM_IDX) ); private static final ArgumentArrayLayout ARGS_LAYOUT = ArgumentArrayLayout.create( 1, false, - StringToIndexMap.of(NAMED_ARGS_ENTRY_LIST.toArray(new StringToIndexMap.Entry[NAMED_ARGS_ENTRY_LIST.size()])), + StringToIndexMap.of(NAMED_ARGS_ENTRIES), true ); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/207d94ef/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlInputElementTemplateDirectiveModel.java ---------------------------------------------------------------------- diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlInputElementTemplateDirectiveModel.java b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlInputElementTemplateDirectiveModel.java index 997ffc5..a840f56 100644 --- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlInputElementTemplateDirectiveModel.java +++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/AbstractHtmlInputElementTemplateDirectiveModel.java @@ -21,8 +21,6 @@ package org.apache.freemarker.spring.model.form; import java.io.IOException; import java.io.Writer; -import java.util.Arrays; -import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -35,13 +33,12 @@ import org.apache.freemarker.core.model.ObjectWrapperAndUnwrapper; import org.apache.freemarker.core.model.TemplateModel; import org.apache.freemarker.core.util.CallableUtils; import org.apache.freemarker.core.util.StringToIndexMap; -import org.apache.freemarker.core.util._CollectionUtils; +import org.apache.freemarker.core.util._ArrayUtils; import org.springframework.web.servlet.support.RequestContext; abstract class AbstractHtmlInputElementTemplateDirectiveModel extends AbstractHtmlElementTemplateDirectiveModel { - private static final int NAMED_ARGS_OFFSET = AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRY_LIST.size() - + 1; + private static final int NAMED_ARGS_OFFSET = AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES.length + 1; private static final int ONFOCUS_PARAM_IDX = NAMED_ARGS_OFFSET; private static final String ONFOCUS_PARAM_NAME = "onfocus"; @@ -61,25 +58,22 @@ abstract class AbstractHtmlInputElementTemplateDirectiveModel extends AbstractHt private static final int READONLY_PARAM_IDX = NAMED_ARGS_OFFSET + 5; private static final String READONLY_PARAM_NAME = "readonly"; - @SuppressWarnings("unchecked") - protected static List<StringToIndexMap.Entry> NAMED_ARGS_ENTRY_LIST = - _CollectionUtils.mergeImmutableLists(false, - AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRY_LIST, - Arrays.asList( - new StringToIndexMap.Entry(ONFOCUS_PARAM_NAME, ONFOCUS_PARAM_IDX), - new StringToIndexMap.Entry(ONBLUR_PARAM_NAME, ONBLUR_PARAM_IDX), - new StringToIndexMap.Entry(ONCHANGE_PARAM_NAME, ONCHANGE_PARAM_IDX), - new StringToIndexMap.Entry(ACCESSKEY_PARAM_NAME, ACCESSKEY_PARAM_IDX), - new StringToIndexMap.Entry(DISABLED_PARAM_NAME, DISABLED_PARAM_IDX), - new StringToIndexMap.Entry(READONLY_PARAM_NAME, READONLY_PARAM_IDX) - ) + protected static StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES = + _ArrayUtils.addAll( + AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES, + new StringToIndexMap.Entry(ONFOCUS_PARAM_NAME, ONFOCUS_PARAM_IDX), + new StringToIndexMap.Entry(ONBLUR_PARAM_NAME, ONBLUR_PARAM_IDX), + new StringToIndexMap.Entry(ONCHANGE_PARAM_NAME, ONCHANGE_PARAM_IDX), + new StringToIndexMap.Entry(ACCESSKEY_PARAM_NAME, ACCESSKEY_PARAM_IDX), + new StringToIndexMap.Entry(DISABLED_PARAM_NAME, DISABLED_PARAM_IDX), + new StringToIndexMap.Entry(READONLY_PARAM_NAME, READONLY_PARAM_IDX) ); private static final ArgumentArrayLayout ARGS_LAYOUT = ArgumentArrayLayout.create( 1, false, - StringToIndexMap.of(NAMED_ARGS_ENTRY_LIST.toArray(new StringToIndexMap.Entry[NAMED_ARGS_ENTRY_LIST.size()])), + StringToIndexMap.of(NAMED_ARGS_ENTRIES), true ); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/207d94ef/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/FormTemplateDirectiveModel.java ---------------------------------------------------------------------- diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/FormTemplateDirectiveModel.java b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/FormTemplateDirectiveModel.java index a35699c..a11c7cd 100644 --- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/FormTemplateDirectiveModel.java +++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/FormTemplateDirectiveModel.java @@ -22,8 +22,6 @@ package org.apache.freemarker.spring.model.form; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.io.Writer; -import java.util.Arrays; -import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -37,7 +35,7 @@ import org.apache.freemarker.core.model.TemplateModel; import org.apache.freemarker.core.model.TemplateStringModel; import org.apache.freemarker.core.util.CallableUtils; import org.apache.freemarker.core.util.StringToIndexMap; -import org.apache.freemarker.core.util._CollectionUtils; +import org.apache.freemarker.core.util._ArrayUtils; import org.apache.freemarker.spring.model.SpringTemplateCallableHashModel; import org.springframework.beans.PropertyAccessor; import org.springframework.http.HttpMethod; @@ -78,8 +76,7 @@ class FormTemplateDirectiveModel extends AbstractHtmlElementTemplateDirectiveMod public static final String NAME = "form"; - private static final int NAMED_ARGS_OFFSET = AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRY_LIST.size() - + 1; + private static final int NAMED_ARGS_OFFSET = AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES.length + 1; private static final int ACTION_PARAM_IDX = NAMED_ARGS_OFFSET; private static final String ACTION_PARAM_NAME = "action"; @@ -120,32 +117,29 @@ class FormTemplateDirectiveModel extends AbstractHtmlElementTemplateDirectiveMod private static final int METHOD_PARAM_PARAM_IDX = NAMED_ARGS_OFFSET + 12; private static final String METHOD_PARAM_PARAM_NAME = "methodParam"; - @SuppressWarnings("unchecked") - protected static List<StringToIndexMap.Entry> NAMED_ARGS_ENTRY_LIST = - _CollectionUtils.mergeImmutableLists(false, - AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRY_LIST, - Arrays.asList( - new StringToIndexMap.Entry(ACTION_PARAM_NAME, ACTION_PARAM_IDX), - new StringToIndexMap.Entry(METHOD_PARAM_NAME, METHOD_PARAM_IDX), - new StringToIndexMap.Entry(TARGET_PARAM_NAME, TARGET_PARAM_IDX), - new StringToIndexMap.Entry(ENCTYPE_PARAM_NAME, ENCTYPE_PARAM_IDX), - new StringToIndexMap.Entry(ACCEPT_CHARSET_PARAM_NAME, ACCEPT_CHARSET_PARAM_IDX), - new StringToIndexMap.Entry(ONSUBMIT_PARAM_NAME, ONSUBMIT_PARAM_IDX), - new StringToIndexMap.Entry(ONRESET_PARAM_NAME, ONRESET_PARAM_IDX), - new StringToIndexMap.Entry(AUTOCOMPLETE_PARAM_NAME, AUTOCOMPLETE_PARAM_IDX), - new StringToIndexMap.Entry(NAME_PARAM_NAME, NAME_PARAM_IDX), - new StringToIndexMap.Entry(VALUE_PARAM_NAME, VALUE_PARAM_IDX), - new StringToIndexMap.Entry(TYPE_PARAM_NAME, TYPE_PARAM_IDX), - new StringToIndexMap.Entry(SERVLET_RELATIVE_ACTION_PARAM_NAME, SERVLET_RELATIVE_ACTION_PARAM_IDX), - new StringToIndexMap.Entry(METHOD_PARAM_PARAM_NAME, METHOD_PARAM_PARAM_IDX) - ) + protected static StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES = + _ArrayUtils.addAll( + AbstractHtmlElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES, + new StringToIndexMap.Entry(ACTION_PARAM_NAME, ACTION_PARAM_IDX), + new StringToIndexMap.Entry(METHOD_PARAM_NAME, METHOD_PARAM_IDX), + new StringToIndexMap.Entry(TARGET_PARAM_NAME, TARGET_PARAM_IDX), + new StringToIndexMap.Entry(ENCTYPE_PARAM_NAME, ENCTYPE_PARAM_IDX), + new StringToIndexMap.Entry(ACCEPT_CHARSET_PARAM_NAME, ACCEPT_CHARSET_PARAM_IDX), + new StringToIndexMap.Entry(ONSUBMIT_PARAM_NAME, ONSUBMIT_PARAM_IDX), + new StringToIndexMap.Entry(ONRESET_PARAM_NAME, ONRESET_PARAM_IDX), + new StringToIndexMap.Entry(AUTOCOMPLETE_PARAM_NAME, AUTOCOMPLETE_PARAM_IDX), + new StringToIndexMap.Entry(NAME_PARAM_NAME, NAME_PARAM_IDX), + new StringToIndexMap.Entry(VALUE_PARAM_NAME, VALUE_PARAM_IDX), + new StringToIndexMap.Entry(TYPE_PARAM_NAME, TYPE_PARAM_IDX), + new StringToIndexMap.Entry(SERVLET_RELATIVE_ACTION_PARAM_NAME, SERVLET_RELATIVE_ACTION_PARAM_IDX), + new StringToIndexMap.Entry(METHOD_PARAM_PARAM_NAME, METHOD_PARAM_PARAM_IDX) ); private static final ArgumentArrayLayout ARGS_LAYOUT = ArgumentArrayLayout.create( 1, false, - StringToIndexMap.of(NAMED_ARGS_ENTRY_LIST.toArray(new StringToIndexMap.Entry[NAMED_ARGS_ENTRY_LIST.size()])), + StringToIndexMap.of(NAMED_ARGS_ENTRIES), true ); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/207d94ef/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/InputTemplateDirectiveModel.java ---------------------------------------------------------------------- diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/InputTemplateDirectiveModel.java b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/InputTemplateDirectiveModel.java index f155054..6d0f49c 100644 --- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/InputTemplateDirectiveModel.java +++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/form/InputTemplateDirectiveModel.java @@ -21,8 +21,6 @@ package org.apache.freemarker.spring.model.form; import java.io.IOException; import java.io.Writer; -import java.util.Arrays; -import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -35,7 +33,7 @@ import org.apache.freemarker.core.model.ObjectWrapperAndUnwrapper; import org.apache.freemarker.core.model.TemplateModel; import org.apache.freemarker.core.util.CallableUtils; import org.apache.freemarker.core.util.StringToIndexMap; -import org.apache.freemarker.core.util._CollectionUtils; +import org.apache.freemarker.core.util._ArrayUtils; import org.springframework.web.servlet.support.RequestContext; /** @@ -72,8 +70,7 @@ class InputTemplateDirectiveModel extends AbstractHtmlInputElementTemplateDirect public static final String NAME = "input"; - private static final int NAMED_ARGS_OFFSET = AbstractHtmlInputElementTemplateDirectiveModel.NAMED_ARGS_ENTRY_LIST - .size() + 1; + private static final int NAMED_ARGS_OFFSET = AbstractHtmlInputElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES.length + 1; private static final int SIZE_PARAM_IDX = NAMED_ARGS_OFFSET; private static final String SIZE_PARAM_NAME = "size"; @@ -90,24 +87,21 @@ class InputTemplateDirectiveModel extends AbstractHtmlInputElementTemplateDirect private static final int AUTOCOMPLETE_PARAM_IDX = NAMED_ARGS_OFFSET + 4; private static final String AUTOCOMPLETE_PARAM_NAME = "autocomplete"; - @SuppressWarnings("unchecked") - protected static List<StringToIndexMap.Entry> NAMED_ARGS_ENTRY_LIST = - _CollectionUtils.mergeImmutableLists(false, - AbstractHtmlInputElementTemplateDirectiveModel.NAMED_ARGS_ENTRY_LIST, - Arrays.asList( - new StringToIndexMap.Entry(SIZE_PARAM_NAME, SIZE_PARAM_IDX), - new StringToIndexMap.Entry(MAXLENGTH_PARAM_NAME, MAXLENGTH_PARAM_IDX), - new StringToIndexMap.Entry(ALT_PARAM_NAME, ALT_PARAM_IDX), - new StringToIndexMap.Entry(ONSELECT_PARAM_NAME, ONSELECT_PARAM_IDX), - new StringToIndexMap.Entry(AUTOCOMPLETE_PARAM_NAME, AUTOCOMPLETE_PARAM_IDX) - ) + protected static StringToIndexMap.Entry[] NAMED_ARGS_ENTRIES = + _ArrayUtils.addAll( + AbstractHtmlInputElementTemplateDirectiveModel.NAMED_ARGS_ENTRIES, + new StringToIndexMap.Entry(SIZE_PARAM_NAME, SIZE_PARAM_IDX), + new StringToIndexMap.Entry(MAXLENGTH_PARAM_NAME, MAXLENGTH_PARAM_IDX), + new StringToIndexMap.Entry(ALT_PARAM_NAME, ALT_PARAM_IDX), + new StringToIndexMap.Entry(ONSELECT_PARAM_NAME, ONSELECT_PARAM_IDX), + new StringToIndexMap.Entry(AUTOCOMPLETE_PARAM_NAME, AUTOCOMPLETE_PARAM_IDX) ); private static final ArgumentArrayLayout ARGS_LAYOUT = ArgumentArrayLayout.create( 1, false, - StringToIndexMap.of(NAMED_ARGS_ENTRY_LIST.toArray(new StringToIndexMap.Entry[NAMED_ARGS_ENTRY_LIST.size()])), + StringToIndexMap.of(NAMED_ARGS_ENTRIES), true );
