org.abora.white.collection.arrays
Class PrimArray

java.lang.Object
  |
  +--org.abora.white.xpp.basic.Heaper
        |
        +--org.abora.white.collection.arrays.PrimArray
Direct Known Subclasses:
PrimArithmeticArray, PtrArray

public abstract class PrimArray
extends Heaper

Array object of a fixed size composed of elements of the same type.


Constructor Summary
protected PrimArray()
          Construct a new array.
 
Method Summary
abstract  boolean contentsEqual(PrimArray other)
          Whether the two ranges contain semantically the same values.
 int contentsHash()
          A hash of the entire contents of the array.
 PrimArray copy()
          Return a copy of this.
 PrimArray copy(int count)
          Return a copy of this including just the first count elements.
 PrimArray copy(int count, int start)
          Return a copy of this including just the elements specified by the index range.
 PrimArray copy(int count, int start, int before)
          Return a copy of this including just the elements specified by the index range prepended by before number of null or 0 elements.
 PrimArray copy(int count, int start, int before, int after)
          Return a copy of this including just the elements specified by the index range prepended by before, and postpended by after number of null or 0 elements.
protected  void copyElements(int to, PrimArray other, int from, int count)
          Copy the respective elements of other to this over the specified index range.
 PrimArray copyGrow(int after)
          Return a copy of this with after null/0 elements postpended to the copied elements.
abstract  int count()
          Return the number of elements the array can hold.
 boolean elementsEqual(int here, PrimArray other)
           
 boolean elementsEqual(int here, PrimArray other, int there)
           
abstract  boolean elementsEqual(int here, PrimArray other, int there, int n)
          Whether the two ranges contain the same values, using the criteria defined in contentsEqual
 int elementsHash()
           
 int elementsHash(int count)
           
abstract  int elementsHash(int count, int start)
          A hash of the range of values out of the array.
abstract  Heaper fetchValue(int index)
          Fetch a value; may be a Heaper, null, or a PrimValue as appropriate to PrimArray subclass.
 Heaper getValue(int index)
          Fetch a value; may be a Heaper or a PrimValue as appropriate to PrimArray subclass, or throw an exception if value is null.
 int indexOf(Heaper value)
          Return the index of the first occurrence of the given value, or -1 if there is none.
 int indexOf(Heaper value, int start)
          Return the index of the first occurrence of the given value at or after (before if nth is negative) the given index, or -1 if there is none.
abstract  int indexOf(Heaper value, int start, int n)
          Return the index of the nth occurrence of the given value at or after (before if nth is negative) the given index, or -1 if there is none.
 int indexOfElements(PrimArray other)
          Return the index of the first occurrence of other in this or -1 if there is none.
 int indexOfElements(PrimArray other, int otherCount)
          Return the index of the first occurrence of the given sequence of values of other in this, or -1 if there is none.at or after (before if nth is negative) the given
 int indexOfElements(PrimArray other, int otherCount, int otherStart)
          Return the index of the first occurrence of the given sequence of values of other in this, or -1 if there is none.at or after (before if nth is negative) the given
 int indexOfElements(PrimArray other, int otherCount, int otherStart, int start)
          Return the index of the first occurrence of the given sequence of values of other at or after the given index index in this, or -1 if there is none.
 int indexOfElements(PrimArray other, int otherCount, int otherStart, int start, int nth)
          Return the index of the nth occurrence of the given sequence of values of other at or after (before if nth is negative) the given index in this, or -1 if there is none.
 int indexPast(Heaper value)
          Return the index of the first occurrence of anything but the given value, or -1 if there is none.
 int indexPast(Heaper value, int start)
          Return the index of the first occurrence of anything but the given value at or after (before if nth is negative) the given index, or -1 if there is none.
abstract  int indexPast(Heaper value, int start, int n)
          Return the index of the nth occurrence of anything but the given value at or after (before if nth is negative) the given index, or -1 if there is none.
 boolean isEqual(Heaper other)
          Return true if the two objects are equal.
protected abstract  PrimArray makeNew(int size, PrimArray source, int sourceOffset, int count, int destOffset)
          Return a new array of the same type as this initialized with the elements of source specified by the index range, prepended by destOffset and postpended by null or 0 elements.
protected  void printElementOn(int index, java.io.PrintWriter oo)
          Print a representation of the element at the given index.
 void printOn(java.io.PrintWriter oo)
          This should rarely be overridden.
