Top Description Fields Constructors Methods
org.droidparts.dexmaker.dx.util

public final Class IntList

extends MutabilityControl
Class Inheritance
Imports
java.util.Arrays

Simple list of ints.

Field Summary

Modifier and TypeField and Description
public static final IntList
EMPTY

non-null; immutable, no-element instance

private int
size

>= 0; current size of the list

private boolean
sorted

whether the values are currently sorted

private int[]
values

non-null; array of elements

Constructor Summary

AccessConstructor and Description
public
IntList()

Constructs an empty instance with a default initial capacity.

public
IntList(int
>= 0; initial capacity of the list
initialCapacity
)

Constructs an empty instance.

Method Summary

Modifier and TypeMethod and Description
public void
add(int
the value to add
value
)

Adds an element to the end of the list.

public int

Returns:

index of value or (-(insertion point) - 1) if the value is not present
binarysearch
(int
value to find
value
)

Performs a binary search on a sorted list, returning the index of the given value if it is present or (-(insertion point) - 1) if the value is not present.

public boolean

Returns:

whether the list contains the given value
contains
(int
value to look for
value
)

Returns whether or not the given value appears in the list.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int

Returns:

the indicated element's value
get
(int
>= 0, < size(); which element
n
)

Gets the indicated value.

private void
growIfNeeded()

Increases size of array if needed

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public int

Returns:

index of value or -1
indexOf
(int
value to find
value
)

Returns the index of the given value, or -1 if the value does not appear in the list.

public void
insert(int
>= 0, <=size(); index of where to insert
n
,
int
value to insert
value
)

Inserts element into specified index, moving elements at and above that index up one.

public static IntList
makeImmutable(int
the sole value in the list
value
)

Constructs a new immutable instance with the given element.

public static IntList
makeImmutable(int
the first value in the list
value0
,
int
the second value in the list
value1
)

Constructs a new immutable instance with the given elements.

public IntList

Returns:

non-null; an appropriately-constructed instance
mutableCopy
()

Makes and returns a mutable copy of the list.

public int

Returns:

value from what was the last element
pop
()

Pops an element off the end of the list and decreasing the size by one.

public void
pop(int
>= 0; number of elements to remove from end
n
)

Pops N elements off the end of the list and decreasing the size by N.

public void
removeIndex(int
>=0, < size(); index of element to remove
n
)

Removes an element at a given index, shifting elements at greater indicies down one.

public void
set(int
>= 0, < size(); which element
n
,
int
value to store
value
)

Sets the value at the given index.

public void
shrink(int
>= 0; the new size
newSize
)

Shrinks the size of the list.

public int
size()

Gets the number of elements in this list.

public void
sort()

Sorts the elements in the list in-place.

public int

Returns:

last value in the array
top
()

Returns the last element in the array without modifying the array

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.droidparts.dexmaker.dx.util.MutabilityControl:
isImmutableisMutablesetImmutablethrowIfImmutablethrowIfMutable

Field Detail

EMPTYback to summary
public static final IntList EMPTY

non-null; immutable, no-element instance

sizeback to summary
private int size

>= 0; current size of the list

sortedback to summary
private boolean sorted

whether the values are currently sorted

valuesback to summary
private int[] values

non-null; array of elements

Constructor Detail

IntListback to summary
public IntList()

Constructs an empty instance with a default initial capacity.

IntListback to summary
public IntList(int initialCapacity)

Constructs an empty instance.

Parameters
initialCapacity:int

>= 0; initial capacity of the list

Method Detail

addback to summary
public void add(int value)

Adds an element to the end of the list. This will increase the list's capacity if necessary.

Parameters
value:int

the value to add

binarysearchback to summary
public int binarysearch(int value)

Performs a binary search on a sorted list, returning the index of the given value if it is present or (-(insertion point) - 1) if the value is not present. If the list is not sorted, then reverts to linear search and returns -size() if the element is not found.

Parameters
value:int

value to find

Returns:int

index of value or (-(insertion point) - 1) if the value is not present

containsback to summary
public boolean contains(int value)

Returns whether or not the given value appears in the list. This will do a binary search if the list is sorted or a linear search if not.

Parameters
value:int

value to look for

Returns:boolean

whether the list contains the given value

See Also
sort
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getback to summary
public int get(int n)

Gets the indicated value.

Parameters
n:int

>= 0, < size(); which element

Returns:int

the indicated element's value

growIfNeededback to summary
private void growIfNeeded()

Increases size of array if needed

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
indexOfback to summary
public int indexOf(int value)

Returns the index of the given value, or -1 if the value does not appear in the list. This will do a binary search if the list is sorted or a linear search if not.

Parameters
value:int

value to find

Returns:int

index of value or -1

insertback to summary
public void insert(int n, int value)

Inserts element into specified index, moving elements at and above that index up one. May not be used to insert at an index beyond the current size (that is, insertion as a last element is legal but no further).

Parameters
n:int

>= 0, <=size(); index of where to insert

value:int

value to insert

makeImmutableback to summary
public static IntList makeImmutable(int value)

Constructs a new immutable instance with the given element.

Parameters
value:int

the sole value in the list

makeImmutableback to summary
public static IntList makeImmutable(int value0, int value1)

Constructs a new immutable instance with the given elements.

Parameters
value0:int

the first value in the list

value1:int

the second value in the list

mutableCopyback to summary
public IntList mutableCopy()

Makes and returns a mutable copy of the list.

Returns:IntList

non-null; an appropriately-constructed instance

popback to summary
public int pop()

Pops an element off the end of the list and decreasing the size by one.

Returns:int

value from what was the last element

Exceptions
IndexOutOfBoundsException:
if stack is empty
popback to summary
public void pop(int n)

Pops N elements off the end of the list and decreasing the size by N.

Parameters
n:int

>= 0; number of elements to remove from end

Exceptions
IndexOutOfBoundsException:
if stack is smaller than N
removeIndexback to summary
public void removeIndex(int n)

Removes an element at a given index, shifting elements at greater indicies down one.

Parameters
n:int

>=0, < size(); index of element to remove

setback to summary
public void set(int n, int value)

Sets the value at the given index.

Parameters
n:int

>= 0, < size(); which element

value:int

value to store

shrinkback to summary
public void shrink(int newSize)

Shrinks the size of the list.

Parameters
newSize:int

>= 0; the new size

sizeback to summary
public int size()

Gets the number of elements in this list.

sortback to summary
public void sort()

Sorts the elements in the list in-place.

topback to summary
public int top()

Returns the last element in the array without modifying the array

Returns:int

last value in the array

Exceptions
IndexOutOfBoundsException:
if stack is empty
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override