1 28 29 package com.caucho.util; 30 31 import java.util.AbstractSet ; 32 import java.util.ArrayList ; 33 import java.util.Collection ; 34 import java.util.Iterator ; 35 36 40 public class LifoSet<E> extends AbstractSet <E> { 41 private final ArrayList <E> _list = new ArrayList <E>(); 42 43 46 public int size() 47 { 48 return _list.size(); 49 } 50 51 54 public boolean isEmpty() 55 { 56 return _list.isEmpty(); 57 } 58 59 62 public boolean add(E o) 63 { 64 if (! _list.contains(o)) { 65 _list.add(0, o); 66 return true; 67 } 68 else 69 return false; 70 } 71 72 75 public void clear() 76 { 77 _list.clear(); 78 } 79 80 83 public boolean contains(Object o) 84 { 85 return _list.contains(o); 86 } 87 88 91 public boolean containsAll(Collection <?> c) 92 { 93 return _list.containsAll(c); 94 } 95 96 99 public Iterator <E> iterator() 100 { 101 return _list.iterator(); 102 } 103 104 107 public boolean remove(Object o) 108 { 109 return _list.remove(o); 110 } 111 112 115 public boolean removeAll(Collection <?> c) 116 { 117 return _list.removeAll(c); 118 } 119 120 123 public boolean retainAll(Collection <?> c) 124 { 125 return _list.retainAll(c); 126 } 127 128 131 public Object []toArray() 132 { 133 return _list.toArray(); 134 } 135 136 139 public <T> T[] toArray(T[] a) 140 { 141 return _list.toArray(a); 142 } 143 144 147 public int hashCode() 148 { 149 return _list.hashCode(); 150 } 151 152 155 public boolean equals(Object o) 156 { 157 if (this == o) 158 return true; 159 else if (! (o instanceof LifoSet)) 160 return false; 161 162 LifoSet set = (LifoSet) o; 163 164 return _list.equals(set._list); 165 } 166 } 167 | Popular Tags |