KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Chains some comparators to make one new comparator.
20  *
21  * @author Michiel Meeuwissen
22  * @version $Id: ChainSorter.java,v 1.3 2005/07/09 15:29:11 nklasens Exp $
23  */

24 public class ChainSorter extends Sorter {
25
26     private List comparators;
27     public ChainSorter() {
28         comparators = new ArrayList();
29     }
30     /**
31      * Empties the chain
32      */

33     public void clear() {
34         comparators.clear();
35     }
36     /**
37      * Add one filter to the chain
38      */

39     public void add(Sorter ri) {
40         comparators.add(ri);
41     }
42
43     public int size() {
44         return comparators.size();
45     }
46     
47     /**
48      * Configure. Configures all elements on default.
49      */

50     public void configure(DocumentReader reader, Element JavaDoc e) {
51         Iterator i = comparators.iterator();
52         while (i.hasNext()) {
53             Sorter ri = (Sorter) i.next();
54             ri.configure(reader, e);
55         }
56     }
57
58     public int compareURLComposer(URLComposer o1, URLComposer o2) {
59         Iterator i = comparators.iterator();
60         while (i.hasNext()) {
61             int comp = ((Sorter) i.next()).compare(o1, o2);
62             if (comp != 0) return comp;
63         }
64         return 0;
65     }
66 }
67
68
Popular Tags