View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.lookup;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Iterator;
22  import java.util.List;
23  import java.util.ListIterator;
24  import java.util.RandomAccess;
25  
26  /**
27   * Wraps a {@link List} and if truncated keeps the complete size
28   *
29   * @param <T> list item type
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class CollectionIncomplete<T> implements List<T>, RandomAccess, Serializable {
33      private static final long serialVersionUID = 8683452581122892189L;
34  
35      private final List<T> list;
36      private Long actualSizeIfTruncated;
37  
38      /**
39       * Collection that may be incomplete/truncated.
40       *
41       * @param collection collection instance to be wrapped
42       * @param actualSizeIfTruncated the actual collection size before truncation.  Zero if the collection is not
43       * truncated.
44       */
45      public CollectionIncomplete(Collection<T> collection, Long actualSizeIfTruncated) {
46          super();
47  
48          this.list = new ArrayList<T>(collection);
49          this.actualSizeIfTruncated = actualSizeIfTruncated;
50      }
51  
52      /**
53       * @see java.util.List#add(int, Object)
54       */
55      public void add(int arg0, T arg1) {
56          list.add(arg0, arg1);
57      }
58  
59      /**
60       * @see java.util.List#add(Object)
61       */
62      public boolean add(T arg0) {
63          return list.add(arg0);
64      }
65  
66      /**
67       * @see java.util.List#addAll(int, java.util.Collection)
68       */
69      public boolean addAll(int arg0, Collection<? extends T> arg1) {
70          return list.addAll(arg0, arg1);
71      }
72  
73      /**
74       * @see java.util.List#addAll(java.util.Collection)
75       */
76      public boolean addAll(Collection<? extends T> arg0) {
77          return list.addAll(arg0);
78      }
79  
80      /**
81       * @see java.util.List#clear()
82       */
83      public void clear() {
84          list.clear();
85      }
86  
87      /**
88       * @see java.util.List#contains(Object)
89       */
90      public boolean contains(Object arg0) {
91          return list.contains(arg0);
92      }
93  
94      /**
95       * @see java.util.List#containsAll(java.util.Collection)
96       */
97      public boolean containsAll(Collection<?> arg0) {
98          return list.containsAll(arg0);
99      }
100 
101     /**
102      * @see java.util.List#equals(Object)
103      */
104     public boolean equals(Object arg0) {
105         return list.equals(arg0);
106     }
107 
108     /**
109      * @see java.util.List#get(int)
110      */
111     public T get(int arg0) {
112         return list.get(arg0);
113     }
114 
115     /**
116      * @see java.util.List#hashCode()
117      */
118     public int hashCode() {
119         return list.hashCode();
120     }
121 
122     /**
123      * @see java.util.List#indexOf(Object)
124      */
125     public int indexOf(Object arg0) {
126         return list.indexOf(arg0);
127     }
128 
129     /**
130      * @see java.util.List#isEmpty()
131      */
132     public boolean isEmpty() {
133         return list.isEmpty();
134     }
135 
136     /**
137      * @see java.util.List#iterator()
138      */
139     public Iterator<T> iterator() {
140         return list.iterator();
141     }
142 
143     /**
144      * @see java.util.List#lastIndexOf(Object)
145      */
146     public int lastIndexOf(Object arg0) {
147         return list.lastIndexOf(arg0);
148     }
149 
150     /**
151      * @see java.util.List#listIterator()
152      */
153     public ListIterator<T> listIterator() {
154         return list.listIterator();
155     }
156 
157     /**
158      * @see java.util.List#listIterator(int)
159      */
160     public ListIterator listIterator(int arg0) {
161         return list.listIterator(arg0);
162     }
163 
164     /**
165      * @see java.util.List#remove(int)
166      */
167     public T remove(int arg0) {
168         return list.remove(arg0);
169     }
170 
171     /**
172      * @see java.util.List#remove(Object)
173      */
174     public boolean remove(Object arg0) {
175         return list.remove(arg0);
176     }
177 
178     /**
179      * @see java.util.List#removeAll(java.util.Collection)
180      */
181     public boolean removeAll(Collection<?> arg0) {
182         return list.removeAll(arg0);
183     }
184 
185     /**
186      * @see java.util.List#retainAll(java.util.Collection)
187      */
188     public boolean retainAll(Collection<?> arg0) {
189         return list.retainAll(arg0);
190     }
191 
192     /**
193      * @see java.util.List#set(int, Object)
194      */
195     public T set(int arg0, T arg1) {
196         return list.set(arg0, arg1);
197     }
198 
199     /**
200      * @see java.util.List#size()
201      */
202     public int size() {
203         return list.size();
204     }
205 
206     /**
207      * @see java.util.List#subList(int, int)
208      */
209     public List<T> subList(int arg0, int arg1) {
210         return list.subList(arg0, arg1);
211     }
212 
213     /**
214      * @see java.util.List#toArray()
215      */
216     public Object[] toArray() {
217         return list.toArray();
218     }
219 
220     /**
221      * @see java.util.List#toArray(Object[])
222      */
223     public <T> T[] toArray(T[] arg0) {
224         return list.toArray(arg0);
225     }
226 
227     /**
228      * @see java.util.List#toString()
229      */
230     public String toString() {
231         return list.toString();
232     }
233 
234     /**
235      * Get the actual collection size if the collection was truncated
236      *
237      * <p>
238      * For non-truncated collection the <code>getActualSizeIfTruncated</code> is zero.
239      * </p>
240      *
241      * @return Returns the actualSizeIfTruncated.
242      */
243     public Long getActualSizeIfTruncated() {
244         return actualSizeIfTruncated;
245     }
246 
247     /**
248      * Set the actual collection size if the collection was truncated
249      *
250      * @param actualSizeIfTruncated The actualSizeIfTruncated to set.
251      */
252     public void setActualSizeIfTruncated(Long actualSizeIfTruncated) {
253         this.actualSizeIfTruncated = actualSizeIfTruncated;
254     }
255 }