package org.eclipse.collections.impl.primitive;
import java.util.Arrays;
import org.eclipse.collections.api.CharIterable;
import org.eclipse.collections.api.LazyCharIterable;
import org.eclipse.collections.api.bag.primitive.MutableCharBag;
import org.eclipse.collections.api.list.primitive.MutableCharList;
import org.eclipse.collections.api.set.primitive.MutableCharSet;
import org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag;
import org.eclipse.collections.impl.lazy.primitive.LazyCharIterableAdapter;
import org.eclipse.collections.impl.list.mutable.primitive.CharArrayList;
import org.eclipse.collections.impl.set.mutable.primitive.CharHashSet;
public abstract class AbstractCharIterable implements CharIterable
{
@Override
public String toString()
{
return this.makeString("[", ", ", "]");
}
@Override
public char minIfEmpty(char defaultValue)
{
if (this.isEmpty())
{
return defaultValue;
}
return this.min();
}
@Override
public char maxIfEmpty(char 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();
}
char[] sortedArray = this.toSortedArray();
int middleIndex = sortedArray.length >> 1;
if (sortedArray.length > 1 && (sortedArray.length & 1) == 0)
{
char first = sortedArray[middleIndex];
char second = sortedArray[middleIndex - 1];
return ((double) first + (double) second) / 2.0;
}
return (double) sortedArray[middleIndex];
}
@Override
public char[] toSortedArray()
{
char[] array = this.toArray();
Arrays.sort(array);
return array;
}
@Override
public MutableCharList toSortedList()
{
return this.toList().sortThis();
}
@Override
public LazyCharIterable asLazy()
{
return new LazyCharIterableAdapter(this);
}
@Override
public MutableCharList toList()
{
return CharArrayList.newList(this);
}
@Override
public MutableCharSet toSet()
{
return CharHashSet.newSet(this);
}
@Override
public MutableCharBag toBag()
{
return CharHashBag.newBag(this);
}
}