|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.samskivert.util.IntListUtil
public class IntListUtil
This class manages arrays of ints. Some of those routines mimic the behavior of array lists, others provide other more specialized (generally faster but making requirements of the caller) list behavior.
An example is probably in order:
int[] list = null; // add our ints to a list list = ListUtil.add(list, 2); list = ListUtil.add(list, 5); // remove 5 from the list (does so by clearing out that index, but it // doesn't slide subsequent elements down) ListUtil.clear(list, 5); // append our objects to the end of the list letting list util know // that we're tracking the list size list = ListUtil.add(list, 0, 2); list = ListUtil.add(list, 1, 5); // remove the elements from the list, compacting it to preserve // element continuity ListUtil.removeAt(list, 0); ListUtil.remove(list, 5);The array is initially assumed to be populated with zeros and zero is assumed to be an emty slot.
See the documentation for the individual functions for their exact behavior.
| Field Summary | |
|---|---|
protected static int |
DEFAULT_LIST_SIZE
The size of a list to create if we have to create one entirely from scratch rather than just expand it. |
| Constructor Summary | |
|---|---|
IntListUtil()
|
|
| Method Summary | |
|---|---|
protected static int[] |
accomodate(int[] list,
int index)
Creates a new list that will accomodate the specified index and copies the contents of the old list to the first. |
static int[] |
add(int[] list,
int value)
Adds the specified value to the first empty slot in the specified list. |
static int[] |
add(int[] list,
int startIdx,
int value)
Adds the specified value to the next empty slot in the specified list. |
static Integer[] |
box(int[] list)
Covnerts an array of primitives to an array of objects. |
static int |
clear(int[] list,
int value)
Clears out the first value that is equal to the supplied value. |
static int[] |
compact(int[] list)
Converts a sparse array (with zero-valued entries) into a compact array (where all elements contain non-zero values) with ordering preserved. |
static boolean |
contains(int[] list,
int value)
Looks for an element that is equal to the supplied value. |
static int[] |
getMaxIndexes(int[] values)
Returns an array of the indexes in the given array of values that have the maximum value in the array, or a zero-length array if the supplied array of values is null or zero-length. |
static int |
getMaxValue(int[] values)
Returns the maximum value in the given array of values, or Integer.MIN_VALUE if the array is null or zero-length. |
static int |
getMaxValueIndex(int[] values)
Returns the index of the maximum value in the given array of values, or -1 if the array is null or
zero-length. |
static int[] |
getMinIndexes(int[] values)
Returns an array of the indexes in the given array of values that have the minimum value in the array, or a zero-length array if the supplied array of values is null or zero-length. |
static int |
getMinValue(int[] values)
Returns the minimum value in the given array of values, or Integer.MAX_VALUE if the array is null or zero-length. |
static int |
indexOf(int[] list,
int value)
Looks for an element that is equal to the supplied value and returns its index in the array. |
static float[] |
normalize(int[] values)
Normalizes an array of integers from the bounding [min,max] to [0.0, 1.0]. |
static int |
remove(int[] list,
int value)
Removes the first value that is equal to the supplied value. |
static int |
removeAt(int[] list,
int index)
Removes the value at the specified index. |
static int |
sum(int[] list)
Returns the total of all of the values in the list. |
static int[] |
testAndAdd(int[] list,
int value)
Searches through the list checking to see if the value supplied is already in the list and adds it if it is not. |
static int[] |
unbox(Integer[] list)
Converts an array of Integer objects to an array of primitives. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final int DEFAULT_LIST_SIZE
| Constructor Detail |
|---|
public IntListUtil()
| Method Detail |
|---|
public static int[] add(int[] list,
int value)
list - the list to which to add the value. Can be null.value - the value to add.
public static int[] add(int[] list,
int startIdx,
int value)
list - the list to which to add the value. Can be null.startIdx - the index at which to start looking for a spot.value - the value to add.
public static int[] testAndAdd(int[] list,
int value)
list - the list to which to add the value. Can be null.value - the value to test and add.
public static boolean contains(int[] list,
int value)
value to this function will cleverly tell you
whether or not there are any empty elements in the array which is
probably not very useful.
public static int indexOf(int[] list,
int value)
value
to this function will cleverly tell you whether or not there are
any empty elements in the array which is probably not very useful.
public static int clear(int[] list,
int value)
value to this function will
cleverly tell you the index of the first empty element in the array
which it will have kindly overwritten with zero just for good
measure.
public static int remove(int[] list,
int value)
public static int removeAt(int[] list,
int index)
public static int[] compact(int[] list)
public static int sum(int[] list)
public static int getMaxValue(int[] values)
Integer.MIN_VALUE if the array is null or zero-length.
public static int getMinValue(int[] values)
Integer.MAX_VALUE if the array is null or zero-length.
public static int getMaxValueIndex(int[] values)
-1 if the array is null or
zero-length.
public static int[] getMaxIndexes(int[] values)
null or zero-length.
public static int[] getMinIndexes(int[] values)
null or zero-length.
public static float[] normalize(int[] values)
protected static int[] accomodate(int[] list,
int index)
public static Integer[] box(int[] list)
public static int[] unbox(Integer[] list)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||