KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > media > filters > Sorter


1  /*
2  
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5  
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8  
9  */

10
11 package org.mmbase.applications.media.filters;
12
13 import org.mmbase.applications.media.urlcomposers.URLComposer;
14 import java.util.*;
15 import org.mmbase.util.xml.DocumentReader;
16 import org.w3c.dom.Element JavaDoc;
17
18 /**
19  * Implements a Filter as a Comparator. That means that it only sorts,
20  * and the implementation is done by calling Collections.sort. You can
21  * be sure that no URLComposers are removed during the filter process.
22  *
23  * @author Michiel Meeuwissen
24  */

25 abstract public class Sorter implements Comparator, Filter {
26
27     /**
28      * Implement this.
29      */

30
31     abstract protected int compareURLComposer(URLComposer o1, URLComposer o2);
32     
33     public void configure(DocumentReader reader, Element JavaDoc e) {
34         // nothing to be configured on default.
35
}
36          
37     final public int compare(Object JavaDoc o1, Object JavaDoc o2) {
38         URLComposer ri1 = (URLComposer) o1;
39         URLComposer ri2 = (URLComposer) o2;
40         return compareURLComposer(ri1, ri2);
41     }
42
43     final public List filter(List urlcomposers) {
44         Collections.sort(urlcomposers, this);
45         return urlcomposers;
46     }
47 }
48
49
Popular Tags