com.samskivert.util
Class CompactIntListUtil

java.lang.Object
  extended by com.samskivert.util.CompactIntListUtil

public class CompactIntListUtil
extends Object

This class manages compact arrays of ints. It is similar to IntListUtil except that the int arrays never contain empty slots and expansion is done one element at a time. In spite of its reduced computational efficiency, compact int lists are at times required.


Constructor Summary
CompactIntListUtil()
           
 
Method Summary
static int[] add(int[] list, int value)
          Adds the specified value to the list iff it is not already in the list.
static boolean contains(int[] list, int value)
          Looks for an element that is equal to the supplied value.
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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompactIntListUtil

public CompactIntListUtil()
Method Detail

add

public static int[] add(int[] list,
                        int value)
Adds the specified value to the list iff it is not already in the list.

Parameters:
list - the list to which to add the value. Can be null.
value - the value to add.
Returns:
a reference to the list with value added (might not be the list you passed in due to expansion, or allocation).

contains

public static boolean contains(int[] list,
                               int value)
Looks for an element that is equal to the supplied value.

Returns:
true if a matching value was found, false otherwise.

indexOf

public 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.

Returns:
the index of the first matching value if one was found, -1 otherwise.

remove

public static int[] remove(int[] list,
                           int value)
Removes the first value that is equal to the supplied value. A new array will be created containing all other elements, except the located element, in the order they existed in the original list.

Returns:
the new array minus the found value, or the original array.

removeAt

public static int[] removeAt(int[] list,
                             int index)
Removes the value at the specified index. A new array will be created containing all other elements, except the specified element, in the order they existed in the original list.

Returns:
the new array minus the specified element.


Copyright © 2000-2008 Michael Bayne. All Rights Reserved.