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:
mdb
2006-01-17 00:18:02 +00:00
parent e2d440a121
commit 54e0c7db9c
@@ -5,6 +5,14 @@ package com.samskivert.velocity;
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.
*/
@@ -52,4 +60,39 @@ public class DataTool
{
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;
}
}