jsat.utils
Class BooleanList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<java.lang.Boolean>
-
- jsat.utils.BooleanList
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Iterable<java.lang.Boolean>, java.util.Collection<java.lang.Boolean>, java.util.List<java.lang.Boolean>, java.util.RandomAccess
public class BooleanList extends java.util.AbstractList<java.lang.Boolean> implements java.io.Serializable, java.util.RandomAccessProvides a modifiable implementation of a List using a boolean array. This provides considerable memory efficency improvements over using anArrayListto store booleans.
Null is not allowed into the list.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description BooleanList()Creates a new empty BooleanListBooleanList(java.util.Collection<java.lang.Boolean> c)Creates a new BooleanList containing the values of the given collectionBooleanList(int capacity)Creates a new empty BooealList
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanadd(boolean e)Performs exactly the same asadd(java.lang.Boolean).booleanadd(java.lang.Boolean e)voidadd(int index, boolean element)Operates exactly asadd(int, java.lang.Boolean)voidadd(int index, java.lang.Boolean element)voidclear()java.lang.Booleanget(int index)booleangetB(int index)Operates exactly asget(int)boolean[]getBackingArray()Returns the reference to the array that backs this list.booleanpeek()This method treats the underlying list as a stack.booleanpop()This method treats the underlying list as a stack.booleanpush(boolean e)This method treats the underlying list as a stack.java.lang.Booleanremove(int index)booleanremoveB(int index)Operates exactly asremove(int)booleanset(int index, boolean element)Operates exactly asset(int, java.lang.Boolean)java.lang.Booleanset(int index, java.lang.Boolean element)intsize()static java.util.List<java.lang.Boolean>unmodifiableView(boolean[] array, int length)Creates an returns an unmodifiable view of the given boolean array that requires only a small object allocation.static BooleanListview(boolean[] array, int length)Creates and returns a view of the given boolean array that requires only a small object allocation.-
Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
BooleanList
public BooleanList()
Creates a new empty BooleanList
-
BooleanList
public BooleanList(int capacity)
Creates a new empty BooealList- Parameters:
capacity- the starting internal capacity of the list
-
BooleanList
public BooleanList(java.util.Collection<java.lang.Boolean> c)
Creates a new BooleanList containing the values of the given collection- Parameters:
c- the collection of values to fill this boolean list with
-
-
Method Detail
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<java.lang.Boolean>- Specified by:
clearin interfacejava.util.List<java.lang.Boolean>- Overrides:
clearin classjava.util.AbstractList<java.lang.Boolean>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<java.lang.Boolean>- Specified by:
sizein interfacejava.util.List<java.lang.Boolean>- Specified by:
sizein classjava.util.AbstractCollection<java.lang.Boolean>
-
add
public boolean add(boolean e)
Performs exactly the same asadd(java.lang.Boolean).- Parameters:
e- the value to add- Returns:
- true if it was added, false otherwise
-
push
public boolean push(boolean e)
This method treats the underlying list as a stack. Pushes an item onto the top of this "stack".- Parameters:
e- the item to push onto the stack- Returns:
- the value added to the stack
-
pop
public boolean pop()
This method treats the underlying list as a stack. Removes the item at the top of this "stack" and returns that item as the value.- Returns:
- the item at the top of this stack (the last item pushed onto it)
-
peek
public boolean peek()
This method treats the underlying list as a stack. Gets the item at the top of this "stack" and returns that item as the value, but leaves it on the stack.- Returns:
- the item at the top of this stack (the last item pushed onto it)
-
add
public boolean add(java.lang.Boolean e)
- Specified by:
addin interfacejava.util.Collection<java.lang.Boolean>- Specified by:
addin interfacejava.util.List<java.lang.Boolean>- Overrides:
addin classjava.util.AbstractList<java.lang.Boolean>
-
getB
public boolean getB(int index)
Operates exactly asget(int)- Parameters:
index- the index of the value to get- Returns:
- the value at the given index
-
get
public java.lang.Boolean get(int index)
- Specified by:
getin interfacejava.util.List<java.lang.Boolean>- Specified by:
getin classjava.util.AbstractList<java.lang.Boolean>
-
set
public boolean set(int index, boolean element)Operates exactly asset(int, java.lang.Boolean)- Parameters:
index- the index to setelement- the value to set- Returns:
- the previous value at said index
-
set
public java.lang.Boolean set(int index, java.lang.Boolean element)- Specified by:
setin interfacejava.util.List<java.lang.Boolean>- Overrides:
setin classjava.util.AbstractList<java.lang.Boolean>
-
add
public void add(int index, boolean element)Operates exactly asadd(int, java.lang.Boolean)- Parameters:
index- the index to add atelement- the value to add
-
add
public void add(int index, java.lang.Boolean element)- Specified by:
addin interfacejava.util.List<java.lang.Boolean>- Overrides:
addin classjava.util.AbstractList<java.lang.Boolean>
-
removeB
public boolean removeB(int index)
Operates exactly asremove(int)- Parameters:
index- the index to remove- Returns:
- the value removed
-
remove
public java.lang.Boolean remove(int index)
- Specified by:
removein interfacejava.util.List<java.lang.Boolean>- Overrides:
removein classjava.util.AbstractList<java.lang.Boolean>
-
getBackingArray
public boolean[] getBackingArray()
Returns the reference to the array that backs this list. Alterations to the array will be visible to the DoubelList and vise versa. The array returned may not the the same size as the value returned bysize()- Returns:
- the underlying array used by this BooleanList
-
unmodifiableView
public static java.util.List<java.lang.Boolean> unmodifiableView(boolean[] array, int length)Creates an returns an unmodifiable view of the given boolean array that requires only a small object allocation.- Parameters:
array- the array to wrap into an unmodifiable listlength- the number of values of the array to use, starting from zero- Returns:
- an unmodifiable list view of the array
-
view
public static BooleanList view(boolean[] array, int length)
Creates and returns a view of the given boolean array that requires only a small object allocation. Changes to the list will be reflected in the array up to a point. If the modification would require increasing the capacity of the array, a new array will be allocated - at which point operations will no longer be reflected in the original array.- Parameters:
array- the array to wrap by a BooleanList objectlength- the initial length of the list- Returns:
- a BoolaenList backed by the given array, unless modified to the point of requiring the allocation of a new array
-
-
DataMelt 3.0 © DataMelt by jWork.ORG