public final class Median
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static Pair<java.lang.Byte,OptionalByte> |
of(byte... a)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Byte,OptionalByte> |
of(byte[] a,
int fromIndex,
int toIndex)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Character,OptionalChar> |
of(char... a)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Character,OptionalChar> |
of(char[] a,
int fromIndex,
int toIndex)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static <T extends java.lang.Comparable<? super T>> |
of(java.util.Collection<T> c) |
static <T> Pair<T,Optional<T>> |
of(java.util.Collection<T> c,
java.util.Comparator<? super T> cmp) |
static Pair<java.lang.Double,OptionalDouble> |
of(double... a)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Double,OptionalDouble> |
of(double[] a,
int fromIndex,
int toIndex)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Float,OptionalFloat> |
of(float... a)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Float,OptionalFloat> |
of(float[] a,
int fromIndex,
int toIndex)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Integer,OptionalInt> |
of(int... a)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Integer,OptionalInt> |
of(int[] a,
int fromIndex,
int toIndex)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Long,OptionalLong> |
of(long... a)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Long,OptionalLong> |
of(long[] a,
int fromIndex,
int toIndex)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Short,OptionalShort> |
of(short... a)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static Pair<java.lang.Short,OptionalShort> |
of(short[] a,
int fromIndex,
int toIndex)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static <T extends java.lang.Comparable<? super T>> |
of(T[] a)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static <T> Pair<T,Optional<T>> |
of(T[] a,
java.util.Comparator<? super T> cmp)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static <T extends java.lang.Comparable<? super T>> |
of(T[] a,
int fromIndex,
int toIndex)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
static <T> Pair<T,Optional<T>> |
of(T[] a,
int fromIndex,
int toIndex,
java.util.Comparator<? super T> cmp)
Returns a
Pair with left is the value at the index of (a.length - 1) / 2 when the array is sorted,
and the right is the value at the index of a.length / 2 if the length of array is even. |
@SafeVarargs public static Pair<java.lang.Character,OptionalChar> of(char... a)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- of(int[])
public static Pair<java.lang.Character,OptionalChar> of(char[] a, int fromIndex, int toIndex)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- fromIndex
- toIndex
- of(int[])
@SafeVarargs public static Pair<java.lang.Byte,OptionalByte> of(byte... a)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- of(int[])
public static Pair<java.lang.Byte,OptionalByte> of(byte[] a, int fromIndex, int toIndex)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- fromIndex
- toIndex
- of(int[])
@SafeVarargs public static Pair<java.lang.Short,OptionalShort> of(short... a)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- of(int[])
public static Pair<java.lang.Short,OptionalShort> of(short[] a, int fromIndex, int toIndex)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- fromIndex
- toIndex
- of(int[])
@SafeVarargs public static Pair<java.lang.Integer,OptionalInt> of(int... a)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.
Median.of(1); // -> [1, empty]
Median.of(1, 3); // -> [1, 3]
Median.of(1, 3, 5); // -> [3, empty]
Median.of(1, 1); // -> [1, 1]
Median.of(1, 1, 3); // -> [1, empty]
Median.of(1, 1, 3, 5); // -> [1, 3]
Median.of(1, 1, 1, 3, 5); // -> [1, empty]
Median.of(1, 1, 1, 3, 3, 5); // -> [1, 3]
Median.of(1, 1, 1, 3, 3, 3, 5); // -> [3, empty]
a
- java.lang.IllegalArgumentException
- if specified array is empty or length is zero.public static Pair<java.lang.Integer,OptionalInt> of(int[] a, int fromIndex, int toIndex)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- fromIndex
- toIndex
- java.lang.IllegalArgumentException
- if specified array is empty or length is zero.@SafeVarargs public static Pair<java.lang.Long,OptionalLong> of(long... a)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- of(int[])
public static Pair<java.lang.Long,OptionalLong> of(long[] a, int fromIndex, int toIndex)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- fromIndex
- toIndex
- of(int[])
@SafeVarargs public static Pair<java.lang.Float,OptionalFloat> of(float... a)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- of(int[])
public static Pair<java.lang.Float,OptionalFloat> of(float[] a, int fromIndex, int toIndex)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- fromIndex
- toIndex
- of(int[])
@SafeVarargs public static Pair<java.lang.Double,OptionalDouble> of(double... a)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- of(int[])
public static Pair<java.lang.Double,OptionalDouble> of(double[] a, int fromIndex, int toIndex)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- fromIndex
- toIndex
- of(int[])
public static <T extends java.lang.Comparable<? super T>> Pair<T,Optional<T>> of(T[] a)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- of(int[])
public static <T extends java.lang.Comparable<? super T>> Pair<T,Optional<T>> of(T[] a, int fromIndex, int toIndex)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- fromIndex
- toIndex
- of(int[])
public static <T> Pair<T,Optional<T>> of(T[] a, java.util.Comparator<? super T> cmp)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- of(int[])
public static <T> Pair<T,Optional<T>> of(T[] a, int fromIndex, int toIndex, java.util.Comparator<? super T> cmp)
Pair
with left
is the value at the index of (a.length - 1) / 2
when the array is sorted,
and the right
is the value at the index of a.length / 2
if the length of array is even.a
- fromIndex
- toIndex
- of(int[])
public static <T extends java.lang.Comparable<? super T>> Pair<T,Optional<T>> of(java.util.Collection<T> c)