<collection-to-array>

Purpose/Function

Convert the java.util.Collection into an untyped array (i.e., Object[]). Setting the recurrence option to true means all nested collections will also be converted. See also <array-to-list>.

Attributes

NAME

TYPE

DEFAULT VALUE

DESCRIPTION

collection

java.util.Collection

(required)

collection to convert

name

java.lang.String

(required)

name of variable to which to assign the result

global

boolean

false

assign to global frame

declare

boolean

true

declare the variable name rather than assign to existing variable

recur

boolean

false

convert all nested collections; default behavior is simply the result of: collection.toArray()

Elements

None

ReturnValues

None.

Examples

...
        <declare name="list">
		<list>
			<list>
				<value type="double">-.408293</value>
				<value type="boolean">false</value>
			</list>
			<value type="int">483</value>
			<value type="long">8822938409128</value>
                        <map>
                                <map-entry key="a">
                                      <value>A</value>
                                </map-entry>
                        </map>
		</list>
	</declare>
	<echo message="${list}" stdout="true" />
	<collection-to-array collection="${list}" name="array" recur="true" />
	<echo message="${array}" stdout="true" />
	<array-to-list array="${array}" name="list" declare="false" recur="true" />
	<echo message="${list}" stdout="true" />
...

Output from the three <echo> statements should be as follows:

<!-- <echo message="${list}" stdout="true"/> -->
<collection type="class java.util.ArrayList">
  <collection type="class java.util.ArrayList">
    <element type="class java.lang.Double">-0.408293</element>
    <element type="class java.lang.Boolean">false</element>
  </collection>
  <element type="class java.lang.Integer">483</element>
  <element type="class java.lang.Long">8822938409128</element>
  <map type="class java.util.HashMap">
    <entry key="a">
      <element type="class java.lang.String">A</element>
    </entry>
  </map>
</collection>

<!-- <echo message="${array}" stdout="true"/> -->
<array>
  <array>
    <element type="class java.lang.Double">-0.408293</element>
    <element type="class java.lang.Boolean">false</element>
  </array>
  <element type="class java.lang.Integer">483</element>
  <element type="class java.lang.Long">8822938409128</element>
  <map type="class java.util.HashMap">
    <entry key="a">
      <element type="class java.lang.String">A</element>
    </entry>
  </map>
</array>

<!-- <echo message="${list}" stdout="true"/> -->
<collection type="class java.util.ArrayList">
  <collection type="class java.util.ArrayList">
    <element type="class java.lang.Double">-0.408293</element>
    <element type="class java.lang.Boolean">false</element>
  </collection>
  <element type="class java.lang.Integer">483</element>
  <element type="class java.lang.Long">8822938409128</element>
  <map type="class java.util.HashMap">
    <entry key="a">
      <element type="class java.lang.String">A</element>
    </entry>
  </map>
</collection>
  • No labels