blob: 0b526400f6810aa2ef7909e1567fcfb9fd6dc223 [file] [log] [blame]
<!--
/***************************************************************************************************************************
* 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.
***************************************************************************************************************************/
-->
Collections
<p>
The following methods are provided for accessing maps and collections:
</p>
<ul class='javatree'>
<li class='jc'>{@link oaj.config.Config}
<ul>
<li class='jm'>{@link oaj.config.Config#getObject(String,Type,Type...) getObject(String,Type,Type...)}
<li class='jm'>{@link oaj.config.Config#getObject(String,Parser,Type,Type...) getObject(String,Parser,Type,Type...)}
<li class='jm'>{@link oaj.config.Config#getObjectWithDefault(String,Object,Type,Type...) getObjectWithDefault(String,T,Type,Type...)}
<li class='jm'>{@link oaj.config.Config#getObjectWithDefault(String,Parser,Object,Type,Type...) getObjectWithDefault(String,T,Parser,Type,Type...)}
</ul>
</ul>
<p>
The <c>Type,Type...</c> arguments allow you to specify the component types for maps and collections.
<c>List</c> class arguments can be followed by zero or one arguments representing the entry types.
<c>Map</c> class arguments can be followed by zero or two arguments representing the key and value types.
The arguments can be chained to produce any data structure consisting of maps, collections, or POJOs.
</p>
<p>
Examples are shown below:
</p>
<ul class='spaced-list'>
<li><c>getObject(<js>"..."</js>, List.<jk>class</jk>)</c>
<br>Produces: <c>List&lt;?&gt;</c>
<li><c>getObject(<js>"..."</js>, LinkedList.<jk>class</jk>)</c>
<br>Produces: <c>LinkedList&lt;?&gt;</c>
<li><c>getObject(<js>"..."</js>, HashSet.<jk>class</jk>, Integer.<jk>class</jk>)</c>
<br>Produces: <c>HashSet&lt;Integer&gt;</c>
<li><c>getObject(<js>"..."</js>, Map.<jk>class</jk>)</c>
<br>Produces: <c>Map&lt;?,?&gt;</c>
<li><c>getObject(<js>"..."</js>, HashMap.<jk>class</jk>)</c>
<br>Produces: <c>HashMap&lt;?,?&gt;</c>
<li><c>getObject(<js>"..."</js>, LinkedHashMap.<jk>class</jk>, String.<jk>class</jk>, MyBean.<jk>class</jk>)</c>
<br>Produces: <c>LinkedHashMap&lt;String,MyBean&gt;</c>
<li><c>getObject(<js>"..."</js>, HashMap.<jk>class</jk>, Integer.<jk>class</jk>, ArrayList.<jk>class</jk>, MyBean[].<jk>class</jk>)</c>
<br>Produces: <c>LinkedHashMap&lt;Integer,ArrayList&lt;MyBean[]&gt;&gt;</c>
</ul>
<h5 class='figure'>Example:</h5>
<p class='bpcode w800'>
<ck>addresses</ck> =
<cv>[
{
street: '123 Main Street',
city: 'Anywhere',
state: 'NY',
zip: 12345
}</cv>,
<cv>{
street: '456 Main Street',
city: 'Anywhere',
state: 'NY',
zip: 12345
}
]</cv>
</p>
<p class='bpcode w800'>
List&lt;Address&gt; addresses = c.getObject(<js>"addresses"</js>, ArrayList.<jk>class</jk>, Address.<jk>class</jk>);
</p>
<p>
Oftentimes, it might be useful to parse into the {@link oaj.ObjectList} and {@link oaj.ObjectMap}
classes that provide the various convenience methods for working with JSON-like data structures:
</p>
<p class='bpcode w800'>
ObjectMap m = c.getObject(<js>"key1"</js>, ObjectMap.<jk>class</jk>);
ObjectList l = c.getObject(<js>"key2"</js>, ObjectList.<jk>class</jk>);
</p>