001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.lookup; 017 018import java.io.Serializable; 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.Iterator; 022import java.util.List; 023import java.util.ListIterator; 024import java.util.RandomAccess; 025 026/** 027 * Wraps a {@link List} and if truncated keeps the complete size 028 * 029 * @param <T> list item type 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032public class CollectionIncomplete<T> implements List<T>, RandomAccess, Serializable { 033 private static final long serialVersionUID = 8683452581122892189L; 034 035 private final List<T> list; 036 private Long actualSizeIfTruncated; 037 038 /** 039 * Collection that may be incomplete/truncated. 040 * 041 * @param collection collection instance to be wrapped 042 * @param actualSizeIfTruncated the actual collection size before truncation. Zero if the collection is not 043 * truncated. 044 */ 045 public CollectionIncomplete(Collection<T> collection, Long actualSizeIfTruncated) { 046 super(); 047 048 this.list = new ArrayList<T>(collection); 049 this.actualSizeIfTruncated = actualSizeIfTruncated; 050 } 051 052 /** 053 * @see java.util.List#add(int, Object) 054 */ 055 public void add(int arg0, T arg1) { 056 list.add(arg0, arg1); 057 } 058 059 /** 060 * @see java.util.List#add(Object) 061 */ 062 public boolean add(T arg0) { 063 return list.add(arg0); 064 } 065 066 /** 067 * @see java.util.List#addAll(int, java.util.Collection) 068 */ 069 public boolean addAll(int arg0, Collection<? extends T> arg1) { 070 return list.addAll(arg0, arg1); 071 } 072 073 /** 074 * @see java.util.List#addAll(java.util.Collection) 075 */ 076 public boolean addAll(Collection<? extends T> arg0) { 077 return list.addAll(arg0); 078 } 079 080 /** 081 * @see java.util.List#clear() 082 */ 083 public void clear() { 084 list.clear(); 085 } 086 087 /** 088 * @see java.util.List#contains(Object) 089 */ 090 public boolean contains(Object arg0) { 091 return list.contains(arg0); 092 } 093 094 /** 095 * @see java.util.List#containsAll(java.util.Collection) 096 */ 097 public boolean containsAll(Collection<?> arg0) { 098 return list.containsAll(arg0); 099 } 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}