abstract  PrimSpec spec()
          A description of the kinds of things which can be stored in this array
 void storeAll(Heaper value)
          Fill every element of this to value or null or 0 depending on the type of array.
 void storeAll(Heaper value, int count)
           
abstract  void storeAll(Heaper value, int count, int start)
          Fill a consequitive range of elements with the supplied value.
 void storeMany(int to, PrimArray other)
          Copy n elements from the other array into this one.
 void storeMany(int to, PrimArray other, int count)
          Copy n elements from the other array into this one.
 void storeMany(int to, PrimArray other, int count, int from)
          Copy the respective elements of other to this over the specified index range.
abstract  void storeValue(int index, Heaper value)
          Store a value; may be a Heaper, null, or a PrimValue as appropriate to PrimArray subclass.
protected abstract  Heaper zeroElement()
          Return a suitable immutable zero element for this type of array; either 0 or null.
 void zeroElements()
           
 void zeroElements(int from)
           
 void zeroElements(int from, int count)
           
 
Methods inherited from class org.abora.white.xpp.basic.Heaper
actualHashForEqual, destroy, destruct, equals, hashForEqual, printContentsOn, sendSelfTo, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrimArray

protected PrimArray()
Construct a new array. Restrict public access to constructor; use suitable static factory method instead.

Method Detail

makeNew

protected abstract PrimArray makeNew(int size,
                                     PrimArray source,
                                     int sourceOffset,
                                     int count,
                                     int destOffset)
Return a new array of the same type as this initialized with the elements of source specified by the index range, prepended by destOffset and postpended by null or 0 elements.

Parameters:
size - size of new array.
source - source of elements to be initialized with in the new array.
sourceOffset - first index of the source array to be included in the range.
count - number of elements of source to include in the new array
destOffset - first index of new array to be initialized with source elements.
Returns:
the new array.

count

public abstract int count()
Return the number of elements the array can hold.


spec

public abstract PrimSpec spec()
A description of the kinds of things which can be stored in this array


storeValue

public abstract void storeValue(int index,
                                Heaper value)
Store a value; may be a Heaper, null, or a PrimValue as appropriate to PrimArray subclass. An exception will be throw if the value is not compatible with the elements this can hold.

It is expected that most PrimArray clients will want to use less abstract access methods

Parameters:
index - index in array the element will be stored at.
value - heaper to store in this.
Throws:
java.lang.ClassCastException - if value is not compatible with the elements of this array
java.lang.IllegalArgumentException - if value can not be held by this array

fetchValue

public abstract Heaper fetchValue(int index)
Fetch a value; may be a Heaper, null, or a PrimValue as appropriate to PrimArray subclass.

It is expected that most PrimArray clients will want to use less abstract access methods.

Parameters:
index - index in array whose element will be returned
Returns:
the heaper at the specified index.

getValue

public Heaper getValue(int index)
Fetch a value; may be a Heaper or a PrimValue as appropriate to PrimArray subclass, or throw an exception if value is null.

It is expected that most PrimArray clients will want to use less abstract access methods.

Parameters:
index - index in array whose element will be returned.
Returns:
the heaper at the specified index.
Throws:
NotInTableException - if a null value was fetched.

isEqual

public boolean isEqual(Heaper other)
Description copied from class: Heaper
Return true if the two objects are equal.

Specified by:
isEqual in class Heaper

contentsEqual

public abstract boolean contentsEqual(PrimArray other)
Whether the two ranges contain semantically the same values. Two non-NULL pointers match iff the Heapers they point to are isEqual. Two integers match iff they have the same value, even though they may be represented as different sizes. Two floats likewise.


contentsHash

public int contentsHash()
A hash of the entire contents of the array. If two arrays are contentsEqual, they will have the same contentsHash.


elementsEqual

public abstract boolean elementsEqual(int here,
                                      PrimArray other,
                                      int there,
                                      int n)
Whether the two ranges contain the same values, using the criteria defined in contentsEqual


elementsEqual

public boolean elementsEqual(int here,
                             PrimArray other,
                             int there)

elementsEqual

public boolean elementsEqual(int here,
                             PrimArray other)

elementsHash

public abstract int elementsHash(int count,
                                 int start)
A hash of the range of values out of the array. If two ranges are elementsEqual, they will have the same hash. For data values, additional zeros on the end make no difference to the hash.


elementsHash

