| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.owasp.dependencycheck.org.apache.tools.ant.util; |
| 19 | |
|
| 20 | |
import java.util.Collection; |
| 21 | |
import java.util.HashSet; |
| 22 | |
import java.util.LinkedList; |
| 23 | |
import java.util.Set; |
| 24 | |
import java.util.Vector; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public final class VectorSet<E> extends Vector<E> { |
| 41 | |
private static final long serialVersionUID = 1L; |
| 42 | |
|
| 43 | 64 | private final HashSet<E> set = new HashSet<E>(); |
| 44 | |
|
| 45 | 128 | public VectorSet() { super(); } |
| 46 | |
|
| 47 | 0 | public VectorSet(int initialCapacity) { super(initialCapacity); } |
| 48 | |
|
| 49 | |
public VectorSet(int initialCapacity, int capacityIncrement) { |
| 50 | 0 | super(initialCapacity, capacityIncrement); |
| 51 | 0 | } |
| 52 | |
|
| 53 | 0 | public VectorSet(Collection<? extends E> c) { |
| 54 | 0 | if (c != null) { |
| 55 | 0 | for (E e : c) { |
| 56 | 0 | add(e); |
| 57 | 0 | } |
| 58 | |
} |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
public synchronized boolean add(E o) { |
| 62 | 160 | if (!set.contains(o)) { |
| 63 | 160 | doAdd(size(), o); |
| 64 | 160 | return true; |
| 65 | |
} |
| 66 | 0 | return false; |
| 67 | |
} |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
public void add(int index, E o) { |
| 74 | 0 | doAdd(index, o); |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
private synchronized void doAdd(int index, E o) { |
| 78 | |
|
| 79 | |
|
| 80 | 168 | if (set.add(o)) { |
| 81 | 168 | int count = size(); |
| 82 | 168 | ensureCapacity(count + 1); |
| 83 | 168 | if (index != count) { |
| 84 | 0 | System.arraycopy(elementData, index, elementData, index + 1, |
| 85 | |
count - index); |
| 86 | |
} |
| 87 | 168 | elementData[index] = o; |
| 88 | 168 | elementCount++; |
| 89 | |
} |
| 90 | 168 | } |
| 91 | |
|
| 92 | |
public synchronized void addElement(E o) { |
| 93 | 8 | doAdd(size(), o); |
| 94 | 8 | } |
| 95 | |
|
| 96 | |
public synchronized boolean addAll(Collection<? extends E> c) { |
| 97 | 0 | boolean changed = false; |
| 98 | 0 | for (E e : c) { |
| 99 | 0 | changed |= add(e); |
| 100 | 0 | } |
| 101 | 0 | return changed; |
| 102 | |
} |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public synchronized boolean addAll(int index, Collection<? extends E> c) { |
| 109 | 0 | LinkedList toAdd = new LinkedList(); |
| 110 | 0 | for (E e : c) { |
| 111 | 0 | if (set.add(e)) { |
| 112 | 0 | toAdd.add(e); |
| 113 | |
} |
| 114 | 0 | } |
| 115 | 0 | if (toAdd.isEmpty()) { |
| 116 | 0 | return false; |
| 117 | |
} |
| 118 | 0 | int count = size(); |
| 119 | 0 | ensureCapacity(count + toAdd.size()); |
| 120 | 0 | if (index != count) { |
| 121 | 0 | System.arraycopy(elementData, index, elementData, index + toAdd.size(), |
| 122 | |
count - index); |
| 123 | |
} |
| 124 | 0 | for (Object o : toAdd) { |
| 125 | 0 | elementData[index++] = o; |
| 126 | 0 | } |
| 127 | 0 | elementCount += toAdd.size(); |
| 128 | 0 | return true; |
| 129 | |
} |
| 130 | |
|
| 131 | |
public synchronized void clear() { |
| 132 | 0 | super.clear(); |
| 133 | 0 | set.clear(); |
| 134 | 0 | } |
| 135 | |
|
| 136 | |
public Object clone() { |
| 137 | |
@SuppressWarnings("unchecked") |
| 138 | 0 | final VectorSet<E> vs = (VectorSet<E>) super.clone(); |
| 139 | 0 | vs.set.addAll(set); |
| 140 | 0 | return vs; |
| 141 | |
} |
| 142 | |
|
| 143 | |
public synchronized boolean contains(Object o) { |
| 144 | 480 | return set.contains(o); |
| 145 | |
} |
| 146 | |
|
| 147 | |
public synchronized boolean containsAll(Collection<?> c) { |
| 148 | 0 | return set.containsAll(c); |
| 149 | |
} |
| 150 | |
|
| 151 | |
public void insertElementAt(E o, int index) { |
| 152 | 0 | doAdd(index, o); |
| 153 | 0 | } |
| 154 | |
|
| 155 | |
public synchronized E remove(int index) { |
| 156 | 0 | E o = get(index); |
| 157 | 0 | remove(o); |
| 158 | 0 | return o; |
| 159 | |
} |
| 160 | |
|
| 161 | |
public boolean remove(Object o) { |
| 162 | 0 | return doRemove(o); |
| 163 | |
} |
| 164 | |
|
| 165 | |
private synchronized boolean doRemove(Object o) { |
| 166 | |
|
| 167 | |
|
| 168 | 0 | if (set.remove(o)) { |
| 169 | 0 | int index = indexOf(o); |
| 170 | 0 | if (index < elementData.length - 1) { |
| 171 | 0 | System.arraycopy(elementData, index + 1, elementData, index, |
| 172 | |
elementData.length - index - 1); |
| 173 | |
} |
| 174 | 0 | elementCount--; |
| 175 | 0 | return true; |
| 176 | |
} |
| 177 | 0 | return false; |
| 178 | |
} |
| 179 | |
|
| 180 | |
public synchronized boolean removeAll(Collection<?> c) { |
| 181 | 0 | boolean changed = false; |
| 182 | 0 | for (Object o : c) { |
| 183 | 0 | changed |= remove(o); |
| 184 | 0 | } |
| 185 | 0 | return changed; |
| 186 | |
} |
| 187 | |
|
| 188 | |
public synchronized void removeAllElements() { |
| 189 | 0 | set.clear(); |
| 190 | 0 | super.removeAllElements(); |
| 191 | 0 | } |
| 192 | |
|
| 193 | |
public boolean removeElement(Object o) { |
| 194 | 0 | return doRemove(o); |
| 195 | |
} |
| 196 | |
|
| 197 | |
public synchronized void removeElementAt(int index) { |
| 198 | 0 | remove(get(index)); |
| 199 | 0 | } |
| 200 | |
|
| 201 | |
public synchronized void removeRange(final int fromIndex, int toIndex) { |
| 202 | 0 | while (toIndex > fromIndex) { |
| 203 | 0 | remove(--toIndex); |
| 204 | |
} |
| 205 | 0 | } |
| 206 | |
|
| 207 | |
public synchronized boolean retainAll(Collection<?> c) { |
| 208 | 0 | if (!(c instanceof Set)) { |
| 209 | 0 | c = new HashSet<Object>(c); |
| 210 | |
} |
| 211 | 0 | LinkedList<E> l = new LinkedList<E>(); |
| 212 | 0 | for (E o : this) { |
| 213 | 0 | if (!c.contains(o)) { |
| 214 | 0 | l.addLast(o); |
| 215 | |
} |
| 216 | 0 | } |
| 217 | 0 | if (!l.isEmpty()) { |
| 218 | 0 | removeAll(l); |
| 219 | 0 | return true; |
| 220 | |
} |
| 221 | 0 | return false; |
| 222 | |
} |
| 223 | |
|
| 224 | |
public synchronized E set(int index, E o) { |
| 225 | 0 | E orig = get(index); |
| 226 | 0 | if (set.add(o)) { |
| 227 | 0 | elementData[index] = o; |
| 228 | 0 | set.remove(orig); |
| 229 | |
} else { |
| 230 | 0 | int oldIndexOfO = indexOf(o); |
| 231 | 0 | remove(o); |
| 232 | 0 | remove(orig); |
| 233 | 0 | add(oldIndexOfO > index ? index : index - 1, o); |
| 234 | |
} |
| 235 | 0 | return orig; |
| 236 | |
} |
| 237 | |
|
| 238 | |
public void setElementAt(E o, int index) { |
| 239 | 0 | set(index, o); |
| 240 | 0 | } |
| 241 | |
|
| 242 | |
} |