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

package it.unimi.dsi.fastutil.floats;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.stream.Stream;
import java.util.stream.DoubleStream;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Spliterator;
import it.unimi.dsi.fastutil.doubles.DoubleSpliterators;
import it.unimi.dsi.fastutil.doubles.DoubleSpliterator;
import it.unimi.dsi.fastutil.doubles.DoubleIterators;
import it.unimi.dsi.fastutil.doubles.DoubleIterator;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.function.Consumer;
import java.util.Collection;
import it.unimi.dsi.fastutil.objects.ObjectArrays;

public final class FloatCollections
{
    private FloatCollections() {
    }
    
    public static FloatCollection synchronize(final FloatCollection c) {
        return new SynchronizedCollection(c);
    }
    
    public static FloatCollection synchronize(final FloatCollection c, final Object sync) {
        return new SynchronizedCollection(c, sync);
    }
    
    public static FloatCollection unmodifiable(final FloatCollection c) {
        return new UnmodifiableCollection(c);
    }
    
    public static FloatCollection asCollection(final FloatIterable iterable) {
        if (iterable instanceof FloatCollection) {
            return (FloatCollection)iterable;
        }
        return new IterableCollection(iterable);
    }
    
    public abstract static class EmptyCollection extends AbstractFloatCollection
    {
        protected EmptyCollection() {
        }
        
        @Override
        public boolean contains(final float k) {
            return false;
        }
        
        @Override
        public Object[] toArray() {
            return ObjectArrays.EMPTY_ARRAY;
        }
        
        @Override
        public <T> T[] toArray(final T[] array) {
            if (array.length > 0) {
                array[0] = null;
            }
            return array;
        }
        
        @Override
        public FloatBidirectionalIterator iterator() {
            return FloatIterators.EMPTY_ITERATOR;
        }
        
        @Override
        public FloatSpliterator spliterator() {
            return FloatSpliterators.EMPTY_SPLITERATOR;
        }
        
        @Override
        public int size() {
            return 0;
        }
        
        @Override
        public void clear() {
        }
        
        @Override
        public int hashCode() {
            return 0;
        }
        
        @Override
        public boolean equals(final Object o) {
            return o == this || (o instanceof Collection && ((Collection)o).isEmpty());
        }
        
        @Deprecated
        @Override
        public void forEach(final Consumer<? super Float> action) {
        }
        
        @Override
        public boolean containsAll(final Collection<?> c) {
            return c.isEmpty();
        }
        
