jsat.utils
Class IntList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<java.lang.Integer>
-
- jsat.utils.IntList
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Iterable<java.lang.Integer>, java.util.Collection<java.lang.Integer>, java.util.List<java.lang.Integer>, java.util.RandomAccess
public class IntList extends java.util.AbstractList<java.lang.Integer> implements java.io.Serializable, java.util.RandomAccessProvides a modifiable implementation of a List using a int array. This provides considerable memory efficency improvements over using anArrayListto store integers. Null is not allowed into the list.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description IntList()Creates a new IntListIntList(java.util.Collection<java.lang.Integer> c)IntList(int capacity)Creates a new IntList with the given initial capacity
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanadd(int e)Operates exactly asadd(java.lang.Integer)booleanadd(java.lang.Integer e)voidadd(int index, int element)Operates exactly asadd(int, java.lang.Integer)voidadd(int index, java.lang.Integer element)booleanaddAll(java.util.Collection<? extends java.lang.Integer> c)voidclear()java.lang.Integerget(int index)intgetI(int index)Operates exactly asget(int)static IntListrange(int end)Returns a new IntList containing values in the range [0, end)static IntListrange(int start, int end)Returns a new IntList containing values in the given rangestatic IntListrange(int start, int end, int step)Returns a new IntList containing values in the given rangejava.lang.Integerremove(int index)intset(int index, int element)Operates exactly asset(int, java.lang.Integer)java.lang.Integerset(int index, java.lang.Integer element)intsize()voidsort()Efficiently sorts this list of integers usingArrays.sort(int[]).java.util.stream.IntStreamstreamInts()static java.util.List<java.lang.Integer>unmodifiableView(int[] array, int length)Creates and returns an unmodifiable view of the given int array that requires only a small object allocation.static IntListview(int[] array)Creates and returns a view of the given int array that requires only a small object allocation.static IntListview(int[] array, int length)Creates and returns a view of the given int 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
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
IntList
public IntList()
Creates a new IntList
-
IntList
public IntList(int capacity)
Creates a new IntList with the given initial capacity- Parameters:
capacity- the starting internal storage space size
-
IntList
public IntList(java.util.Collection<java.lang.Integer> c)
-
-
Method Detail
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<java.lang.Integer>- Specified by:
clearin interfacejava.util.List<java.lang.Integer>- Overrides:
clearin classjava.util.AbstractList<java.lang.Integer>
-
set
public int set(int index, int element)Operates exactly asset(int, java.lang.Integer)- Parameters:
index- the index to setelement- the value to set- Returns:
- the previous value at the index
-
set
public java.lang.Integer set(int index, java.lang.Integer element)- Specified by:
setin interfacejava.util.List<java.lang.Integer>- Overrides:
setin classjava.util.AbstractList<java.lang.Integer>
-
add
public void add(int index, int element)Operates exactly asadd(int, java.lang.Integer)- Parameters:
index- the index to add the value intoelement- the value to add
-
add
public void add(int index, java.lang.Integer element)- Specified by:
addin interfacejava.util.List<java.lang.Integer>- Overrides:
addin classjava.util.AbstractList<java.lang.Integer>
-
add
public boolean add(int e)
Operates exactly asadd(java.lang.Integer)- Parameters:
e- the value to add- Returns:
- true if it was added, false otherwise
-
add
public boolean add(java.lang.Integer e)
- Specified by:
addin interfacejava.util.Collection<java.lang.Integer>- Specified by:
addin interfacejava.util.List<java.lang.Integer>- Overrides:
addin classjava.util.AbstractList<java.lang.Integer>
-
getI
public int getI(int index)
Operates exactly asget(int)- Parameters:
index- the index of the value to get- Returns:
- the value at the index
-
get
public java.lang.Integer get(int index)
- Specified by:
getin interfacejava.util.List<java.lang.Integer>- Specified by:
getin classjava.util.AbstractList<java.lang.Integer>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<java.lang.Integer>- Specified by:
sizein interfacejava.util.List<java.lang.Integer>- Specified by:
sizein classjava.util.AbstractCollection<java.lang.Integer>
-
addAll
public boolean addAll(java.util.Collection<? extends java.lang.Integer> c)
- Specified by:
addAllin interfacejava.util.Collection<java.lang.Integer>- Specified by:
addAllin interfacejava.util.List<java.lang.Integer>- Overrides:
addAllin classjava.util.AbstractCollection<java.lang.Integer>
-
remove
public java.lang.Integer remove(int index)
- Specified by:
removein interfacejava.util.List<java.lang.Integer>- Overrides:
removein classjava.util.AbstractList<java.lang.Integer>
-
sort
public void sort()
Efficiently sorts this list of integers usingArrays.sort(int[]).
-
unmodifiableView
public static java.util.List<java.lang.Integer> unmodifiableView(int[] array, int length)Creates and returns an unmodifiable view of the given int 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 IntList view(int[] array, int length)
Creates and returns a view of the given int 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 an IntList objectlength- the initial length of the list- Returns:
- an IntList backed by the given array, unless modified to the point of requiring the allocation of a new array
-
view
public static IntList view(int[] array)
Creates and returns a view of the given int 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 an IntList object- Returns:
- an IntList backed by the given array, unless modified to the point of requiring the allocation of a new array
-
streamInts
public java.util.stream.IntStream streamInts()
- Returns:
- a sequential stream of integers with this as its source
-
range
public static IntList range(int start, int end, int step)
Returns a new IntList containing values in the given range- Parameters:
start- the starting value (inclusive)end- the ending value (exclusive)step- the step size- Returns:
- a new IntList populated by integer values as if having run through a for loop
-
range
public static IntList range(int start, int end)
Returns a new IntList containing values in the given range- Parameters:
start- the starting value (inclusive)end- the ending value (exclusive)- Returns:
- a new IntList populated by integer values as if having run through a for loop
-
range
public static IntList range(int end)
Returns a new IntList containing values in the range [0, end)- Parameters:
end- the ending value (exclusive)- Returns:
- a new IntList populated by integer values as if having run through a for loop
-
-
DataMelt 3.0 © DataMelt by jWork.ORG