View Javadoc
1   /**
2    * Copyright 2005-2016 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   * A {@link Collection} that may be truncated
28   *
29   * @param <T> The type that the collection stores internally
30   */
31  public class CollectionIncomplete<T> implements List<T>, RandomAccess, Serializable {
32  
33      private static final long serialVersionUID = 8683452581122892189L;
34  	private final List<T> list;
35      private Long actualSizeIfTruncated;
36  
37  
38      /**
39       * Collection that may be incomplete/truncated
40       *
41       * @param collection
42       * @param actualSizeIfTruncated the actual collection size before truncation.  Zero if the collection is not truncated.
43       */
44      public CollectionIncomplete(Collection<T> collection, Long actualSizeIfTruncated) {
45          super();
46          this.list = new ArrayList<T>(collection);
47          this.actualSizeIfTruncated = actualSizeIfTruncated;
48      }
49  
50      /**
51       * @see java.util.List#add(int, Object)
52       */
53      public void add(int arg0, T arg1) {
54          list.add(arg0, arg1);
55      }
56  
57      /**
58       * @see java.util.List#add(Object)
59       */
60      public boolean add(T arg0) {
61          return list.add(arg0);
62      }
63  
64      /**
65       * @see java.util.List#addAll(int, java.util.Collection)
66       */
67      public boolean addAll(int arg0, Collection<? extends T> arg1) {
68          return list.addAll(arg0, arg1);
69      }
70  
71      /**
72       * @see java.util.List#addAll(java.util.Collection)
73       */
74      public boolean addAll(Collection<? extends T> arg0) {
75          return list.addAll(arg0);
76      }
77  
78      /**
79       * @see java.util.List#clear()
80       */
81      public void clear() {
82          list.clear();
83      }
84  
85      /**
86       * @see java.util.List#contains(Object)
87       */
88      public boolean contains(Object arg0) {
89          return list.contains(arg0);
90      }
91  
92      /**
93       *  @see java.util.List#containsAll(java.util.Collection)
94       */
95      public boolean containsAll(Collection<?> arg0) {
96          return list.containsAll(arg0);
97      }
98  
99      /**
100      * @see java.util.List#equals(Object)
101      */
102     public boolean equals(Object arg0) {
103         return list.equals(arg0);
104     }
105 
106     /**
107      * @see java.util.List#get(int)
108      */
109     public T get(int arg0) {
110         return list.get(arg0);
111     }
112 
113     /**
114      * @see java.util.List#hashCode()
115      */
116     public int hashCode() {
117         return list.hashCode();
118     }
119 
120     /**
121      * @see java.util.List#indexOf(Object)
122      */
123     public int indexOf(Object arg0) {
124         return list.indexOf(arg0);
125     }
126 
127     /**
128      * @see java.util.List#isEmpty()
129      */
130     public boolean isEmpty() {
131         return list.isEmpty();
132     }
133 
134     /**
135      * @see java.util.List#iterator()
136      */
137     public Iterator<T> iterator() {
138         return list.iterator();
139     }
140 
141     /**
142      * @see java.util.List#lastIndexOf(Object)
143      */
144     public int lastIndexOf(Object arg0) {
145         return list.lastIndexOf(arg0);
146     }
147 
148     /**
149      * @see java.util.List#listIterator()
150      */
151     public ListIterator<T> listIterator() {
152         return list.listIterator();
153     }
154 
155     /**
156      * @see java.util.List#listIterator(int)
157      */
158     public ListIterator listIterator(int arg0) {
159         return list.listIterator(arg0);
160     }
161 
162     /**
163      * @see java.util.List#remove(int)
164      */
165     public T remove(int arg0) {
166         return list.remove(arg0);
167     }
168 
169     /**
170      * @see java.util.List#remove(Object)
171      */
172     public boolean remove(Object arg0) {
173         return list.remove(arg0);
174     }
175 
176     /**
177      * @see java.util.List#removeAll(java.util.Collection)
178      */
179     public boolean removeAll(Collection<?> arg0) {
180         return list.removeAll(arg0);
181     }
182 
183     /**
184      * @see java.util.List#retainAll(java.util.Collection)
185      */
186     public boolean retainAll(Collection<?> arg0) {
187         return list.retainAll(arg0);
188     }
189 
190     /**
191      * @see java.util.List#set(int, Object)
192      */
193     public T set(int arg0, T arg1) {
194         return list.set(arg0, arg1);
195     }
196 
197     /**
198      * @see java.util.List#size()
199      */
200     public int size() {
201         return list.size();
202     }
203 
204     /**
205      * @see java.util.List#subList(int, int)
206      */
207     public List<T> subList(int arg0, int arg1) {
208         return list.subList(arg0, arg1);
209     }
210 
211     /**
212      * @see java.util.List#toArray()
213      */
214     public Object[] toArray() {
215         return list.toArray();
216     }
217 
218     /**
219      * @see java.util.List#toArray(Object[])
220      */
221     public <T> T[] toArray(T[] arg0) {
222         return list.toArray(arg0);
223     }
224 
225     /**
226      * @see java.util.List#toString()
227      */
228     public String toString() {
229         return list.toString();
230     }
231 
232     /**
233      * Get the actual collection size if the collection was truncated
234      *
235      * <p>
236      * For non-truncated collection the <code>getActualSizeIfTruncated</code> is zero.
237      * </p>
238      *
239      * @return Returns the actualSizeIfTruncated.
240      */
241     public Long getActualSizeIfTruncated() {
242         return actualSizeIfTruncated;
243     }
244 
245     /**
246      * Set the actual collection size if the collection was truncated
247      *
248      * @param actualSizeIfTruncated The actualSizeIfTruncated to set.
249      */
250     public void setActualSizeIfTruncated(Long actualSizeIfTruncated) {
251         this.actualSizeIfTruncated = actualSizeIfTruncated;
252     }
253 }