package org.eclipse.collections.impl.primitive;
import java.util.Arrays;
import org.eclipse.collections.api.ByteIterable;
import org.eclipse.collections.api.LazyByteIterable;
import org.eclipse.collections.api.bag.primitive.MutableByteBag;
import org.eclipse.collections.api.list.primitive.MutableByteList;
import org.eclipse.collections.api.set.primitive.MutableByteSet;
import org.eclipse.collections.impl.bag.mutable.primitive.ByteHashBag;
import org.eclipse.collections.impl.lazy.primitive.LazyByteIterableAdapter;
import org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList;
import org.eclipse.collections.impl.set.mutable.primitive.ByteHashSet;
public abstract class AbstractByteIterable implements ByteIterable
{
@Override
public String toString()
{
return this.makeString("[", ", ", "]");
}
@Override
public byte minIfEmpty(byte defaultValue)
{
if (this.isEmpty())
{
return defaultValue;
}
return this.min();
}
@Override
public byte maxIfEmpty(byte 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();
}
byte[] sortedArray = this.toSortedArray();
int middleIndex = sortedArray.length >> 1;
if (sortedArray.length > 1 && (sortedArray.length & 1) == 0)
{
byte first = sortedArray[middleIndex];
byte second = sortedArray[middleIndex - 1];
return ((double) first + (double) second) / 2.0;
}
return (double) sortedArray[middleIndex];
}
@Override
public byte[] toSortedArray()
{
byte[] array = this.toArray();
Arrays.sort(array);
return array;
}
@Override
public MutableByteList toSortedList()
{
return this.toList().sortThis();
}
@Override
public LazyByteIterable asLazy()
{
return new LazyByteIterableAdapter(this);
}
@Override
public MutableByteList toList()
{
return ByteArrayList.newList(this);
}
@Override
public MutableByteSet toSet()
{
return ByteHashSet.newSet(this);
}
@Override
public MutableByteBag toBag()
{
return ByteHashBag.newBag(this);
}
}