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

public Class ShortArray

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

A resizable, ordered or unordered short 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 short[]
public boolean
public int

Constructor Summary

AccessConstructor and Description
public
ShortArray()

Creates an ordered array with a capacity of 16.

public
ShortArray(int capacity)

Creates an ordered array with the specified capacity.

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

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

public
ShortArray(short[] array)

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

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

Casts the specified value to short and adds it.

public void
add(short value)

public void
add(short value1, short value2)

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

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

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

public void
addAll(short... array)

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

public void
public boolean
contains(short value)

public short[]

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.

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

public short
first()

Returns the first item.

public short
get(int index)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public void
incr(int index, short value)

public void
incr(short value)

public int
indexOf(short value)

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

public void
mul(int index, short value)

public void
mul(short value)

public boolean
notEmpty()

Returns true if the array has one or more items.

public short
peek()

Returns the last item.

public short
pop()

Removes and returns the last item.

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

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

public short
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(short value)

public int

Returns:

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

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

public short[]

Returns:

items
setSize
(int newSize)

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

public short[]

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 short[]
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 ShortArray
with(short... array)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

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

Constructor Detail

ShortArrayback to summary
public ShortArray()

Creates an ordered array with a capacity of 16.

ShortArrayback to summary
public ShortArray(int capacity)

Creates an ordered array with the specified capacity.

ShortArrayback to summary
public ShortArray(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.

ShortArrayback to summary
public ShortArray(ShortArray 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.

ShortArrayback to summary
public ShortArray(short[] 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.

ShortArrayback to summary
public ShortArray(boolean ordered, short[] 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(int value)

Casts the specified value to short and adds it.

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

items

equalsback to summary
public boolean equals(Object object)

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.

firstback to summary
public short first()

Returns the first item.

getback to summary
public short 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, short value)
incrback to summary
public void incr(short value)
indexOfback to summary
public int indexOf(short value)
insertback to summary
public void insert(int index, short 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(short value)
mulback to summary
public void mul(int index, short value)
mulback to summary
public void mul(short value)
notEmptyback to summary
public boolean notEmpty()

Returns true if the array has one or more items.

peekback to summary
public short peek()

Returns the last item.

popback to summary
public short pop()

Removes and returns the last item.

randomback to summary
public short random()

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

removeAllback to summary
public boolean removeAll(ShortArray 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 short 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(short value)
replaceAllback to summary
public int replaceAll(short value, short replacement)

Returns the number of replacements done.

Parameters
value:short

the short to be replaced

replacement:short

all occurrences of value will be replaced by this replacement

Returns:int

the number of replacements done

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

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

Parameters
value:short

the short to be replaced

replacement:short

the first value will be replaced by this replacement if found

Returns:boolean

if value was found and replaced

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

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

Returns:short[]

items

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

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 short[] 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 ShortArray with(short... array)
See Also
ShortArray(short[])