Storage.java 1.05 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.xfa.ut;

import java.util.ArrayList;
import java.util.List;

public class Storage<T>
extends ArrayList<T> {
    private static final long serialVersionUID = -3453467565507172287L;

    public Storage() {
    }

    public Storage(int size) {
        super(size);
    }

    public Storage(List<T> storage) {
        super(storage.size());
        for (int i = 0; i < storage.size(); ++i) {
            this.add(storage.get(i));
        }
    }

    public void setSize(int size) {
        int oldSize = this.size();
        if (size < oldSize) {
            this.removeRange(size, oldSize);
        } else if (size > oldSize) {
            this.ensureCapacity(size);
            while (oldSize++ < size) {
                this.add(null);
            }
        }
    }

    public T last() {
        int end = this.size();
        return end > 0 ? (T)this.get(end - 1) : null;
    }

    public void removeLast() {
        int end = this.size();
        if (end > 0) {
            this.setSize(end - 1);
        }
    }
}