View Javadoc

1   /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18   *
19   * For further informations on the SmartWeb Framework please visit
20   *
21   *                        http://smartweb.sourceforge.net
22   */
23   
24  package net.smartlab.web.page;
25  
26  import java.util.Collection;
27  import java.util.Iterator;
28  
29  /**
30   * TODO documentation
31   * 
32   * @author rlogiacco
33   */
34  public class CollectionPaginator extends Paginator implements Collection {
35  
36  	private Collection collection;
37  
38  	/**
39  	 * TODO documentation
40  	 * 
41  	 * @param collection
42  	 */
43  	public CollectionPaginator(Collection collection) {
44  		this(collection, 0);
45  	}
46  
47  	/**
48  	 * TODO documentation
49  	 * 
50  	 * @param collection
51  	 * @param size
52  	 */
53  	public CollectionPaginator(Collection collection, int size) {
54  		this(collection, size, Paginator.UNLIMITED_PAGES);
55  	}
56  
57  	/**
58  	 * TODO documentation
59  	 * 
60  	 * @param collection
61  	 * @param size
62  	 * @param pages
63  	 */
64  	public CollectionPaginator(Collection collection, int size, int pages) {
65  		super(size, pages);
66  		super.setCount(collection.size());
67  		this.collection = collection;
68  	}
69  
70  	/**
71  	 * @see net.smartlab.web.Paginator#setArray()
72  	 */
73  	protected void setArray() {
74  		Object[] temp = collection.toArray();
75  		try {
76  			java.lang.System.arraycopy(temp, (super.getPage() - 1) * array.length, array, 0, array.length);
77  		} catch (IndexOutOfBoundsException ioobe) {
78  			java.lang.System.arraycopy(temp, (super.getPage() - 1) * array.length, array, 0, collection.size() % array.length);
79  			array[collection.size() % array.length] = null;
80  		}
81  	}
82  
83  	/**
84  	 * @see java.util.Collection#size()
85  	 */
86  	public int size() {
87  		return collection.size();
88  	}
89  
90  	/**
91  	 * @see java.util.Collection#clear()
92  	 */
93  	public void clear() {
94  		collection.clear();
95  	}
96  
97  	/**
98  	 * @see java.util.Collection#isEmpty()
99  	 */
100 	public boolean isEmpty() {
101 		return collection.isEmpty();
102 	}
103 
104 	/**
105 	 * @see java.util.Collection#toArray()
106 	 */
107 	public Object[] toArray() {
108 		return this.array;
109 	}
110 
111 	/**
112 	 * @see java.util.Collection#add(java.lang.Object)
113 	 */
114 	public boolean add(Object o) {
115 		return collection.add(o);
116 	}
117 
118 	/**
119 	 * @see java.util.Collection#contains(java.lang.Object)
120 	 */
121 	public boolean contains(Object o) {
122 		return collection.contains(o);
123 	}
124 
125 	/**
126 	 * @see java.util.Collection#remove(java.lang.Object)
127 	 */
128 	public boolean remove(Object o) {
129 		return collection.remove(o);
130 	}
131 
132 	/**
133 	 * @see java.util.Collection#addAll(java.util.Collection)
134 	 */
135 	public boolean addAll(Collection c) {
136 		return collection.addAll(c);
137 	}
138 
139 	/**
140 	 * @see java.util.Collection#containsAll(java.util.Collection)
141 	 */
142 	public boolean containsAll(Collection c) {
143 		return collection.containsAll(c);
144 	}
145 
146 	/**
147 	 * @see java.util.Collection#removeAll(java.util.Collection)
148 	 */
149 	public boolean removeAll(Collection c) {
150 		return collection.removeAll(c);
151 	}
152 
153 	/**
154 	 * @see java.util.Collection#retainAll(java.util.Collection)
155 	 */
156 	public boolean retainAll(Collection c) {
157 		return collection.retainAll(c);
158 	}
159 
160 	/**
161 	 * @see java.util.Collection#iterator()
162 	 */
163 	public Iterator iterator() {
164 		return this;
165 	}
166 
167 	/**
168 	 * @see java.util.Collection#toArray(java.lang.Object[])
169 	 */
170 	public Object[] toArray(Object[] a) {
171 		throw new UnsupportedOperationException();
172 	}
173 
174 }