public int elementsHash(int count)

elementsHash

public int elementsHash()

storeAll

public abstract void storeAll(Heaper value,
                              int count,
                              int start)
Fill a consequitive range of elements with the supplied value.

Parameters:
value - to store within range or 0.0 if null.
count - number of consequentive elements in range or all elements from start if -1.
start - index of first element in range.
Throws:
java.lang.ClassCastException - if other is not compatible with this array
java.lang.IllegalArgumentException - if others elements can not be held by this array

storeAll

public void storeAll(Heaper value,
                     int count)

storeAll

public void storeAll(Heaper value)
Fill every element of this to value or null or 0 depending on the type of array.


storeMany

public void storeMany(int to,
                      PrimArray other,
                      int count,
                      int from)
Copy the respective elements of other to this over the specified index range. The other array must be of a compatible type.

Parameters:
to - first index of receiver to be included in the receivers range..
other - other elements to be copied into this.
count - number of elements from the other array included in range, or -1 for all others elements starting at from. Fail if count is greater than number of available elements.
from - first index of the other array to be included in the range.
Throws:
java.lang.ClassCastException - if other is not compatible with this array
java.lang.IllegalArgumentException - if others elements can not be held by this array

storeMany

public void storeMany(int to,
                      PrimArray other,
                      int count)
Copy n elements from the other array into this one. The other array must be of a compatible type.


storeMany

public void storeMany(int to,
                      PrimArray other)
Copy n elements from the other array into this one. The other array must be of a compatible type.


copy

public PrimArray copy(int count,
                      int start,
                      int before,
                      int after)
Return a copy of this including just the elements specified by the index range prepended by before, and postpended by after number of null or 0 elements.

If before == 10, then the the resulting array with be 10 elements larger and the copied elements would start at index 10.

Parameters:
count - number of elements to copy, or -1 for all from and after start
start - index of first element to copy from
before - number of leading null or 0 elements to include before the copied elements in the returned array.
after - number of trailing null or 0 elements to include after the copied elements in the returned array.
Returns:
PrimArray a copy of this.

copy

public PrimArray copy(int count,
                      int start,
                      int before)
Return a copy of this including just the elements specified by the index range prepended by before number of null or 0 elements.

If before == 10, then the the resulting array with be 10 elements larger and the copied elements would start at index 10.

Parameters:
count - number of elements to copy, or -1 for all from and after start
start - index of first element to copy from
before - number of leading null or 0 elements in include before the copied elements in the returned array.
Returns:
PrimArray a copy of this.

copy

public PrimArray copy(int count,
                      int start)
Return a copy of this including just the elements specified by the index range.

Parameters:
count - number of elements to copy, or -1 for all from and after start
start - index of first element to copy from
Returns:
PrimArray a copy of this

copy

public PrimArray copy(int count)
Return a copy of this including just the first count elements.

Parameters:
count -
Returns:
PrimArray a copy of this.

copy

public PrimArray copy()
Return a copy of this.

Returns:
a copy of this.

copyGrow

public PrimArray copyGrow(int after)
Return a copy of this with after null/0 elements postpended to the copied elements.

Parameters:
after - number of trailing null or 0 elements to include after the copied elements in the returned array.

copyElements

protected void copyElements(int to,
                            PrimArray other,
                            int from,
                            int count)
Copy the respective elements of other to this over the specified index range. The other array must be of a compatible type.

Parameters:
to - first index of receiver to be included in the receivers range..
other - other elements to be copied into this.
from - first index of the other array to be included in the range.
count - number of elements from the other array included in range, or -1 for all others elements starting at from. Fail if count is greater than number of available elements.

indexOf

public abstract int indexOf(Heaper value,
                            int start,
                            int n)
Return the index of the nth occurrence of the given value at or after (before if nth is negative) the given index, or -1 if there is none.

Parameters:
value - element that is to be matched
start - index to start the search. If positive start from that index, if negative start from relatie to end of array
Returns:
index of element matched or -1 if there is none

indexOf

public int indexOf(Heaper value,
                   int start)
Return the index of the first occurrence of the given value at or after (before if nth is negative) the given index, or -1 if there is none.

Parameters:
value - element that is to be matched
start - index to start the search. If positive start from that index, if negative start from relatie to end of array
Returns:
index of element matched or -1 if there is none

indexOf

public int indexOf(Heaper value)
Return the index of the first occurrence of the given value, or -1 if there is none.

