APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.utils

public Class BooleanArray

extends Object
Class Inheritance
Imports
com.badlogic.gdx.math.MathUtils, java.util.BitSet

A resizable, ordered or unordered boolean array. Avoids the boxing that occurs with ArrayList. It is less memory efficient than BitSet, except for very small sizes. It more CPU efficient than BitSet, except for very large sizes or if BitSet functionality such as and, or, xor, etc are needed. If unordered, this class avoids a memory copy when removing elements (the last element is moved to the removed element's position).
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
public boolean[]
public boolean
public int

Constructor Summary

AccessConstructor and Description
public
BooleanArray()

Creates an ordered array with a capacity of 16.

public
BooleanArray(int capacity)

Creates an ordered array with the specified capacity.

public
BooleanArray(boolean
If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
ordered
,
int
Any elements added beyond this will cause the backing array to be grown.
capacity
)

public
BooleanArray(BooleanArray array)

Creates a new array containing the elements in the specific array.

public
BooleanArray(boolean[] array)

Creates a new ordered array containing the elements in the specified array.

public
BooleanArray(boolean
If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
ordered
,
boolean[] array, int startIndex, int count)

Creates a new array containing the elements in the specified array.

Method Summary

Modifier and TypeMethod and Description
public void
add(boolean value)

public void
add(boolean value1, boolean value2)

public void
add(boolean value1, boolean value2, boolean value3)

public void
add(boolean value1, boolean value2, boolean value3, boolean value4)

public void
public void
addAll(BooleanArray array, int offset, int length)

public void
addAll(boolean... array)

public void
addAll(boolean[] array, int offset, int length)

public void
public boolean[]

Returns:

items
ensureCapacity
(int additionalCapacity)

Increases the size of the backing array to accommodate the specified number of additional items.

public boolean
equals(Object object)

Overrides java.lang.Object.equals.

Returns false if either array is unordered.

public boolean
first()

Returns the first item.

public boolean
get(int index)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public void
insert(int index, boolean value)

public void
insertRange(int index, int count)

Inserts the specified number of items at the specified index.

public boolean
isEmpty()

Returns true if the array is empty.

public boolean
notEmpty()

Returns true if the array has one or more items.

public boolean
peek()

Returns the last item.

public boolean
pop()

Removes and returns the last item.

public boolean
random()

Returns a random item from the array, or false if the array is empty.

public boolean

Returns:

true if this array was modified.
removeAll
(BooleanArray array)

Removes from this array the first instance of each element contained in the specified array.

public boolean
removeIndex(int index)

Removes and returns the item at the specified index.

public void
removeRange(int start, int end)

Removes the items between the specified indices, inclusive.

public int

Returns:

the number of replacements done
replaceAll
(boolean
the boolean to be replaced
value
,
boolean
all occurrences of value will be replaced by this replacement
replacement
)

Returns the number of replacements done.

public boolean

Returns:

if value was found and replaced
replaceFirst
(boolean
the boolean to be replaced
value
,
boolean
the first value will be replaced by this replacement if found
replacement
)

Returns true if the specified value was replaced successfully with the replacement

protected boolean[]
resize(int newSize)

public void
public void
set(int index, boolean value)

public boolean[]

Returns:

items
setSize
(int newSize)

Sets the array size, leaving any values beyond the current size undefined.

public boolean[]

Returns:

items
shrink
()

Reduces the size of the backing array to the size of the actual items.

public void
public void
swap(int first, int second)

public boolean[]
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public String
toString(String separator)

public void
truncate(int newSize)

Reduces the size of the array to the specified size.

public static BooleanArray
with(boolean... array)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

itemsback to summary
public boolean[] items
orderedback to summary
public boolean ordered
sizeback to summary
public int size

Constructor Detail

BooleanArrayback to summary
public BooleanArray()

Creates an ordered array with a capacity of 16.

BooleanArrayback to summary
public BooleanArray(int capacity)

Creates an ordered array with the specified capacity.

BooleanArrayback to summary
public BooleanArray(boolean ordered, int capacity)
Parameters
ordered:boolean

If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.

capacity:int

Any elements added beyond this will cause the backing array to be grown.

BooleanArrayback to summary
public BooleanArray(BooleanArray array)

Creates a new array containing the elements in the specific array. The new array will be ordered if the specific array is ordered. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.

BooleanArrayback to summary
public BooleanArray(boolean[] array)

Creates a new ordered array containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.

BooleanArrayback to summary
public BooleanArray(boolean ordered, boolean[] array, int startIndex, int count)

Creates a new array containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.

Parameters
ordered:boolean

If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.

Method Detail

addback to summary
public void add(boolean value)
addback to summary
public void add(boolean value1, boolean value2)
addback to summary
public void add(boolean value1, boolean value2, boolean value3)
addback to summary
public void add(boolean value1, boolean value2, boolean value3, boolean value4)
addAllback to summary
public void addAll(BooleanArray array)
addAllback to summary
public void addAll(BooleanArray array, int offset, int length)
addAllback to summary
public void addAll(boolean... array)
addAllback to summary
public void addAll(boolean[] array, int offset, int length)
clearback to summary
public void clear()
ensureCapacityback to summary
public boolean[] ensureCapacity(int additionalCapacity)

Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes.

Returns:boolean[]

items

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Returns false if either array is unordered.

firstback to summary
public boolean first()

Returns the first item.

getback to summary
public boolean get(int index)
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.
insertback to summary
public void insert(int index, boolean value)
insertRangeback to summary
public void insertRange(int index, int count)

Inserts the specified number of items at the specified index. The new items will have values equal to the values at those indices before the insertion.

isEmptyback to summary
public boolean isEmpty()

Returns true if the array is empty.

notEmptyback to summary
public boolean notEmpty()

Returns true if the array has one or more items.

peekback to summary
public boolean peek()

Returns the last item.

popback to summary
public boolean pop()

Removes and returns the last item.

randomback to summary
public boolean random()

Returns a random item from the array, or false if the array is empty.

removeAllback to summary
public boolean removeAll(BooleanArray array)

Removes from this array the first instance of each element contained in the specified array.

Returns:boolean

true if this array was modified.

removeIndexback to summary
public boolean removeIndex(int index)

Removes and returns the item at the specified index.

removeRangeback to summary
public void removeRange(int start, int end)

Removes the items between the specified indices, inclusive.

replaceAllback to summary
public int replaceAll(boolean value, boolean replacement)

Returns the number of replacements done.

Parameters
value:boolean

the boolean to be replaced

replacement:boolean

all occurrences of value will be replaced by this replacement

Returns:int

the number of replacements done

replaceFirstback to summary
public boolean replaceFirst(boolean value, boolean replacement)

Returns true if the specified value was replaced successfully with the replacement

Parameters
value:boolean

the boolean to be replaced

replacement:boolean

the first value will be replaced by this replacement if found

Returns:boolean

if value was found and replaced

resizeback to summary
protected boolean[] resize(int newSize)
reverseback to summary
public void reverse()
setback to summary
public void set(int index, boolean value)
setSizeback to summary
public boolean[] setSize(int newSize)

Sets the array size, leaving any values beyond the current size undefined.

Returns:boolean[]

items

shrinkback to summary
public boolean[] shrink()

Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have been removed, or if it is known that more items will not be added.

Returns:boolean[]

items

shuffleback to summary
public void shuffle()
swapback to summary
public void swap(int first, int second)
toArrayback to summary
public boolean[] toArray()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

toStringback to summary
public String toString(String separator)
truncateback to summary
public void truncate(int newSize)

Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken.

withback to summary
public static BooleanArray with(boolean... array)
See Also
BooleanArray(boolean[])