org.expasy.jpl.commons.collection
Class PrimitiveArrayUtils

java.lang.Object
  extended by org.expasy.jpl.commons.collection.PrimitiveArrayUtils

public final class PrimitiveArrayUtils
extends Object

Provides static generic methods on primitive arrays.

Version:
1.0
Author:
nikitin

Constructor Summary
PrimitiveArrayUtils()
           
 
Method Summary
static List<Integer> asIntList(int[] ints)
          Convert ints to List of Integers.
static
<T> List<T>
asList(T[] os)
          Convert arrays of Ts to List of Ts.
static int byteArrayToInt(byte[] bytes)
          Convert an array of bytes into integer value.
static int[] convert2ints(Object[] objects)
          Convert objects to ints.
static Double[] doubles2Doubles(double[] dbls)
          Convert array of doubles to array of Doubles.
static double[] floats2doubles(float[] fArray)
           
static int[] getIndexRange(double[] values, double start, double end)
          Get the index range of values where each is contained in the given interval.
static IntegerSequence getIndexRange(double[] values, Interval interval)
          Get an interval of index in sorted values.
static void getNthHighestElement(double[] array, int rank)
           
static double[] getSubArray(double[] values, int from, int to)
           
static Integer[] ints2Integers(int[] ints)
          Convert ints to array of Integers.
static byte[] intToByteArray(int value)
          Convert an integer to an array of bytes.
static
<T> double[]
loadArray(T object, org.apache.commons.collections15.Transformer<T,double[]> o2a, double[] copy)
          Copy array of doubles accessible from T-object in a given copy array.
static double[] mapping(double[] vals, int[] indices)
          Map the doubles found at given indices.
static double[] mapping(double[] vals, int from, int to)
          Map the values found in the given interval.
static int[] mapping(int[] array, int[] indices)
          Map the integers found at given indices.
static Object[] mapping(Object[] objects, int[] indices)
          Map the objects found at given indices.
static double[] mergeUp(double[] array1, double[] array2)
          Merge two sorted arrays (ascending or up) in one
static void reverse(int[] b)
          simply reverse the array
static List<Integer> searchIndices(double[] values, double[] intervalCenters, double halfIntervalRange)
          Search the given query intervals into the target values.
static List<Integer> searchIndices(double[] values, double[] intervalCenters, double halfIntervalRange, int from)
          Search the given query intervals into the target values.
static double[] sortDown(double[] array)
          Sort double values in descending order.
static int[] sortDown(int[] array)
          Sort int values in descending order.
static int[] sortIndexesDown(double[] array)
           
static int[] sortIndexesDown(int[] array)
          Sort int value indices in descending order.
static int[] sortIndexesUp(double[] array)
           
static int[] sortIndexesUp(int[] array)
          Sort int value indices in ascending order.
static int[] sortIndices(double[] objects)
           
static int[] sortIndices(double[] objects, int[] indices, int from, int to)
          Reimplementation of quicksort for performance gain.
static double[] sortUp(double[] array)
          Sort double values in ascending order.
static int[] sortUp(int[] array)
          Sort int values in ascending order.
static void sortUpArrraysOnFirst(double[][] arrays)
          sort (increasing) the list of arrays based on the values contained in the first one (think of masses, intensities...)
static double[] toDoubleArray(List<Double> list)
          Convert a list of Doubles to an array of doubles.
static int[] toIntArray(List<Integer> list)
          Convert a list of Integers to an array of ints.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrimitiveArrayUtils

public PrimitiveArrayUtils()
Method Detail

reverse

public static void reverse(int[] b)
simply reverse the array


mapping

public static Object[] mapping(Object[] objects,
                               int[] indices)
Map the objects found at given indices.

Parameters:
objects - the objects to map.
indices - the indices of objects array.
Returns:
an array of mapped Objects.

mapping

public static int[] mapping(int[] array,
                            int[] indices)
Map the integers found at given indices.

Parameters:
array - the integers to map.
indices - the indices of objects array.
Returns:
an array of mapped ints.

mapping

public static double[] mapping(double[] vals,
                               int[] indices)
Map the doubles found at given indices.

Parameters:
vals - the values to map.
indices - the indices of objects array.
Returns:
an array of mapped doubles.

mapping

public static double[] mapping(double[] vals,
                               int from,
                               int to)
Map the values found in the given interval.

Parameters:
vals - the values to map.
from - the first index.
to - the last index.
Returns:
an array of doubles.

convert2ints

public static int[] convert2ints(Object[] objects)
Convert objects to ints.

Parameters:
objects - the objects to convert.

ints2Integers

public static Integer[] ints2Integers(int[] ints)
Convert ints to array of Integers.

Parameters:
ints - the ints to convert.

asIntList

public static List<Integer> asIntList(int[] ints)
Convert ints to List of Integers.

Parameters:
ints - the ints to convert.

asList

public static <T> List<T> asList(T[] os)
Convert arrays of Ts to List of Ts.

Parameters:
os - the object array to convert.

doubles2Doubles

public static Double[] doubles2Doubles(double[] dbls)
Convert array of doubles to array of Doubles.

