Class pmr.euclid.IntArray
All Packages Class Hierarchy This Package Previous Next Index
Class pmr.euclid.IntArray
java.lang.Object
|
+----pmr.euclid.Status
|
+----pmr.euclid.IntArray
- public class IntArray
- extends Status
IntArray - array of ints
IntArray represents a 1-dimensional vector/array of ints and
is basically a wrapper for int[] in Java
There are a lot of useful member functions (sorting, ranges, parallel
operations, etc. - have a look)
The default is an array with zero points. All arrays are valid objects.
Attempting to create an array with < 0 points creates a default array
(zero points).
Since int[] knows its length (unlike C), there are many cases where
int[] can be safely used. However it is not a first-class object
and IntArray supplies this feature. int[] is referenceable
through getArray().
- Author:
- (C) P. Murray-Rust, 1996
-
IntArray()
- default is an array of zero points
-
IntArray(int)
- creates n-element array initialised to 0
-
IntArray(int, int)
- set all elements of the array to a given value
-
IntArray(int, int, int)
- This gives a nelem-element array initialised to elem1+(i-1)*delta
-
IntArray(int, int[])
- Formed by feeding in an existing array; requires the size.
-
IntArray(int, String, int)
- Create a given 'shape' of array for data filtering.
-
IntArray(int[])
- from an existing int[] (which knows its length)
-
IntArray(IntArray)
- copy constructor
-
IntArray(IntArray, int, int)
- subarray of another array - inclusive; if low > high or other silly
indices, creates default array
-
IntArray(String)
- from a String with space-separated strings representing Ints
-
IntArray(String[])
- from an array of Strings (which must represent Ints)
-
absSumAllElements()
- absolute sum of all elements
-
addArray(IntArray)
- append elements
-
addElement(int)
- append element
-
applyFilter(IntArray)
- apply filter (i.e.
-
clearArray()
- clear all elements of array
-
clone()
- clones another IntArray
-
copy(int[])
- copy a int[] into a new one
-
cumulativeSum()
- cumulative sum of array (new RA contains
elem[i] = sum(k = 0 to i) f[k]
does not modify 'this'
-
deleteElement(int)
- delete element and close up; if outside range, take no action
-
deleteElements(int, int)
- delete elements and close up; if outside range take no action
-
deleteElements(int[], int, int)
- delete elements (lo - > hi inclusive) in a float[] and close up;
if hi >= float.length hi is reset to float.length-1.
-
dotProduct(IntArray)
- dot product of two IntArrays - if of same length - else zero
-
elementAt(int)
- extracts a given element from the array
-
equals(IntArray)
- are two arrays equal in all elements? (use epsilon as tolerance)
-
getArray()
- return the array as a int[]; this has to resize the array to the precise
length used , or confusion will result! Note that this gives the user access to
the actual array, so that they can alter its contents.
-
getReorderedArray(IntSet)
- reorder by index in IntSet; does NOT modify array
-
getReverseArray()
- return the elements in reverse order as int[]
-
getStringValues()
- returns values as strings
-
getSubArray(int, int)
- RHS: get a subIntArray from element start to end
-
indexOfLargestElement()
- index of largest element; returns -1 if zero element array
-
indexOfSmallestElement()
- index of smallest element
-
indexSortAscending()
-
-
indexSortDescending()
- sort array into descending order via indexes; array NOT MODIFIED
-
innerProduct()
- inner product - same as dotProduct
-
inRange(IntRange)
- return index of elements within a given range
-
insertArray(int, IntArray)
- insert a IntArray at position elem and expand
-
insertElementAt(int, int)
- insert element and expand; if outside range, take no action
-
isClear()
- is the array filled with zeros?
-
largestElement()
- value of largest element
-
main(String[])
-
-
multiplyBy(int)
- array multiplication by a scalar; does NOT modify 'this'
-
negative()
- change the sign of all elements; MODIFIES this
-
outOfRange(IntRange)
- return index of elements outside a given range
-
plus(IntArray)
- array addition - adds conformable arrays
-
range()
- range of array (default IntRange for zero array)
-
reverse()
- MODIFIES array to be in reverse order
-
setAllElements(int)
- initialise array to given int[]
-
setElementAt(int, int)
- set a given element into the array; must be less than current max index
-
setElements(int, int[])
- copy a smaller array into the array statrting at start
-
setMaxIndex(int)
- reset the maximum index (for when poking elements) (no other effect)
-
shallowCopy(IntArray)
- shallowCopy
-
size()
- get actual number of elements
-
smallestElement()
- value of smallest element
-
sortAscending()
- MODIFIES array to be in ascending order
-
sortDescending()
- MODIFIES array to be in ascending order
-
subtract(IntArray)
- array subtraction - subtracts conformable arrays
-
sumAllElements()
- sum all elements
-
test()
-
-
toString()
- concatenates values with spaces
IntArray
public IntArray()
- default is an array of zero points
IntArray
public IntArray(int n)
- creates n-element array initialised to 0
IntArray
public IntArray(int n,
int elem1,
int delta)
- This gives a nelem-element array initialised to elem1+(i-1)*delta
IntArray
public IntArray(int n,
int elem1)
- set all elements of the array to a given value
IntArray
public IntArray(int n,
int arr[])
- Formed by feeding in an existing array; requires the size.
(You can use the *.length of the array if necessary)
IntArray
public IntArray(int arr[])
- from an existing int[] (which knows its length)
IntArray
public IntArray(IntArray m,
int low,
int high)
- subarray of another array - inclusive; if low > high or other silly
indices, creates default array
IntArray
public IntArray(IntArray m)
- copy constructor
IntArray
public IntArray(int nn,
String shape,
int maxval)
- Create a given 'shape' of array for data filtering. An intended use
is with IntArray.arrayFilter().
The shapes (before scaling by maxval) are:
- "TRIANGLE"; 1/nn, 2/nn, ... 1 ... 2/nn, 1/nn; nelem is set to 2*nn - 1
- "ZIGZAG"; 1/nn, 2/nn, ... 1 ... 1/nn, 0, -1/nn, -2/nn, -1, ... -1/nn,;
nelem is set to 4*nn - 1
IntArray
public IntArray(String strings[]) throws NumberFormatException
- from an array of Strings (which must represent Ints)
- Throws: NumberFormatException
- a string could not be interpreted as Int
IntArray
public IntArray(String string) throws NumberFormatException
- from a String with space-separated strings representing Ints
- Throws: NumberFormatException
- a string could not be interpreted as Int
clone
public Object clone()
- clones another IntArray
- Overrides:
- clone in class Object
shallowCopy
public void shallowCopy(IntArray m)
- shallowCopy
elementAt
public int elementAt(int elem) throws ArrayIndexOutOfBoundsException
- extracts a given element from the array
- Throws: ArrayIndexOutOfBoundsException
- elem >= size of this
size
public int size()
- get actual number of elements
getArray
public int[] getArray()
- return the array as a int[]; this has to resize the array to the precise
length used , or confusion will result! Note that this gives the user access to
the actual array, so that they can alter its contents. This should be used
with care, but Java should stop any access outside the buffer limits.
clearArray
public void clearArray()
- clear all elements of array
getReverseArray
public int[] getReverseArray()
- return the elements in reverse order as int[]
setMaxIndex
public void setMaxIndex(int max)
- reset the maximum index (for when poking elements) (no other effect)
equals
public boolean equals(IntArray f) throws UnequalLengthArraysException
- are two arrays equal in all elements? (use epsilon as tolerance)
- Throws: UnequalLengthArraysException
- f is different size from this
plus
public IntArray plus(IntArray f) throws UnequalLengthArraysException
- array addition - adds conformable arrays
- Throws: UnequalLengthArraysException
- f is different size from this
subtract
public IntArray subtract(IntArray f) throws UnequalLengthArraysException
- array subtraction - subtracts conformable arrays
- Throws: UnequalLengthArraysException
- f is different size from this
negative
public void negative()
- change the sign of all elements; MODIFIES this
multiplyBy
public IntArray multiplyBy(int f)
- array multiplication by a scalar; does NOT modify 'this'
setElementAt
public void setElementAt(int elem,
int f) throws ArrayIndexOutOfBoundsException
- set a given element into the array; must be less than current max index
- Throws: ArrayIndexOutOfBoundsException
- elem >= size of this
getSubArray
public IntArray getSubArray(int start,
int end)
- RHS: get a subIntArray from element start to end
setElements
public void setElements(int start,
int a[])
- copy a smaller array into the array statrting at start
isClear
public boolean isClear()
- is the array filled with zeros?
setAllElements
public void setAllElements(int f)
- initialise array to given int[]
sumAllElements
public int sumAllElements()
- sum all elements
absSumAllElements
public int absSumAllElements()
- absolute sum of all elements
innerProduct
public int innerProduct()
- inner product - same as dotProduct
dotProduct
public int dotProduct(IntArray f) throws UnequalLengthArraysException
- dot product of two IntArrays - if of same length - else zero
- Throws: UnequalLengthArraysException
- f is different size from this
cumulativeSum
public IntArray cumulativeSum()
- cumulative sum of array (new RA contains
elem[i] = sum(k = 0 to i) f[k]
does not modify 'this'
applyFilter
public IntArray applyFilter(IntArray filter)
- apply filter (i.e. convolute RA with another RA). This is 1-D
image processing. If filter has <= 1 element, return this
unchanged. filter should have an odd number of elements.
The filter can be created with a IntArray constructor
indexOfLargestElement
public int indexOfLargestElement()
- index of largest element; returns -1 if zero element array
indexOfSmallestElement
public int indexOfSmallestElement()
- index of smallest element
largestElement
public int largestElement()
- value of largest element
smallestElement
public int smallestElement()
- value of smallest element
range
public IntRange range()
- range of array (default IntRange for zero array)
deleteElement
public void deleteElement(int elem)
- delete element and close up; if outside range, take no action
deleteElements
public void deleteElements(int low,
int high)
- delete elements and close up; if outside range take no action
insertElementAt
public void insertElementAt(int elem,
int f)
- insert element and expand; if outside range, take no action
insertArray
public void insertArray(int elem,
IntArray f)
- insert a IntArray at position elem and expand
addElement
public void addElement(int f)
- append element
addArray
public void addArray(IntArray f)
- append elements
getReorderedArray
public IntArray getReorderedArray(IntSet idx) throws BadSubscriptException
- reorder by index in IntSet; does NOT modify array
- Throws: BadSubscriptException
- an element of idx is outside range of this
inRange
public IntSet inRange(IntRange r)
- return index of elements within a given range
outOfRange
public IntSet outOfRange(IntRange r)
- return index of elements outside a given range
getStringValues
public String[] getStringValues()
- returns values as strings
toString
public String toString()
- concatenates values with spaces
- Overrides:
- toString in class Object
deleteElements
public static int[] deleteElements(int f[],
int low,
int hi)
- delete elements (lo - > hi inclusive) in a float[] and close up;
if hi >= float.length hi is reset to float.length-1.
copy
public static int[] copy(int f[])
- copy a int[] into a new one
sortAscending
public void sortAscending()
- MODIFIES array to be in ascending order
sortDescending
public void sortDescending()
- MODIFIES array to be in ascending order
reverse
public void reverse()
- MODIFIES array to be in reverse order
indexSortAscending
public IntSet indexSortAscending()
indexSortDescending
public IntSet indexSortDescending()
- sort array into descending order via indexes; array NOT MODIFIED
test
public static void test()
main
public static void main(String args[])
All Packages Class Hierarchy This Package Previous Next Index