package org.eclipse.collections.impl.primitive;
import java.util.Arrays;
import org.eclipse.collections.api.FloatIterable;
import org.eclipse.collections.api.LazyFloatIterable;
import org.eclipse.collections.api.bag.primitive.MutableFloatBag;
import org.eclipse.collections.api.list.primitive.MutableFloatList;
import org.eclipse.collections.api.set.primitive.MutableFloatSet;
import org.eclipse.collections.impl.bag.mutable.primitive.FloatHashBag;
import org.eclipse.collections.impl.lazy.primitive.LazyFloatIterableAdapter;
import org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList;
import org.eclipse.collections.impl.set.mutable.primitive.FloatHashSet;
public abstract class AbstractFloatIterable implements FloatIterable
{
@Override
public String toString()
{
return this.makeString("[", ", ", "]");
}
@Override
public float minIfEmpty(float defaultValue)
{
if (this.isEmpty())
{
return defaultValue;
}
return this.min();
}
@Override
public float maxIfEmpty(float defaultValue)
{
if (this.isEmpty())
{
return defaultValue;
}
return this.max();
}
@Override
public double average()
{
if (this.isEmpty())
{
throw new ArithmeticException();
}
return (double) this.sum() / (double) this.size();
}
@Override
public double median()
{
if (this.isEmpty())
{
throw new ArithmeticException();
}
float[] sortedArray = this.toSortedArray();
int middleIndex = sortedArray.length >> 1;
if (sortedArray.length > 1 && (sortedArray.length & 1) == 0)
{
float first = sortedArray[middleIndex];
float second = sortedArray[middleIndex - 1];
return ((double) first + (double) second) / 2.0;
}
return (double) sortedArray[middleIndex];
}
@Override
public float[] toSortedArray()
{
float[] array = this.toArray();
Arrays.sort(array);
return array;
}
@Override
public MutableFloatList toSortedList()
{
return this.toList().sortThis();
}
@Override
public LazyFloatIterable asLazy()
{
return new LazyFloatIterableAdapter(this);
}
@Override
public MutableFloatList toList()
{
return FloatArrayList.newList(this);
}
@Override
public MutableFloatSet toSet()
{
return FloatHashSet.newSet(this);
}
@Override
public MutableFloatBag toBag()
{
return FloatHashBag.newBag(this);
}
@Override
public boolean containsAll(float... source)
{
for (float item : source)
{
if (!this.contains(item))
{
return false;
}
}
return true;
}
@Override
public boolean containsAll(FloatIterable source)
{
return source.allSatisfy(this::contains);
}
}