Parameters:
value - element that is to be matched
Returns:
index of element matched or -1 if there is none

indexPast

public abstract int indexPast(Heaper value,
                              int start,
                              int n)
Return the index of the nth occurrence of anything but the given value at or after (before if nth is negative) the given index, or -1 if there is none.

Parameters:
value - anything except this element that is to be matched
start - index to start the search. If positive start from that index, if negative start from relatie to end of array
Returns:
index of element matched or -1 if there is none

indexPast

public int indexPast(Heaper value,
                     int start)
Return the index of the first occurrence of anything but the given value at or after (before if nth is negative) the given index, or -1 if there is none.

Parameters:
value - anything except this element that is to be matched
start - index to start the search. If positive start from that index, if negative start from relatie to end of array
Returns:
index of element matched or -1 if there is none

indexPast

public int indexPast(Heaper value)
Return the index of the first occurrence of anything but the given value, or -1 if there is none.

Parameters:
value - anything except this element that is to be matched
Returns:
index of element matched or -1 if there is none

indexOfElements

public int indexOfElements(PrimArray other,
                           int otherCount,
                           int otherStart,
                           int start,
                           int nth)
Return the index of the nth occurrence of the given sequence of values of other at or after (before if nth is negative) the given index in this, or -1 if there is none. Negative numbers for start are relative to the end of the array.

Parameters:
other - array of elements that is being searched for in this.
otherCount - number of elements from other that is being searched for, or -1 to include all elements after otherStart.
otherStart - index of first element of other to start searching for.
start - index to start the search from. If positive start from that index, if negative start from relative to end of array where -1 is the last valid index.
nth - nth occurrence of the matched value at or after the start if positive, or at or before if negative. A 0 nth immediately fails.
Returns:
index of match or -1 if failed

indexOfElements

public int indexOfElements(PrimArray other,
                           int otherCount,
                           int otherStart,
                           int start)
Return the index of the first occurrence of the given sequence of values of other at or after the given index index in this, or -1 if there is none. Negative numbers for start are relative to the end of the array.

Parameters:
other - array of elements that is being searched for in this.
otherCount - number of elements from other that is being searched for, or -1 to include all elements after otherStart.
otherStart - index of first element of other to start searching for.
start - index to start the search from. If positive start from that index, if negative start from relative to end of array where -1 is the last valid index.
Returns:
index of match or -1 if failed

indexOfElements

public int indexOfElements(PrimArray other,
                           int otherCount,
                           int otherStart)
Return the index of the first occurrence of the given sequence of values of other in this, or -1 if there is none.at or after (before if nth is negative) the given

Parameters:
other - array of elements that is being searched for in this.
otherCount - number of elements from other that is being searched for, or -1 to include all elements after otherStart.
otherStart - index of first element of other to start searching for.
Returns:
index of match or -1 if failed

indexOfElements

public int indexOfElements(PrimArray other,
                           int otherCount)
Return the index of the first occurrence of the given sequence of values of other in this, or -1 if there is none.at or after (before if nth is negative) the given

Parameters:
other - array of elements that is being searched for in this.
otherCount - number of elements from other that is being searched for, or -1 to include all elements.
Returns:
index of match or -1 if failed

indexOfElements

public int indexOfElements(PrimArray other)
Return the index of the first occurrence of other in this or -1 if there is none.

Parameters:
other - array of elements that is being searched for in this.
Returns:
index of match or -1 if failed

printOn

public void printOn(java.io.PrintWriter oo)
Description copied from class: Heaper
This should rarely be overridden. In Tofu, it prints ClassName(...), where ... is either produced by printInsideOn or is ??? if printInsideOn it not overridden.

Overrides:
printOn in class Heaper

printElementOn

protected void printElementOn(int index,
                              java.io.PrintWriter oo)
Print a representation of the element at the given index.

Parameters:
index - index of element to be printed.
oo - print stream to write element representation to.

zeroElements

public void zeroElements(int from,
                         int count)

zeroElements

public void zeroElements(int from)

zeroElements

public void zeroElements()

zeroElement

protected abstract Heaper zeroElement()
Return a suitable immutable zero element for this type of array; either 0 or null.

Returns:
zero element for this type of array


Copyright © 2003 David G Jones. All Rights Reserved.
Original Udanax-Gold - Copyright © 1979-1999 Udanax.com. All rights reserved.