libgdx API

com.badlogic.gdx.utils
Class CharArray

java.lang.Object
  extended by com.badlogic.gdx.utils.CharArray

public class CharArray
extends java.lang.Object

A resizable, ordered or unordered char 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
 char[] items
           
 boolean ordered
           
 int size
           
 
Constructor Summary
CharArray()
          Creates an ordered array with a capacity of 16.
CharArray(boolean ordered, char[] array)
          Creates a new array containing the elements in the specified array.
CharArray(boolean ordered, int capacity)
           
CharArray(char[] array)
          Creates a new ordered array containing the elements in the specified array.
CharArray(CharArray array)
          Creates a new array containing the elements in the specific array.
CharArray(int capacity)
          Creates an ordered array with the specified capacity.
 
Method Summary
 void add(char value)
           
 void addAll(char[] array)
           
 void addAll(char[] array, int offset, int length)
           
 void addAll(CharArray array)
           
 void addAll(CharArray array, int offset, int length)
           
 void clear()
           
 boolean contains(char value)
           
 char[] ensureCapacity(int additionalCapacity)
          Increases the size of the backing array to acommodate the specified number of additional items.
 char get(int index)
           
 int indexOf(char value)
           
 void insert(int index, char value)
           
 char peek()
          Returns the last item.
 char pop()
          Removes and returns the last item.
 char random()
          Returns a random item from the array, or zero if the array is empty.
 char removeIndex(int index)
          Removes and returns the item at the specified index.
 boolean removeValue(char value)
           
protected  char[] resize(int newSize)
           
 void reverse()
           
 void set(int index, char value)
           
 void shrink()
          Reduces the size of the backing array to the size of the actual items.
 void shuffle()
           
 void sort()
           
 char[] toArray()
           
 java.lang.String toString()
           
 java.lang.String toString(java.lang.String separator)
           
 void truncate(int newSize)
          Reduces the size of the array to the specified size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

items

public char[] items

size

public int size

ordered

public boolean ordered
Constructor Detail

CharArray

public CharArray()
Creates an ordered array with a capacity of 16.


CharArray

public CharArray(int capacity)
Creates an ordered array with the specified capacity.


CharArray

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

CharArray

public CharArray(CharArray 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.


CharArray

public CharArray(char[] 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.


CharArray

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

add

public void add(char value)

addAll

public void addAll(CharArray array)

addAll

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

addAll

public void addAll(char[] array)

addAll

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

get

public char get(int index)

set

public void set(int index,
                char value)

insert

public void insert(int index,
                   char value)

contains

public boolean contains(char value)

indexOf

public int indexOf(char value)

removeValue

public boolean removeValue(char value)

removeIndex

public char removeIndex(int index)
Removes and returns the item at the specified index.


pop

public char pop()
Removes and returns the last item.


peek

public char peek()
Returns the last item.


clear

public void clear()

shrink

public void 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.


ensureCapacity

public char[] ensureCapacity(int additionalCapacity)
Increases the size of the backing array to acommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes.

Returns:
items

resize

protected char[] resize(int newSize)

sort

public void sort()

reverse

public void reverse()

shuffle

public void shuffle()

truncate

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.


random

public char random()
Returns a random item from the array, or zero if the array is empty.


toArray

public char[] toArray()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String separator)

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)