Class Vector
Class vector is a variable size sequence of objects. Its notation is object[], like int[], which is a vector of 'int's.
There are many methods in vector class: You may add a new object or vector on it or remove an object or a range from it. You may replace range of it with another object or vector.
CONSTRUCTION
SIZE
REFERENCE & ASSIGNEMENT
INSERTION
REPLACEMENT
(object[]) <object[] o>.copy
Create a new object[] from 'this'.
Parameters
Return value
main
int[] iv1
iv1 &= 4
iv1 &= 5
iv1 &= 6
int[] iv2 = iv1.copy
print iv2.get size // LOG: 3
print iv2[0] // LOG: 4
print iv2[1] // LOG: 5
print iv2[2] // LOG: 6
int[] iv3
iv2 = iv3.copy
print iv2.get size // LOG: 0
(object[]) new object[] from <object o> [ size <int n = 1> ]
Create a new vector of length 'n', all objects having value 'o'.
Parameters
- o - Object values
- n - Length of vector. An acceptable value is zero or positive.
Return value
Exceptions
- InvalidArgumentException - If the value of 'n' is not acceptable.
main
int[] iv = new int[] from 5
print iv.get size // LOG: 1
print iv[0] // LOG: 5
iv = new int[] from 5 size 10
print iv.get size // LOG: 10
int i = 0
while i < 10
print iv[i] // LOG: 5
i++
(object[]) []
Creates an empty vector.
Return value
main
int[] iv = []
print iv.get size // LOG: 0
iv = new int[] from 5
print iv.get size // LOG: 1
print iv[0] // LOG: 5
iv = new int[] from 5 size 10
print iv.get size // LOG: 10
int i = 0
while i < 10
print iv[i] // LOG: 5
i++
iv = []
print iv.get size // LOG: 0
(object[]) [<object o>]
Creates a vector from an object.
Parameters
Return value
main
int[] iv = [5]
print iv.get size // LOG: 1
print iv[0] // LOG: 5
iv = new int[] from 5
print iv.get size // LOG: 1
print iv[0] // LOG: 5
iv = new int[] from 5 size 10
print iv.get size // LOG: 10
int i = 0
while i < 10
print iv[i] // LOG: 5
i++
iv = []
print iv.get size // LOG: 0
(int) <object[] o>.get size
Query size of 'this'.
Parameters
Return value
main
int[] iv
print iv.get size // LOG: 0
iv &= 3
print iv.get size // LOG: 1
iv = new int[] from 5 size 1000
print iv.get size // LOG: 1000
(object) [ <int i> ]
Query the object value at the specified position 'i'.
Parameters
Return value
- Reference to the object at the specified position
Exceptions
- IndexOutOfBoundsException - If the position is not within the vector.
main
int[] iv
iv &= 4
iv &= 5
iv &= 6
print iv[1] // LOG: 5
iv[1] = 7
print iv[1] // LOG: 7
<object[] v> *= <int n>
Append itself 'n' - 1 times.
Parameters
- v -
- n - Factor. An acceptable value is zero or positive.
Exceptions
- InvalidArgumentException - If the value of 'n' is not acceptable.
main
int[] iv
iv &= 4
iv &= 5
iv *= 3
print iv.get size // LOG: 6
print iv[0] // LOG: 4
print iv[1] // LOG: 5
print iv[2] // LOG: 4
print iv[3] // LOG: 5
print iv[4] // LOG: 4
print iv[5] // LOG: 5
<object[] v> &= <object o>
Append an object to a vector.
Parameters
- v -
- o - Object to be appended to the vector.
main
int[] iv
iv &= 4
iv &= 5
iv &= 3
print iv.get size // LOG: 3
print iv[0] // LOG: 4
print iv[1] // LOG: 5
print iv[2] // LOG: 3
<object[] v> &= <object[] o>
Append an object to a vector.
Parameters
- v -
- o - Vector of objects to be appended to the vector.
main
int[] iv
iv &= 4
iv &= 5
iv &= iv
print iv.get size // LOG: 4
print iv[0] // LOG: 4
print iv[1] // LOG: 5
print iv[2] // LOG: 4
print iv[3] // LOG: 5
<object[] v> [ <range r> ] = <object[] ov>
Replace range 'r' of vector with a vector 'ov'.
Parameters
- v -
- r - Range
- ov - A substitutive vector
Exceptions
- InvalidRangeException - If the specified range is not within the vector.
main
int[] iv1
iv1 &= 1
iv1 &= 2
iv1 &= 3
iv1 &= 4
iv1 &= 5
int[] iv2
iv2 &= 0
iv2 &= 0
iv1[ 0 size 2 ] = iv2
print iv1.get size // LOG: 4
print iv1[0] // LOG: 1
print iv1[1] // LOG: 2
print iv1[2] // LOG: 0
print iv1[3] // LOG: 0
iv1[ 0 size 1 ] = [5]
print iv1.get size // LOG: 2
print iv1[0] // LOG: 1
print iv1[1] // LOG: 5