// 
// Decompiled by Procyon v0.6.0
// 

package it.unimi.dsi.fastutil.shorts;

import java.util.Iterator;
import java.util.Collection;
import java.util.Arrays;
import java.util.AbstractCollection;

public abstract class AbstractShortCollection extends AbstractCollection<Short> implements ShortCollection
{
    protected AbstractShortCollection() {
    }
    
    @Override
    public abstract ShortIterator iterator();
    
    @Override
    public boolean add(final short k) {
        throw new UnsupportedOperationException();
    }
    
    @Override
    public boolean contains(final short k) {
        final ShortIterator iterator = this.iterator();
        while (iterator.hasNext()) {
            if (k == iterator.nextShort()) {
                return true;
            }
        }
        return false;
    }
    
    @Override
    public boolean rem(final short k) {
        final ShortIterator iterator = this.iterator();
        while (iterator.hasNext()) {
            if (k == iterator.nextShort()) {
                iterator.remove();
                return true;
            }
        }
        return false;
    }
    
    @Deprecated
    @Override
    public boolean add(final Short key) {
        return super.add(key);
    }
    
    @Deprecated
    @Override
    public boolean contains(final Object key) {
        return super.contains(key);
    }
    
    @Deprecated
    @Override
    public boolean remove(final Object key) {
        return super.remove(key);
    }
    
    @Override
    public short[] toArray(short[] a) {
        final int size = this.size();
        if (a == null) {
            a = new short[size];
        }
        else if (a.length < size) {
            a = Arrays.copyOf(a, size);
        }
        ShortIterators.unwrap(this.iterator(), a);
        return a;
    }
    
    @Override
    public short[] toShortArray() {
        final int size = this.size();
        if (size == 0) {
            return ShortArrays.EMPTY_ARRAY;
        }
        final short[] a = new short[size];
        ShortIterators.unwrap(this.iterator(), a);
        return a;
    }
    
    @Deprecated
    @Override
    public short[] toShortArray(final short[] a) {
        return this.toArray(a);
    }
    
    @Override
    public boolean addAll(final ShortCollection c) {
        boolean retVal = false;
        final ShortIterator i = c.iterator();
        while (i.hasNext()) {
            if (this.add(i.nextShort())) {
                retVal = true;
            }
        }
        return retVal;
    }
    
    @Override
    public boolean addAll(final Collection<? extends Short> c) {
        if (c instanceof ShortCollection) {
            return this.addAll((ShortCollection)c);
        }
        return super.addAll(c);
    }
    
    @Override
    public boolean containsAll(final ShortCollection c) {
        final ShortIterator i = c.iterator();
        while (i.hasNext()) {
            if (!this.contains(i.nextShort())) {
                return false;
            }
        }
        return true;
    }
    
    @Override
    public boolean containsAll(final Collection<?> c) {
        if (c instanceof ShortCollection) {
            return this.containsAll((ShortCollection)c);
        }
        return super.containsAll(c);
    }
    
    @Override
    public boolean removeAll(final ShortCollection c) {
        boolean retVal = false;
        final ShortIterator i = c.iterator();
        while (i.hasNext()) {
            if (this.rem(i.nextShort())) {
                retVal = true;
            }
        }
        return retVal;
    }
    
    @Override
    public boolean removeAll(final Collection<?> c) {
        if (c instanceof ShortCollection) {
            return this.removeAll((ShortCollection)c);
        }
        return super.removeAll(c);
    }
    
    @Override
    public boolean retainAll(final ShortCollection c) {
        boolean retVal = false;
        final ShortIterator i = this.iterator();
        while (i.hasNext()) {
            if (!c.contains(i.nextShort())) {
                i.remove();
                retVal = true;
            }
        }
        return retVal;
    }
    
    @Override
    public boolean retainAll(final Collection<?> c) {
        if (c instanceof ShortCollection) {
            return this.retainAll((ShortCollection)c);
        }
        return super.retainAll(c);
    }
    
    @Override
    public String toString() {
        final StringBuilder s = new StringBuilder();
        final ShortIterator i = this.iterator();
        int n = this.size();
        boolean first = true;
        s.append("{");
        while (n-- != 0) {
            if (first) {
                first = false;
            }
            else {
                s.append(", ");
            }
            final short k = i.nextShort();
            s.append(String.valueOf(k));
        }
        s.append("}");
        return s.toString();
    }
}