Parameters:
dbls - the array to convert.

sortUp

public static int[] sortUp(int[] array)
Sort int values in ascending order.

Parameters:
array - the int array to sort.
Returns:
the sorted array.

sortDown

public static int[] sortDown(int[] array)
Sort int values in descending order.

Parameters:
array - the int array to sort.
Returns:
the sorted array.

sortUp

public static double[] sortUp(double[] array)
Sort double values in ascending order.

Parameters:
array - the double array to sort.
Returns:
the sorted array.

sortDown

public static double[] sortDown(double[] array)
Sort double values in descending order.

Parameters:
array - the double array to sort.
Returns:
the sorted array.

sortIndexesUp

public static int[] sortIndexesUp(int[] array)
Sort int value indices in ascending order.

Parameters:
array - the int array to sort indices.
Returns:
the sorted array.

sortIndexesDown

public static int[] sortIndexesDown(int[] array)
Sort int value indices in descending order.

Parameters:
array - the int array to sort indices.
Returns:
the sorted array.

sortIndexesUp

public static int[] sortIndexesUp(double[] array)

sortIndexesDown

public static int[] sortIndexesDown(double[] array)

mergeUp

public static double[] mergeUp(double[] array1,
                               double[] array2)
Merge two sorted arrays (ascending or up) in one

Parameters:
array1 - the first sorted array
array2 - the second sorted array
Returns:
array the sorted merged array

sortIndices

public static final int[] sortIndices(double[] objects)

sortIndices

public static final int[] sortIndices(double[] objects,
                                      int[] indices,
                                      int from,
                                      int to)
Reimplementation of quicksort for performance gain.

Parameters:
objects - the array of object to sort.
from - the lower limit.
to - the upper limit.

sortUpArrraysOnFirst

public static void sortUpArrraysOnFirst(double[][] arrays)
sort (increasing) the list of arrays based on the values contained in the first one (think of masses, intensities...)

Parameters:
arrays -
Throws:
IllegalArgumentException - if 0 arrays are passed of if length differs

getNthHighestElement

public static void getNthHighestElement(double[] array,
                                        int rank)

floats2doubles

public static double[] floats2doubles(float[] fArray)

getIndexRange

public static int[] getIndexRange(double[] values,
                                  double start,
                                  double end)
Get the index range of values where each is contained in the given interval.

Parameters:
values - the values to get the range from.
start - the interval included start.
end - the interval excluded end.
Returns:
a range of indices

getIndexRange

public static IntegerSequence getIndexRange(double[] values,
                                            Interval interval)
Get an interval of index in sorted values.

Parameters:
interval - of definition.
Returns:
an interval on values index [imin, imax[.
Throws:
IllegalArgumentException - if values are not sorted.

searchIndices

public static List<Integer> searchIndices(double[] values,
                                          double[] intervalCenters,
                                          double halfIntervalRange)
Search the given query intervals into the target values.

Parameters:
values - the sorted values to find indices in.
intervalCenters - the sorted interval centers query.
halfIntervalRange - the half-range interval for all query value.
Returns:
a list of indices found in at least one query interval.
Throws:
IllegalArgumentException - - if the arrays are not sorted.

searchIndices

public static List<Integer> searchIndices(double[] values,
                                          double[] intervalCenters,
                                          double halfIntervalRange,
                                          int from)
Search the given query intervals into the target values.

Parameters:
values - the sorted values to find indices in.
intervalCenters - the sorted interval centers query.
halfIntervalRange - the half-range interval for all query value.
from - the begin index to search into values.
Returns:
a list of indices found in at least one query interval.
Throws:
IllegalArgumentException - - if the arrays are not sorted.

getSubArray

public static double[] getSubArray(double[] values,
                                   int from,
                                   int to)

intToByteArray

public static final byte[] intToByteArray(int value)
Convert an integer to an array of bytes. http://snippets.dzone.com/posts/show/93

Parameters:
value - the integer to convert.

byteArrayToInt

public static final int byteArrayToInt(byte[] bytes)
Convert an array of bytes into integer value. http://snippets.dzone.com/posts/show/93

Parameters:
bytes - the bytes to convert into integer.

toDoubleArray

public static final double[] toDoubleArray(List<Double> list)
Convert a list of Doubles to an array of doubles.

Parameters:
list - the list to convert.
Returns:
an array of doubles.

toIntArray

public static final int[] toIntArray(List<Integer> list)
Convert a list of Integers to an array of ints.

Parameters:
list - the list to convert.
Returns:
an array of ints.

loadArray

public static <T> double[] loadArray(T object,
                                     org.apache.commons.collections15.Transformer<T,double[]> o2a,
                                     double[] copy)
Copy array of doubles accessible from T-object in a given copy array.

Type Parameters:
T - the object typed wrapping double[].
Parameters:
object - the T-object to copy doubles from.
copy - the array to copy doubles into.
o2a - the transformer to access double[] from T-object.
Returns:
the given copy loaded with doubles or a new array if copy is not defined or had reduced capacity.


Copyright (c) 2012 Swiss Institute of Bioinformatics. All rights reserved.