FileDocCategorySizeDatePackage
SortIteratorFilter.javaAPI DocExample3394Mon Jul 23 13:26:56 BST 2007org.apache.struts2.util

SortIteratorFilter

public class SortIteratorFilter extends IteratorFilterSupport implements com.opensymphony.xwork2.Action, Iterator
A bean that takes a source and comparator then attempt to sort the source utilizing the comparator. It is being used in SortIteratorTag.
see
org.apache.struts2.views.jsp.iterator.SortIteratorTag

Fields Summary
Comparator
comparator
Iterator
iterator
List
list
Object
source
Constructors Summary
Methods Summary
public java.lang.Stringexecute()

        if (source == null) {
            return ERROR;
        } else {
            try {
                if (!MakeIterator.isIterable(source)) {
                    LogFactory.getLog(SortIteratorFilter.class.getName()).warn("Cannot create SortIterator for source " + source);

                    return ERROR;
                }

                list = new ArrayList();

                Iterator i = MakeIterator.convert(source);

                while (i.hasNext()) {
                    list.add(i.next());
                }

                // Sort it
                Collections.sort(list, comparator);
                iterator = list.iterator();

                return SUCCESS;
            } catch (Exception e) {
                LogFactory.getLog(SortIteratorFilter.class.getName()).warn("Error creating sort iterator.", e);

                return ERROR;
            }
        }
    
public java.util.ListgetList()

        return list;
    
public booleanhasNext()

        return (source == null) ? false : iterator.hasNext();
    
public java.lang.Objectnext()

        return iterator.next();
    
public voidremove()

        throw new UnsupportedOperationException("Remove is not supported in SortIteratorFilter.");
    
public voidsetComparator(java.util.Comparator aComparator)

        this.comparator = aComparator;
    
public voidsetSource(java.lang.Object anIterator)

        source = anIterator;