1 16 package com.blandware.atleap.common.util; 17 18 import org.apache.commons.lang.builder.ToStringBuilder; 19 import org.apache.commons.lang.builder.ToStringStyle; 20 21 import java.io.Serializable ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 35 public class PartialCollection implements Collection , Serializable { 36 37 40 private Collection collection; 41 42 45 private Integer total; 46 47 53 public PartialCollection(Collection collection, int total) { 54 this(collection, new Integer (total)); 55 } 56 57 60 public PartialCollection() { 61 this(new ArrayList (), 0); 62 } 63 64 70 public PartialCollection(Collection collection, Integer total) { 71 this.collection = collection; 72 this.total = total; 73 } 74 75 80 public List asList() { 81 List result = null; 82 if ( collection != null ) { 83 if ( !(collection instanceof List ) ) { 84 result = new ArrayList (collection); 85 } else { 86 result = (List ) collection; 87 } 88 } 89 return result; 90 } 91 92 97 public int size() { 98 return collection.size(); 99 } 100 101 104 public void clear() { 105 collection.clear(); 106 } 107 108 113 public boolean isEmpty() { 114 return collection.isEmpty(); 115 } 116 117 public Object [] toArray() { 118 return collection.toArray(); 119 } 120 121 public boolean add(Object o) { 122 return collection.add(o); 123 } 124 125 public boolean contains(Object o) { 126 return collection.contains(o); 127 } 128 129 public boolean remove(Object o) { 130 return collection.remove(o); 131 } 132 133 public boolean addAll(Collection c) { 134 return collection.addAll(c); 135 } 136 137 public boolean containsAll(Collection c) { 138 return collection.containsAll(c); 139 } 140 141 public boolean removeAll(Collection c) { 142 return collection.removeAll(c); 143 } 144 145 public boolean retainAll(Collection c) { 146 return collection.retainAll(c); 147 } 148 149 public Iterator iterator() { 150 return collection.iterator(); 151 } 152 153 public Object [] toArray(Object [] a) { 154 return collection.toArray(a); 155 } 156 157 162 public Integer getTotal() { 163 return total; 164 } 165 166 179 public String toString() { 180 return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); 181 } 182 } 183 | Popular Tags |