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

package it.unimi.dsi.fastutil.bytes;

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

public abstract class AbstractByteCollection extends AbstractCollection<Byte> implements ByteCollection
{
    protected AbstractByteCollection() {
    }
    
    @Override
    public abstract ByteIterator iterator();
    
    @Override
    public boolean add(final byte k) {
        throw new UnsupportedOperationException();
    }
    
    @Override
    public boolean contains(final byte k) {
        final ByteIterator iterator = this.iterator();
        while (iterator.hasNext()) {
            if (k == iterator.nextByte()) {
                return true;
            }
        }
        return false;
    }
    
    @Override
    public boolean rem(final byte k) {
        final ByteIterator iterator = this.iterator();
        while (iterator.hasNext()) {
            if (k == iterator.nextByte()) {
                iterator.remove();
                return true;
            }
        }
        return false;
    }
    
    @Deprecated
    @Override
    public boolean add(final Byte 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 byte[] toArray(byte[] a) {
        final int size = this.size();
        if (a == null) {
            a = new byte[size];
        }
        else if (a.length < size) {
            a = Arrays.copyOf(a, size);
        }
        ByteIterators.unwrap(this.iterator(), a);
        return a;
    }
    
    @Override
    public byte[] toByteArray() {
        final int size = this.size();
        if (size == 0) {
            return ByteArrays.EMPTY_ARRAY;
        }
        final byte[] a = new byte[size];
        ByteIterators.unwrap(this.iterator(), a);
        return a;
    }
    
    @Deprecated
    @Override
    public byte[] toByteArray(final byte[] a) {
        return this.toArray(a);
    }
    
    @Override
    public boolean addAll(final ByteCollection c) {
        boolean retVal = false;
        final ByteIterator i = c.iterator();
        while (i.hasNext()) {
            if (this.add(i.nextByte())) {
                retVal = true;
            }
        }
        return retVal;
    }
    
    @Override
    public boolean addAll(final Collection<? extends Byte> c) {
        if (c instanceof ByteCollection) {
            return this.addAll((ByteCollection)c);
        }
        return super.addAll(c);
    }
    
    @Override
    public boolean containsAll(final ByteCollection c) {
        final ByteIterator i = c.iterator();
        while (i.hasNext()) {
            if (!this.contains(i.nextByte())) {
                return false;
            }
        }
        return true;
    }
    
    @Override
    public boolean containsAll(final Collection<?> c) {
        if (c instanceof ByteCollection) {
            return this.containsAll((ByteCollection)c);
        }
        return super.containsAll(c);
    }
    
    @Override
    public boolean removeAll(final ByteCollection c) {
        boolean retVal = false;
        final ByteIterator i = c.iterator();
        while (i.hasNext()) {
            if (this.rem(i.nextByte())) {
                retVal = true;
            }
        }
        return retVal;
    }
    
    @Override
    public boolean removeAll(final Collection<?> c) {
        if (c instanceof ByteCollection) {
            return this.removeAll((ByteCollection)c);
        }
        return super.removeAll(c);
    }
    
    @Override
    public boolean retainAll(final ByteCollection c) {
        boolean retVal = false;
        final ByteIterator i = this.iterator();
        while (i.hasNext()) {
            if (!c.contains(i.nextByte())) {
                i.remove();
                retVal = true;
            }
        }
        return retVal;
    }
    
    @Override
    public boolean retainAll(final Collection<?> c) {
        if (c instanceof ByteCollection) {
            return this.retainAll((ByteCollection)c);
        }
        return super.retainAll(c);
    }
    
    @Override
    public String toString() {
        final StringBuilder s = new StringBuilder();
        final ByteIterator i = this.iterator();
        int n = this.size();
        boolean first = true;
        s.append("{");
        while (n-- != 0) {
            if (first) {
                first = false;
            }
            else {
                s.append(", ");
            }
            final byte k = i.nextByte();
            s.append(String.valueOf(k));
        }
        s.append("}");
        return s.toString();
    }
}
