PDFCosArrayList.java 14.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.internal.pdftoolkit.core.cos.CosArray
 *  com.adobe.internal.pdftoolkit.core.cos.CosObject
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
 */
package com.adobe.internal.pdftoolkit.pdf.document;

import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObjectContainer;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public abstract class PDFCosArrayList<V extends PDFCosObjectContainer>
extends PDFCosObject
implements List<V> {
    protected PDFCosArrayList(CosObject cosObject) throws PDFInvalidDocumentException {
        super(cosObject);
        if (!(cosObject instanceof CosArray)) {
            throw new PDFInvalidDocumentException("CosArray expected, found" + cosObject.getClass() + ". Object number of invalid cosObject:" + cosObject.getObjNum());
        }
    }

    protected abstract V itemInstantiator(CosObject var1) throws PDFCosParseException, PDFIOException, PDFInvalidDocumentException, PDFSecurityException;

    @Override
    public int size() {
        return this.getCosArray().size();
    }

    @Override
    public void clear() {
        int i;
        CosObject[] cosObjects = new CosObject[this.size()];
        for (i = 0; i < this.size(); ++i) {
            try {
                cosObjects[i] = this.getCosArray().get(i);
                continue;
            }
            catch (PDFException e) {
                // empty catch block
            }
        }
        for (i = 0; i < this.size(); ++i) {
            try {
                this.getCosArray().remove(cosObjects[i]);
                continue;
            }
            catch (PDFException e) {
                // empty catch block
            }
        }
    }

    @Override
    public boolean isEmpty() {
        return this.size() == 0;
    }

    @Override
    public Object[] toArray() {
        Object[] objects = new Object[this.size()];
        for (int i = 0; i < this.size(); ++i) {
            objects[i] = this.get(i);
        }
        return objects;
    }

    @Override
    public V get(int index) {
        try {
            CosObject cosObj = this.getCosArray().get(index);
            return this.itemInstantiator(cosObj);
        }
        catch (PDFException e) {
            throw new RuntimeException("Error fetching PDFCosObject at index " + index, (Throwable)e);
        }
    }

    @Override
    public V remove(int index) {
        Object obj = this.get(index);
        if (obj == null) {
            return null;
        }
        try {
            this.getCosArray().remove(obj.getPDFCosObject().getCosObject());
        }
        catch (PDFException e) {
            throw new RuntimeException("Error deleting PDFCosObject at index " + index, (Throwable)e);
        }
        return (V)obj;
    }

    @Override
    public void add(int index, V element) {
        CosObject cosObject = element.getPDFCosObject().getCosObject();
        try {
            this.getCosArray().add(index, cosObject);
        }
        catch (PDFException e) {
            IllegalArgumentException newException = new IllegalArgumentException("Error during add to the PDFCosArrayList.");
            newException.initCause((Throwable)e);
            throw newException;
        }
    }

    @Override
    public int indexOf(Object element) {
        if (!(element instanceof PDFCosObjectContainer)) {
            return -1;
        }
        CosObject findThisCosObject = ((PDFCosObjectContainer)element).getPDFCosObject().getCosObject();
        CosArray cosArray = this.getCosArray();
        for (int i = 0; i < cosArray.size(); ++i) {
            try {
                if (findThisCosObject != cosArray.get(i)) continue;
                return i;
            }
            catch (PDFException e) {
                return -1;
            }
        }
        return -1;
    }

    @Override
    public int lastIndexOf(Object o) {
        int curSize = this.size();
        if (o == null) {
            for (int i = curSize - 1; i >= 0; --i) {
                if (this.get(i) != null) continue;
                return i;
            }
        } else {
            for (int i = curSize - 1; i >= 0; --i) {
                if (!o.equals(this.get(i))) continue;
                return i;
            }
        }
        return -1;
    }

    @Override
    public boolean add(V element) {
        CosObject cosObject = element.getPDFCosObject().getCosObject();
        try {
            return this.getCosArray().add(cosObject);
        }
        catch (PDFException e) {
            IllegalArgumentException newException = new IllegalArgumentException("Error during add to the PDFCosArrayList.");
            newException.initCause((Throwable)e);
            throw newException;
        }
    }

    public void addList(PDFCosArrayList<V> list) {
        if (list == null) {
            return;
        }
        Iterator<V> listIter = list.iterator();
        while (listIter.hasNext()) {
            this.add((V)((PDFCosObjectContainer)listIter.next()));
        }
    }

    @Override
    public boolean contains(Object element) {
        if (!(element instanceof PDFCosObjectContainer)) {
            return false;
        }
        CosObject findThisCosObject = ((PDFCosObjectContainer)element).getPDFCosObject().getCosObject();
        CosArray cosArray = this.getCosArray();
        for (int i = 0; i < cosArray.size(); ++i) {
            try {
                if (findThisCosObject != cosArray.get(i)) continue;
                return true;
            }
            catch (PDFException e) {
                // empty catch block
            }
        }
        return false;
    }

    @Override
    public boolean remove(Object element) {
        if (!(element instanceof PDFCosObjectContainer)) {
            return false;
        }
        CosObject cosObject = ((PDFCosObjectContainer)element).getPDFCosObject().getCosObject();
        try {
            return this.getCosArray().remove(cosObject);
        }
        catch (PDFException e) {
            return false;
        }
    }

    @Override
    public boolean addAll(int index, Collection<? extends V> c) {
        Iterator<V> cIter = c.iterator();
        while (cIter.hasNext()) {
            this.add(index++, (V)((PDFCosObjectContainer)cIter.next()));
        }
        return !c.isEmpty();
    }

    @Override
    public boolean addAll(Collection<? extends V> c) {
        return this.addAll(this.size(), c);
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        Iterator<?> e = c.iterator();
        while (e.hasNext()) {
            if (this.contains(e.next())) continue;
            return false;
        }
        return true;
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return this.removeOrRetainAll(c, true);
    }

    private boolean removeOrRetainAll(Collection<?> c, boolean remove) {
        boolean modified = false;
        Iterator<V> e = this.iterator();
        while (e.hasNext()) {
            boolean removeElement = !(c.contains(e.next()) ^ remove);
            if (!removeElement) continue;
            e.remove();
            modified = true;
        }
        return modified;
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return this.removeOrRetainAll(c, false);
    }

    @Override
    public Iterator<V> iterator() {
        return new PDFCosArrayListIterator(this);
    }

    protected Iterator<V> iterator(PDFObjectFilter filter) {
        return new PDFCosArrayFilteredIterator(filter);
    }

    public Iterator<V> iterator(int index) {
        return new PDFCosArrayListIterator(this, index);
    }

    @Override
    public List subList(int fromIndex, int toIndex) {
        return null;
    }

    @Override
    public ListIterator<V> listIterator() {
        return new PDFCosArrayListIterator(this);
    }

    @Override
    public ListIterator<V> listIterator(int index) {
        return new PDFCosArrayListIterator(this, index);
    }

    @Override
    public V set(int index, V element) {
        CosObject cosObject = element.getPDFCosObject().getCosObject();
        try {
            this.getCosArray().set(index, cosObject);
        }
        catch (PDFException e) {
            IllegalArgumentException newException = new IllegalArgumentException("Error during set on the PDFCosArrayList.");
            newException.initCause((Throwable)e);
            throw newException;
        }
        return null;
    }

    @Override
    public Object[] toArray(Object[] objects) {
        if (objects.length < this.size()) {
            objects = (Object[])Array.newInstance(objects.getClass().getComponentType(), this.size());
        }
        for (int i = 0; i < this.size(); ++i) {
            objects[i] = this.get(i);
        }
        return objects;
    }

    /*
     * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
     */
    public class PDFCosArrayListIterator
    implements ListIterator<V> {
        private final ListIterator<CosObject> mIterator;
        final /* synthetic */ PDFCosArrayList this$0;

        PDFCosArrayListIterator(PDFCosArrayList pDFCosArrayList) {
            this.this$0 = pDFCosArrayList;
            this.mIterator = pDFCosArrayList.getCosArray().listIterator();
        }

        PDFCosArrayListIterator(PDFCosArrayList pDFCosArrayList, int index) {
            this.this$0 = pDFCosArrayList;
            this.mIterator = pDFCosArrayList.getCosArray().listIterator();
            while (this.mIterator.hasNext() && index > 0) {
                this.mIterator.next();
                --index;
            }
        }

        public PDFCosArrayListIterator(PDFCosArrayList pDFCosArrayList, CosArray array) {
            this.this$0 = pDFCosArrayList;
            this.mIterator = array.listIterator();
        }

        @Override
        public boolean hasNext() {
            return this.mIterator.hasNext();
        }

        @Override
        public V next() {
            try {
                return this.this$0.itemInstantiator(this.mIterator.next());
            }
            catch (PDFException e) {
                NoSuchElementException newException = new NoSuchElementException("Error during add to the PDFCosArrayList.");
                newException.initCause((Throwable)e);
                throw newException;
            }
        }

        @Override
        public void remove() {
            this.mIterator.remove();
        }

        @Override
        public int nextIndex() {
            return this.mIterator.nextIndex();
        }

        @Override
        public int previousIndex() {
            return this.mIterator.previousIndex();
        }

        @Override
        public boolean hasPrevious() {
            return this.mIterator.hasPrevious();
        }

        @Override
        public V previous() {
            try {
                return this.this$0.itemInstantiator(this.mIterator.previous());
            }
            catch (PDFException e) {
                NoSuchElementException newException = new NoSuchElementException("Error during add to the PDFCosArrayList.");
                newException.initCause((Throwable)e);
                throw newException;
            }
        }

        @Override
        public void add(V o) {
            this.mIterator.add(o.getPDFCosObject().getCosObject());
        }

        @Override
        public void set(V o) {
            this.mIterator.set(o.getPDFCosObject().getCosObject());
        }
    }

    /*
     * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
     */
    private class PDFCosArrayFilteredIterator
    implements Iterator<V> {
        private final PDFObjectFilter mFilter;
        private final ListIterator<CosObject> mIterator;
        private CosObject next;
        private int lastIndex;

        private PDFCosArrayFilteredIterator(PDFObjectFilter filter) {
            this.lastIndex = -1;
            this.mIterator = PDFCosArrayList.this.getCosArray().listIterator();
            this.mFilter = filter;
        }

        @Override
        public boolean hasNext() {
            try {
                if (this.mFilter == null) {
                    return this.mIterator.hasNext();
                }
                if (this.next != null) {
                    return true;
                }
                while (this.mIterator.hasNext()) {
                    this.next = this.mIterator.next();
                    if (!this.mFilter.accept(this.next)) continue;
                    return true;
                }
            }
            catch (PDFException e) {
                throw new RuntimeException((Throwable)e);
            }
            return false;
        }

        @Override
        public V next() {
            try {
                if (this.hasNext()) {
                    CosObject obj = this.next;
                    this.next = null;
                    this.lastIndex = this.mIterator.nextIndex();
                    return PDFCosArrayList.this.itemInstantiator(obj);
                }
                return null;
            }
            catch (PDFException e) {
                NoSuchElementException newException = new NoSuchElementException("Error during next() of the PDFCosArrayList.");
                newException.initCause((Throwable)e);
                throw newException;
            }
        }

        @Override
        public void remove() {
            for (int currentIndex = this.mIterator.nextIndex(); currentIndex > this.lastIndex; --currentIndex) {
                this.mIterator.previous();
            }
            this.mIterator.remove();
        }
    }

    public static interface PDFObjectFilter {
        public boolean accept(CosObject var1) throws PDFCosParseException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException;
    }

}