blob: 30fd9c189efc797317a0883c6614615683a59f84 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Wed Oct 10 00:41:12 CEST 2018 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SortTool (VelocityTools 3.0 API)</title>
<meta name="date" content="2018-10-10">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="SortTool (VelocityTools 3.0 API)";
}
}
catch(err) {
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/SortTool.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html" title="class in org.apache.velocity.tools.generic"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../org/apache/velocity/tools/generic/ValueParser.html" title="class in org.apache.velocity.tools.generic"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/velocity/tools/generic/SortTool.html" target="_top">Frames</a></li>
<li><a href="SortTool.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li><a href="#nested.classes.inherited.from.class.org.apache.velocity.tools.generic.CollectionTool">Nested</a>&nbsp;|&nbsp;</li>
<li><a href="#fields.inherited.from.class.org.apache.velocity.tools.generic.CollectionTool">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#methods.inherited.from.class.org.apache.velocity.tools.generic.CollectionTool">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li>Method</li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.velocity.tools.generic</div>
<h2 title="Class SortTool" class="title">Class SortTool</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html" title="class in org.apache.velocity.tools.generic">org.apache.velocity.tools.generic.SafeConfig</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html" title="class in org.apache.velocity.tools.generic">org.apache.velocity.tools.generic.CollectionTool</a></li>
<li>
<ul class="inheritance">
<li>org.apache.velocity.tools.generic.SortTool</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>All Implemented Interfaces:</dt>
<dd><a href="https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html?is-external=true" title="class or interface in java.io">Serializable</a></dd>
</dl>
<hr>
<div class="block"><span class="deprecatedLabel">Deprecated.</span>&nbsp;
<div class="block"><span class="deprecationComment">use CollectionTool sort methods</span></div>
</div>
<br>
<pre><a href="../../../../../org/apache/velocity/tools/config/DefaultKey.html" title="annotation in org.apache.velocity.tools.config">@DefaultKey</a>(<a href="../../../../../org/apache/velocity/tools/config/DefaultKey.html#value--">value</a>="sorter")
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Deprecated.html?is-external=true" title="class or interface in java.lang">@Deprecated</a>
public class <span class="typeNameLabel">SortTool</span>
extends <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html" title="class in org.apache.velocity.tools.generic">CollectionTool</a></pre>
<div class="block"><p>SortTool allows a user to sort a collection (or array, iterator, etc)
on any arbitary set of properties exposed by the objects contained
within the collection.</p>
<p>The sort tool is specifically designed to use within a #foreach
but you may find other uses for it.</p>
<p>The sort tool can handle all of the collection types supported by
#foreach and the same constraints apply as well as the following.
Every object in the collection must support the set of properties
selected to sort on. Each property which is to be sorted on must
return one of the follow:</p>
<ul>
<li>Primitive type: e.g. int, char, long etc</li>
<li>Standard Object: e.g. String, Integer, Long etc</li>
<li>Object which implements the Comparable interface.</li>
</ul>
<p>During the sort operation all properties are compared by calling
compareTo() with the exception of Strings for which
compareToIgnoreCase() is called.</p>
<p>The sort is performed by calling Collections.sort() after
marshalling the collection to sort into an appropriate collection type.
The original collection will not be re-ordered; a new list containing
the sorted elements will always be returned.</p>
<p>The tool is used as follows:</p>
<pre>
Single Property Sort
#foreach($obj in $sorter.sort($objects, "name"))
$obj.name Ordinal= $obj.ordinal
#end
End
Multiple Property Sort
#foreach($obj in $sorter.sort($objects, ["name", "ordinal"]))
$obj.name, $obj.ordinal
#end
End
</pre>
<p>The sort method takes two parameters a collection and a property name
or an array of property names. The property names and corresponding
methods must conform to java bean standards since commons-beanutils
is used to extract the property values.</p>
<p>By default the sort tool sorts ascending, you can override this by
adding a sort type suffix to any property name.</p>
<p>The supported suffixes are:</p>
<pre>
For ascending
:asc
For descending
:desc
Example
#foreach($obj in $sorter.sort($objects, ["name:asc", "ordinal:desc"]))
$obj.name, $obj.ordinal
#end
</pre>
<p>This will sort first by Name in ascending order and then by Ordinal
in descending order, of course you could have left the :asc off of the
'Name' property as ascending is always the default.</p>
<p>Example tools.xml config (if you want to use this with VelocityView):</p>
<pre>
&lt;tools&gt;
&lt;toolbox scope="application"&gt;
&lt;tool class="org.apache.velocity.tools.generic.SortTool"/&gt;
&lt;/toolbox&gt;
&lt;/tools&gt;
</pre></div>
<dl>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>VelocityTools 1.2</dd>
<dt><span class="simpleTagLabel">Version:</span></dt>
<dd>$Id: SortTool.java 1842348 2018-09-29 22:35:00Z michaelo $</dd>
<dt><span class="simpleTagLabel">Author:</span></dt>
<dd>S. Brett Sutton, Nathan Bubna</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../serialized-form.html#org.apache.velocity.tools.generic.SortTool">Serialized Form</a></dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== NESTED CLASS SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="nested.class.summary">
<!-- -->
</a>
<h3>Nested Class Summary</h3>
<ul class="blockList">
<li class="blockList"><a name="nested.classes.inherited.from.class.org.apache.velocity.tools.generic.CollectionTool">
<!-- -->
</a>
<h3>Nested classes/interfaces inherited from class&nbsp;org.apache.velocity.tools.generic.<a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html" title="class in org.apache.velocity.tools.generic">CollectionTool</a></h3>
<code><a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.PropertiesComparator.html" title="class in org.apache.velocity.tools.generic">CollectionTool.PropertiesComparator</a></code></li>
</ul>
</li>
</ul>
<!-- =========== FIELD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="field.summary">
<!-- -->
</a>
<h3>Field Summary</h3>
<ul class="blockList">
<li class="blockList"><a name="fields.inherited.from.class.org.apache.velocity.tools.generic.CollectionTool">
<!-- -->
</a>
<h3>Fields inherited from class&nbsp;org.apache.velocity.tools.generic.<a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html" title="class in org.apache.velocity.tools.generic">CollectionTool</a></h3>
<code><a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#DEFAULT_STRINGS_DELIMITER">DEFAULT_STRINGS_DELIMITER</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#DEFAULT_STRINGS_TRIM">DEFAULT_STRINGS_TRIM</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#STRINGS_DELIMITER_FORMAT_KEY">STRINGS_DELIMITER_FORMAT_KEY</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#STRINGS_TRIM_KEY">STRINGS_TRIM_KEY</a></code></li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="fields.inherited.from.class.org.apache.velocity.tools.generic.SafeConfig">
<!-- -->
</a>
<h3>Fields inherited from class&nbsp;org.apache.velocity.tools.generic.<a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html" title="class in org.apache.velocity.tools.generic">SafeConfig</a></h3>
<code><a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#LOCK_CONFIG_KEY">LOCK_CONFIG_KEY</a>, <a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#log">log</a>, <a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#LOGGER_NAME_KEY">LOGGER_NAME_KEY</a>, <a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#SAFE_MODE_KEY">SAFE_MODE_KEY</a>, <a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#USE_CLASS_LOGGER_KEY">USE_CLASS_LOGGER_KEY</a></code></li>
</ul>
</li>
</ul>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><span class="memberNameLink"><a href="../../../../../org/apache/velocity/tools/generic/SortTool.html#SortTool--">SortTool</a></span>()</code>
<div class="block"><span class="deprecatedLabel">Deprecated.</span>&nbsp;</div>
&nbsp;</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.org.apache.velocity.tools.generic.CollectionTool">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;org.apache.velocity.tools.generic.<a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html" title="class in org.apache.velocity.tools.generic">CollectionTool</a></h3>
<code><a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#configure-org.apache.velocity.tools.generic.ValueParser-">configure</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#getComparable-java.lang.Object-java.lang.String-">getComparable</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#getStringsDelimiter--">getStringsDelimiter</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#getStringsTrim--">getStringsTrim</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#internalSort-java.util.List-java.util.List-">internalSort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#setStringsDelimiter-java.lang.String-">setStringsDelimiter</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#setStringsTrim-boolean-">setStringsTrim</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.util.Collection-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.util.Collection-java.util.Comparator-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.util.Collection-java.util.List-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.util.Map-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.util.Map-java.util.Comparator-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.util.Map-java.util.List-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.lang.Object-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.lang.Object:A-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.lang.Object:A-java.util.List-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.lang.Object-java.util.Comparator-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-java.lang.Object-java.lang.String-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#sort-T:A-java.util.Comparator-">sort</a>, <a href="../../../../../org/apache/velocity/tools/generic/CollectionTool.html#split-java.lang.String-">split</a></code></li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.org.apache.velocity.tools.generic.SafeConfig">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;org.apache.velocity.tools.generic.<a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html" title="class in org.apache.velocity.tools.generic">SafeConfig</a></h3>
<code><a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#configure-java.util.Map-">configure</a>, <a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#getLog--">getLog</a>, <a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#initLogger-org.apache.velocity.tools.generic.ValueParser-">initLogger</a>, <a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#isConfigLocked--">isConfigLocked</a>, <a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#isSafeMode--">isSafeMode</a>, <a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#setLockConfig-boolean-">setLockConfig</a>, <a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html#setSafeMode-boolean-">setSafeMode</a></code></li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></h3>
<code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#clone--" title="class or interface in java.lang">clone</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#equals-java.lang.Object-" title="class or interface in java.lang">equals</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#finalize--" title="class or interface in java.lang">finalize</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#getClass--" title="class or interface in java.lang">getClass</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#hashCode--" title="class or interface in java.lang">hashCode</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notify--" title="class or interface in java.lang">notify</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notifyAll--" title="class or interface in java.lang">notifyAll</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#toString--" title="class or interface in java.lang">toString</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait--" title="class or interface in java.lang">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait-long-" title="class or interface in java.lang">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait-long-int-" title="class or interface in java.lang">wait</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="SortTool--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>SortTool</h4>
<pre>public&nbsp;SortTool()</pre>
<div class="block"><span class="deprecatedLabel">Deprecated.</span>&nbsp;</div>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/SortTool.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/velocity/tools/generic/SafeConfig.html" title="class in org.apache.velocity.tools.generic"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../org/apache/velocity/tools/generic/ValueParser.html" title="class in org.apache.velocity.tools.generic"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/velocity/tools/generic/SortTool.html" target="_top">Frames</a></li>
<li><a href="SortTool.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li><a href="#nested.classes.inherited.from.class.org.apache.velocity.tools.generic.CollectionTool">Nested</a>&nbsp;|&nbsp;</li>
<li><a href="#fields.inherited.from.class.org.apache.velocity.tools.generic.CollectionTool">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#methods.inherited.from.class.org.apache.velocity.tools.generic.CollectionTool">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li>Method</li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright &#169; 2002&#x2013;2018 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p>
</body>
</html>