        @Override
        public boolean addAll(final Collection<? extends Float> c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean removeAll(final Collection<?> c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean retainAll(final Collection<?> c) {
            throw new UnsupportedOperationException();
        }
        
        @Deprecated
        @Override
        public boolean removeIf(final Predicate<? super Float> filter) {
            Objects.requireNonNull(filter);
            return false;
        }
        
        @Override
        public float[] toFloatArray() {
            return FloatArrays.EMPTY_ARRAY;
        }
        
        @Deprecated
        @Override
        public float[] toFloatArray(final float[] a) {
            return a;
        }
        
        @Override
        public void forEach(final FloatConsumer action) {
        }
        
        @Override
        public boolean containsAll(final FloatCollection c) {
            return c.isEmpty();
        }
        
        @Override
        public boolean addAll(final FloatCollection c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean removeAll(final FloatCollection c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean retainAll(final FloatCollection c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean removeIf(final FloatPredicate filter) {
            Objects.requireNonNull(filter);
            return false;
        }
        
        @Override
        public DoubleIterator doubleIterator() {
            return DoubleIterators.EMPTY_ITERATOR;
        }
        
        @Override
        public DoubleSpliterator doubleSpliterator() {
            return DoubleSpliterators.EMPTY_SPLITERATOR;
        }
    }
    
    static class SynchronizedCollection implements FloatCollection, Serializable
    {
        private static final long serialVersionUID = -7046029254386353129L;
        protected final FloatCollection collection;
        protected final Object sync;
        
        protected SynchronizedCollection(final FloatCollection c, final Object sync) {
            this.collection = Objects.requireNonNull(c);
            this.sync = sync;
        }
        
        protected SynchronizedCollection(final FloatCollection c) {
            this.collection = Objects.requireNonNull(c);
            this.sync = this;
        }
        
        @Override
        public boolean add(final float k) {
            synchronized (this.sync) {
                return this.collection.add(k);
            }
        }
        
        @Override
        public boolean contains(final float k) {
            synchronized (this.sync) {
                return this.collection.contains(k);
            }
        }
        
        @Override
        public boolean rem(final float k) {
            synchronized (this.sync) {
                return this.collection.rem(k);
            }
        }
        
        @Override
        public int size() {
            synchronized (this.sync) {
                return this.collection.size();
            }
        }
        
        @Override
        public boolean isEmpty() {
            synchronized (this.sync) {
                return this.collection.isEmpty();
            }
        }
        
        @Override
        public float[] toFloatArray() {
            synchronized (this.sync) {
                return this.collection.toFloatArray();
            }
        }
        
        @Override
        public Object[] toArray() {
            synchronized (this.sync) {
                return this.collection.toArray();
            }
        }
        
        @Deprecated
        @Override
        public float[] toFloatArray(final float[] a) {
            return this.toArray(a);
        }
        
        @Override
        public float[] toArray(final float[] a) {
            synchronized (this.sync) {
                return this.collection.toArray(a);
            }
        }
        
        @Override
        public boolean addAll(final FloatCollection c) {
            synchronized (this.sync) {
                return this.collection.addAll(c);
            }
        }
        
        @Override
        public boolean containsAll(final FloatCollection c) {
            synchronized (this.sync) {
                return this.collection.containsAll(c);
            }
        }
        
        @Override
        public boolean removeAll(final FloatCollection c) {
            synchronized (this.sync) {
                return this.collection.removeAll(c);
            }
        }
        
        @Override
        public boolean retainAll(final FloatCollection c) {
            synchronized (this.sync) {
                return this.collection.retainAll(c);
            }
        }
        
        @Deprecated
        @Override
        public boolean add(final Float k) {
            synchronized (this.sync) {
                return this.collection.add(k);
            }
        }
        
        @Deprecated
        @Override
        public boolean contains(final Object k) {
            synchronized (this.sync) {
                return this.collection.contains(k);
            }
        }
        
        @Deprecated
        @Override
        public boolean remove(final Object k) {
            synchronized (this.sync) {
                return this.collection.remove(k);
            }
        }
        
        @Override
        public DoubleIterator doubleIterator() {
            return this.collection.doubleIterator();
        }
        
        @Override
        public DoubleSpliterator doubleSpliterator() {
            return this.collection.doubleSpliterator();
        }
        
        @Override
        public DoubleStream doubleStream() {
            return this.collection.doubleStream();
        }
        
        @Override
        public DoubleStream doubleParallelStream() {
            return this.collection.doubleParallelStream();
        }
        
        @Override
        public <T> T[] toArray(final T[] a) {
            synchronized (this.sync) {
                return this.collection.toArray(a);
            }
        }
        
        @Override
        public FloatIterator iterator() {
            return this.collection.iterator();
        }
        
        @Override
        public FloatSpliterator spliterator() {
            return this.collection.spliterator();
        }
        
        @Deprecated
        @Override
        public Stream<Float> stream() {
            return this.collection.stream();
        }
        
        @Deprecated
        @Override
        public Stream<Float> parallelStream() {
            return this.collection.parallelStream();
        }
        
        @Override
        public void forEach(final FloatConsumer action) {
            synchronized (this.sync) {
                this.collection.forEach(action);
            }
        }
        
        @Override
        public boolean addAll(final Collection<? extends Float> c) {
            synchronized (this.sync) {
                return this.collection.addAll(c);
            }
        }
        
        @Override
        public boolean containsAll(final Collection<?> c) {
            synchronized (this.sync) {
                return this.collection.containsAll(c);
            }
        }
        
        @Override
        public boolean removeAll(final Collection<?> c) {
            synchronized (this.sync) {
                return this.collection.removeAll(c);
            }
        }
        
        @Override
        public boolean retainAll(final Collection<?> c) {
            synchronized (this.sync) {
                return this.collection.retainAll(c);
            }
        }
        
        @Override
        public boolean removeIf(final FloatPredicate filter) {
            synchronized (this.sync) {
                return this.collection.removeIf(filter);
            }
        }
        
        @Override
        public void clear() {
            synchronized (this.sync) {
                this.collection.clear();
            }
        }
        
        @Override
        public String toString() {
            synchronized (this.sync) {
                return this.collection.toString();
            }
        }
        
        @Override
        public int hashCode() {
            synchronized (this.sync) {
                return this.collection.hashCode();
            }
        }
        
        @Override
        public boolean equals(final Object o) {
            if (o == this) {
                return true;
            }
            synchronized (this.sync) {
                return this.collection.equals(o);
            }
        }
        
        private void writeObject(final ObjectOutputStream s) throws IOException {
            synchronized (this.sync) {
                s.defaultWriteObject();
            }
        }
    }
    
    static class UnmodifiableCollection implements FloatCollection, Serializable
    {
        private static final long serialVersionUID = -7046029254386353129L;
        protected final FloatCollection collection;
        
        protected UnmodifiableCollection(final FloatCollection c) {
            this.collection = Objects.requireNonNull(c);
        }
        
        @Override
        public boolean add(final float k) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean rem(final float k) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public int size() {
            return this.collection.size();
        }
        
        @Override
        public boolean isEmpty() {
            return this.collection.isEmpty();
        }
        
        @Override
        public boolean contains(final float o) {
            return this.collection.contains(o);
        }
        
        @Override
        public FloatIterator iterator() {
            return FloatIterators.unmodifiable(this.collection.iterator());
        }
        
        @Override
        public FloatSpliterator spliterator() {
            return this.collection.spliterator();
        }
        
        @Deprecated
        @Override
        public Stream<Float> stream() {
            return this.collection.stream();
        }
        
        @Deprecated
        @Override
        public Stream<Float> parallelStream() {
            return this.collection.parallelStream();
        }
        
        @Override
        public void clear() {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public <T> T[] toArray(final T[] a) {
            return this.collection.toArray(a);
        }
        
        @Override
        public Object[] toArray() {
            return this.collection.toArray();
        }
        
        @Override
        public void forEach(final FloatConsumer action) {
            this.collection.forEach(action);
        }
        
        @Override
        public boolean containsAll(final Collection<?> c) {
            return this.collection.containsAll(c);
        }
        
        @Override
        public boolean addAll(final Collection<? extends Float> c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean removeAll(final Collection<?> c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean retainAll(final Collection<?> c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean removeIf(final FloatPredicate filter) {
            throw new UnsupportedOperationException();
        }
        
        @Deprecated
        @Override
        public boolean add(final Float k) {
            throw new UnsupportedOperationException();
        }
        
        @Deprecated
        @Override
        public boolean contains(final Object k) {
            return this.collection.contains(k);
        }
        
        @Deprecated
        @Override
        public boolean remove(final Object k) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public float[] toFloatArray() {
            return this.collection.toFloatArray();
        }
        
        @Deprecated
        @Override
        public float[] toFloatArray(final float[] a) {
            return this.toArray(a);
        }
        
        @Override
        public float[] toArray(final float[] a) {
            return this.collection.toArray(a);
        }
        
        @Override
        public boolean containsAll(final FloatCollection c) {
            return this.collection.containsAll(c);
        }
        
        @Override
        public boolean addAll(final FloatCollection c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean removeAll(final FloatCollection c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean retainAll(final FloatCollection c) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public DoubleIterator doubleIterator() {
            return this.collection.doubleIterator();
        }
        
        @Override
        public DoubleSpliterator doubleSpliterator() {
            return this.collection.doubleSpliterator();
        }
        
        @Override
        public DoubleStream doubleStream() {
            return this.collection.doubleStream();
        }
        
        @Override
        public DoubleStream doubleParallelStream() {
            return this.collection.doubleParallelStream();
        }
        
        @Override
        public String toString() {
            return this.collection.toString();
        }
        
        @Override
        public int hashCode() {
            return this.collection.hashCode();
        }
        
        @Override
        public boolean equals(final Object o) {
            return o == this || this.collection.equals(o);
        }
    }
    
    public static class IterableCollection extends AbstractFloatCollection implements Serializable
    {
        private static final long serialVersionUID = -7046029254386353129L;
        protected final FloatIterable iterable;
        
        protected IterableCollection(final FloatIterable iterable) {
            this.iterable = Objects.requireNonNull(iterable);
        }
        
        @Override
        public int size() {
            final long size = this.iterable.spliterator().getExactSizeIfKnown();
            if (size >= 0L) {
                return (int)Math.min(2147483647L, size);
            }
            int c = 0;
            final FloatIterator iterator = this.iterator();
            while (iterator.hasNext()) {
                iterator.nextFloat();
                ++c;
            }
            return c;
        }
        
        @Override
        public boolean isEmpty() {
            return !this.iterable.iterator().hasNext();
        }
        
        @Override
        public FloatIterator iterator() {
            return this.iterable.iterator();
        }
        
        @Override
        public FloatSpliterator spliterator() {
            return this.iterable.spliterator();
        }
        
        @Override
        public DoubleIterator doubleIterator() {
            return this.iterable.doubleIterator();
        }
        
        @Override
        public DoubleSpliterator doubleSpliterator() {
            return this.iterable.doubleSpliterator();
        }
    }
}
