OrderedSet.java 2.27 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.day.util;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;

public class OrderedSet
implements Set {
    private final HashSet set;
    private final LinkedList list = new LinkedList();

    public OrderedSet() {
        this.set = new HashSet();
    }

    public OrderedSet(Collection c) {
        this.set = new HashSet(Math.max((int)((float)c.size() / 0.75f) + 1, 16));
        this.addAll(c);
    }

    public OrderedSet(int initialCapacity, float loadFactor) {
        this.set = new HashSet(initialCapacity, loadFactor);
    }

    public OrderedSet(int initialCapacity) {
        this.set = new HashSet(initialCapacity);
    }

    public int size() {
        return this.set.size();
    }

    public boolean isEmpty() {
        return this.set.isEmpty();
    }

    public boolean contains(Object o) {
        return this.set.contains(o);
    }

    public Iterator iterator() {
        return this.list.iterator();
    }

    public Object[] toArray() {
        return this.list.toArray();
    }

    public Object[] toArray(Object[] a) {
        return this.list.toArray(a);
    }

    public boolean add(Object o) {
        if (this.set.add(o)) {
            this.list.add(o);
            return true;
        }
        return false;
    }

    public boolean remove(Object o) {
        if (this.set.remove(o)) {
            this.list.remove(o);
            return true;
        }
        return false;
    }

    public boolean containsAll(Collection c) {
        return this.set.containsAll(c);
    }

    public boolean addAll(Collection c) {
        boolean ret = false;
        Iterator iter = c.iterator();
        while (iter.hasNext()) {
            ret |= this.add(iter.next());
        }
        return ret;
    }

    public boolean retainAll(Collection c) {
        this.set.clear();
        this.list.clear();
        return this.addAll(c);
    }

    public boolean removeAll(Collection c) {
        boolean ret = false;
        Iterator iter = c.iterator();
        while (iter.hasNext()) {
            ret |= this.remove(iter.next());
        }
        return ret;
    }

    public void clear() {
        this.set.clear();
        this.list.clear();
    }
}