View Javadoc

1   package net.sf.mmapps.commons.bridge;
2   
3   import java.util.ArrayList;
4   import java.util.Collections;
5   import java.util.Comparator;
6   import java.util.HashMap;
7   import java.util.Map;
8   
9   import org.mmbase.bridge.Node;
10  import org.mmbase.bridge.NodeIterator;
11  import org.mmbase.bridge.NodeList;
12  
13  
14  
15  /***
16   * Generic node list to use extend MMbase node lists with properties
17   * 
18   * @author Nico Klasens (Finalist IT Group)
19   * @version $Id: GenericNodeList.java,v 1.1 2006/04/06 10:00:34 nklasens Exp $
20   */
21  public class GenericNodeList extends ArrayList implements NodeList {
22     private Map prop = new HashMap();
23  
24     /***
25      * @see org.mmbase.bridge.NodeList#getNode(int)
26      */
27     public Node getNode(int index) {
28        return (Node) get(index);
29     }
30  
31     /***
32      * @see org.mmbase.bridge.NodeList#nodeIterator()
33      */
34     public NodeIterator nodeIterator() {
35        return new GenericNodeIterator(listIterator());
36     }
37  
38     /***
39      * @see org.mmbase.bridge.NodeList#subNodeList(int, int)
40      */
41     public NodeList subNodeList(int fromIndex, int toIndex) {
42        GenericNodeList b = new GenericNodeList();
43        b.addAll(subList(fromIndex, toIndex));
44  
45        return b;
46     }
47  
48     /***
49      * @see org.mmbase.bridge.BridgeList#getProperty(java.lang.Object)
50      */
51     public Object getProperty(Object key) {
52        return prop.get(key);
53     }
54  
55     /***
56      * @see org.mmbase.bridge.BridgeList#setProperty(java.lang.Object, java.lang.Object)
57      */
58     public void setProperty(Object key, Object val) {
59        prop.put(key, val);
60     }
61  
62     /***
63      * @see org.mmbase.bridge.BridgeList#sort()
64      */
65     public void sort() {
66        // do nothing..
67     }
68  
69     /***
70      * @see org.mmbase.bridge.BridgeList#sort(java.util.Comparator)
71      */
72     public void sort(Comparator comp) {
73        Collections.sort(this, comp);
74     }
75  }