01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10:
11: package org.mmbase.util;
12:
13: import java.util.*;
14:
15: /**
16: * Simple utility to chain several lists into a new one.
17: *
18: * @author Michiel Meeuwissen
19: * @since MMBase-1.9
20: * @version $Id: ChainedList.java,v 1.3 2007/12/05 20:39:35 michiel Exp $
21: * @see ChainedIterator
22: */
23: public class ChainedList<E> extends AbstractList<E> {
24:
25: private final List<List<? extends E>> lists = new ArrayList<List<? extends E>>();
26:
27: public ChainedList(List<? extends E>... ls) {
28: for (List<? extends E> l : ls) {
29: addList(l);
30: }
31: }
32:
33: public ChainedList<E> addList(List<? extends E> l) {
34: lists.add(l);
35: return this ;
36: }
37:
38: public int size() {
39: int size = 0;
40: for (List<? extends E> l : lists) {
41: size += l.size();
42: }
43: return size;
44: }
45:
46: public E get(int i) {
47: for (List<? extends E> l : lists) {
48: if (l.size() > i) {
49: return l.get(i);
50: }
51: i -= l.size();
52: }
53: throw new IndexOutOfBoundsException();
54: }
55:
56: }
|