Added routines for sorting lists, collections and iterator contents.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1761 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -5,6 +5,14 @@ package com.samskivert.velocity;
|
|||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.samskivert.util.CollectionUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some helpful methods for dealing with data in velocity.
|
* Some helpful methods for dealing with data in velocity.
|
||||||
*/
|
*/
|
||||||
@@ -52,4 +60,39 @@ public class DataTool
|
|||||||
{
|
{
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts the supplied list and returns it. The elements <em>must</em>
|
||||||
|
* implement {@link Comparable}.
|
||||||
|
*/
|
||||||
|
public List sort (List list)
|
||||||
|
{
|
||||||
|
Collections.sort(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the data from the supplied collection into a list, sorts it and
|
||||||
|
* returns the list. The elements <em>must</em> implement {@link
|
||||||
|
* Comparable}.
|
||||||
|
*/
|
||||||
|
public List sort (Collection data)
|
||||||
|
{
|
||||||
|
ArrayList list = new ArrayList(data);
|
||||||
|
Collections.sort(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the data from the supplied iterator into a list, sorts it and
|
||||||
|
* returns the list. The elements <em>must</em> implement {@link
|
||||||
|
* Comparable}.
|
||||||
|
*/
|
||||||
|
public List sort (Iterator iter)
|
||||||
|
{
|
||||||
|
ArrayList list = new ArrayList();
|
||||||
|
CollectionUtil.addAll(list, iter);
|
||||||
|
Collections.sort(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user