All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jp.kyasu.util.RunArray

java.lang.Object
   |
   +----jp.kyasu.util.RunArray

public class RunArray
extends Object
implements Cloneable, Serializable
The RunArray class implements a space-efficient growable array that tends to be constant over long runs of the possible indices.

Version:
17 Jun 1998
Author:
Kazuki YASUMATSU

Constructor Index

 o RunArray()
Constructs an empty array.
 o RunArray(Class)
Constructs an empty array with the specified component type.
 o RunArray(int, Object)
Constructs an array with the specified size (length), whose every component equals to the specified value.
 o RunArray(int, Object, Class)
Constructs an array with the specified size (length), whose every component equals to the specified value.

Method Index

 o append(int, Object)
Grows the length of this array to the current array's length plus the specified length.
 o append(Object)
Appends the object to this array.
 o append(RunArray)
Appends the components of the RunArray object to this array.
 o clone()
Returns a clone of this array.
 o elements()
Returns an enumeration of the components of this array.
 o elements(int, int)
Returns an enumeration of the components of this array.
 o equals(Object)
Compares two Objects for equality.
 o get(int)
Returns the component object at the specified index.
 o getComponentType()
Returns the component type of this array.
 o getRunLengthAt(int)
Returns the run length (the number of the constant occurrence) at the specified index.
 o getRunOffsetAt(int)
Returns the run offset (the starting index of the constant occurrence) at the specified index.
 o getValueCount()
Returns the number of the components in this array.
 o getValues()
Returns the components in this array.
 o getValues(int, int)
Returns the components in this array.
 o hashCode()
Returns a hashcode for this array.
 o insert(int, RunArray)
Inserts the components of the RunArray object to this array from the specified offset.
 o isEmpty()
Tests if this array has no components.
 o length()
Returns the length of this array, i.e., the number of components in this array.
 o remove(int, int)
Removes the components in this array from the specified offset.
 o removeAll()
Removes all components from this array and sets its length to zero.
 o replace(int, int, RunArray)
Replaces the components of this array with the components of the RunArray object.
 o size()
Returns the size of this array, i.e., the number of components in this array.
 o subarray(int)
Returns a new array that is a subarray of this array.
 o subarray(int, int)
Returns a new array that is a subarray of this array.
 o toString()
Returns a string representation of this array.

Constructors

 o RunArray
 public RunArray()
Constructs an empty array.

 o RunArray
 public RunArray(Class componentType)
Constructs an empty array with the specified component type.

Parameters:
componentType - the component type of the array.
Throws: IllegalArgumentException
if the specified component type is a primitive type.
 o RunArray
 public RunArray(int size,
                 Object value)
Constructs an array with the specified size (length), whose every component equals to the specified value.

Parameters:
size - the size (length) of the array.
value - the components of the array.
 o RunArray
 public RunArray(int size,
                 Object value,
                 Class componentType)
Constructs an array with the specified size (length), whose every component equals to the specified value.

Parameters:
size - the size (length) of the array.
value - the components of the array.
componentType - the component type of the array.
Throws: IllegalArgumentException
if the specified component type is a primitive type.

Methods

 o size
 public final int size()
Returns the size of this array, i.e., the number of components in this array.

Returns:
the size of this array.
 o length
 public final int length()
Returns the length of this array, i.e., the number of components in this array.

Returns:
the length of this array.
 o isEmpty
 public final boolean isEmpty()
Tests if this array has no components.

Returns:
true if this array has no components; false otherwise.
 o elements
 public final Enumeration elements()
Returns an enumeration of the components of this array.

Returns:
an enumeration of the components of this array.
 o elements
 public final Enumeration elements(int begin,
                                   int end)
Returns an enumeration of the components of this array.

Parameters:
begin - the beginning index to get components, inclusive.
end - the ending index to get components, exclusive.
Returns:
an enumeration of the components of this array.
Throws: ArrayIndexOutOfBoundsException
if the begin, or the end is out of range.
 o getComponentType
 public final Class getComponentType()
Returns the component type of this array.

Returns:
the component type of this array.
 o getValueCount
 public final int getValueCount()
Returns the number of the components in this array.

Returns:
the number of the components in this array.
 o getValues
 public final Object[] getValues()
