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

public Class FloatArray

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

A resizable, ordered or unordered float array. Avoids the boxing that occurs with ArrayList. 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 float[]
public boolean
public int

Constructor Summary

AccessConstructor and Description
public
FloatArray()

Creates an ordered array with a capacity of 16.

public
FloatArray(int capacity)

Creates an ordered array with the specified capacity.

public
FloatArray(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
FloatArray(FloatArray array)

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

public
FloatArray(float[] array)

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

public
FloatArray(boolean
If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
ordered
,
float[] 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(float value)

public void
add(float value1, float value2)

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

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

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

public void
addAll(float... array)

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

public void
public boolean
contains(float value)

public float[]

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
equals(Object object, float epsilon)

Returns false if either array is unordered.

public float
first()

Returns the first item.

public float
get(int index)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public void
incr(int index, float value)

public void
incr(float value)

public int
indexOf(float value)

public void
insert(int index, float 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 int
lastIndexOf(float value)

public void
mul(int index, float value)

public void
mul(float value)

public boolean
notEmpty()

Returns true if the array has one or more items.

public float
peek()

Returns the last item.

public float
pop()

Removes and returns the last item.

public float
random()

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

public boolean

Returns:

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

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

public float
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 boolean
removeValue(float value)

public int

Returns:

the number of replacements done
replaceAll
(float
the float to be replaced
value
,
float
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
(float
the float to be replaced
value
,
float
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 float[]
resize(int newSize)

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

public float[]

Returns:

items
setSize
(int newSize)

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

public float[]

Returns:

items
shrink
()

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

public void
public void
sort()

public void
swap(int first, int second)

public float[]
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 FloatArray
with(float... array)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

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

Constructor Detail

FloatArrayback to summary
public FloatArray()

Creates an ordered array with a capacity of 16.

FloatArrayback to summary
public FloatArray(int capacity)

Creates an ordered array with the specified capacity.

FloatArrayback to summary
public FloatArray(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.

FloatArrayback to summary
public FloatArray(FloatArray 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.

FloatArrayback to summary
public FloatArray(float[] 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.

FloatArrayback to summary
public FloatArray(boolean ordered, float[] 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(float value)
addback to summary
public void add(float value1, float value2)
addback to summary
public void add(float value1, float value2, float value3)
addback to summary
public void add(float value1, float value2, float value3, float value4)
addAllback to summary
public void addAll(FloatArray array)
addAllback to summary
public void addAll(FloatArray array, int offset, int length)
addAllback to summary
public void addAll(float... array)
addAllback to summary
public void addAll(float[] array, int offset, int length)
clearback to summary
public void clear()
containsback to summary
public boolean contains(float value)
ensureCapacityback to summary
public float[] 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:float[]

items

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Returns false if either array is unordered.

equalsback to summary
public boolean equals(Object object, float epsilon)

Returns false if either array is unordered.

firstback to summary
public float first()

Returns the first item.

getback to summary
public float 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.
incrback to summary
public void incr(int index, float value)
incrback to summary
public void incr(float value)
indexOfback to summary
public int indexOf(float value)
insertback to summary
public void insert(int index, float 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.

lastIndexOfback to summary
public int lastIndexOf(float value)
mulback to summary
public void mul(int index, float value)
mulback to summary
public void mul(float value)
notEmptyback to summary
public boolean notEmpty()

Returns true if the array has one or more items.

peekback to summary
public float peek()

Returns the last item.

popback to summary
public float pop()

Removes and returns the last item.

randomback to summary
public float random()

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

removeAllback to summary
public boolean removeAll(FloatArray 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 float 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.

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

Returns the number of replacements done.

Parameters
value:float

the float to be replaced

replacement:float

all occurrences of value will be replaced by this replacement

Returns:int

the number of replacements done

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

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

Parameters
value:float

the float to be replaced

replacement:float

the first value will be replaced by this replacement if found

Returns:boolean

if value was found and replaced

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

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

Returns:float[]

items

shrinkback to summary
public float[] 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:float[]

items

shuffleback to summary
public void shuffle()
sortback to summary
public void sort()
swapback to summary
public void swap(int first, int second)
toArrayback to summary
public float[] 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 FloatArray with(float... array)
See Also
FloatArray(float[])