Returns the components in this array.

Returns:
the components in this array.
 o getValues
 public final Object[] getValues(int begin,
                                 int end)
Returns the components in this array.

Parameters:
begin - the beginning index to get components, inclusive.
end - the ending index to get components, exclusive.
Returns:
the components in this array.
Throws: ArrayIndexOutOfBoundsException
if the begin, or the end is out of range.
 o get
 public final Object get(int index)
Returns the component object at the specified index.

Parameters:
index - an index into this array.
Returns:
the component at the specified index.
Throws: ArrayIndexOutOfBoundsException
if an invalid index was given.
 o getRunLengthAt
 public final int getRunLengthAt(int index)
Returns the run length (the number of the constant occurrence) at the specified index.

Parameters:
index - an index into this array.
Returns:
the run length from the specified index.
Throws: ArrayIndexOutOfBoundsException
if an invalid index was given.
 o getRunOffsetAt
 public final int getRunOffsetAt(int index)
Returns the run offset (the starting index of the constant occurrence) at the specified index.

Parameters:
index - an index into this array.
Returns:
the run offset from the specified index.
Throws: ArrayIndexOutOfBoundsException
if an invalid index was given.
 o hashCode
 public int hashCode()
Returns a hashcode for this array.

Returns:
a hash code value for this array.
Overrides:
hashCode in class Object
 o equals
 public boolean equals(Object anObject)
Compares two Objects for equality.

Parameters:
anObject - the reference object with which to compare.
Returns:
true if this array is the same as the anObject argument; false otherwise.
Overrides:
equals in class Object
 o removeAll
 public final void removeAll()
Removes all components from this array and sets its length to zero.

 o remove
 public final void remove(int offset,
                          int size)
Removes the components in this array from the specified offset. The number of the components to be removed is specified by the size. Each component in this array with an index greater or equal to offset+size is shifted downward.

Parameters:
offset - the start index of the components to be removed.
size - the number of the components to be removed.
Throws: ArrayIndexOutOfBoundsException
if the offset or the size were invalid.
 o subarray
 public final RunArray subarray(int beginIndex)
Returns a new array that is a subarray of this array. The subarray begins at the specified index and extends to the end of this array.

Parameters:
beginIndex - the beginning index, inclusive.
Returns:
the subarray.
Throws: ArrayIndexOutOfBoundsException
if the beginIndex is out of range.
 o subarray
 public final RunArray subarray(int beginIndex,
                                int endIndex)
Returns a new array that is a subarray of this array. The subarray begins at the specified beginIndex and extends to the component at index endIndex-1.

Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the subarray.
Throws: ArrayIndexOutOfBoundsException
if the beginIndex or the endIndex is out of range.
 o append
 public final RunArray append(RunArray array)
Appends the components of the RunArray object to this array.

Parameters:
array - an RunArray object.
Returns:
this array.
 o append
 public final RunArray append(Object obj)
Appends the object to this array.

Parameters:
obj - an object.
Returns:
this array.
 o append
 public final RunArray append(int length,
                              Object defObj)
Grows the length of this array to the current array's length plus the specified length. If this array isn't empty, the last value is added to the end of the array. Otherwise, defObj is added to the end of the array.

Parameters:
length - object.
defObj - an object.
Returns:
this array.
 o insert
 public final RunArray insert(int offset,
                              RunArray array)
Inserts the components of the RunArray object to this array from the specified offset.

Parameters:
offset - the start index of the components to be inserted.
array - a RunArray object.
Returns:
this array.
Throws: ArrayIndexOutOfBoundsException
if the offset was invalid.
 o replace
 public final RunArray replace(int begin,
                               int end,
                               RunArray array)
Replaces the components of this array with the components of the RunArray object.

Parameters:
begin - the beginning index to replace, inclusive.
end - the ending index to replace, exclusive.
array - a replacement RunArray object.
Returns:
this array.
Throws: ArrayIndexOutOfBoundsException
if the begin or the end is out of range.
 o toString
 public String toString()
Returns a string representation of this array.

Returns:
a string representation of this array.
Overrides:
toString in class Object
 o clone
 public Object clone()
Returns a clone of this array.

Returns:
a clone of this array.
Overrides:
clone in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index