- All Implemented Interfaces:
Iterable<Byte>,Collection<Byte>,List<Byte>,SequencedCollection<Byte>,ByteList,ByteSequencedCollection
A
byte-valued list backed by a primitive array.- Author:
- Werner Randelshofer
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty instance with 0 initial capacity.ByteArrayList(int initialCapacity) Creates a new empty instance with the specified initial capacity.ByteArrayList(Collection<Byte> collection) Creates a new instance from the specified collection -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidaddAllAsByte(ByteArrayList that) Adds all items of the specified list to this list.<T extends Collection<Byte>>
TaddAllInto(T out) Adds all items of this collection to the specified collection.voidaddAsByte(byte newItem) Adds a new item to the end of the list.voidaddAsByte(int index, byte newItem) Inserts a new item at the specified index into this list.voidvoidReturns a stream for processing the items of this list.voidclear()Clears the list in O(1).booleanvoidcopyInto(byte[] a, int offset) Copies the contents of this list into the provided array.booleanget(int index) byte[]getArray()bytegetAsByte(int index) Gets the item at the specified index.getFirst()bytegetLast()byteinthashCode()intindexOfAsByte(byte item) intindexOfAsByte(byte item, int start) booleanisEmpty()Returns true if size==0.iterator()Returns an iterator for this list.intlastIndexOfAsByte(byte item) intlastIndexOfAsByte(byte item, int start) static ByteArrayListof(byte... items) Creates a new instance with the specified items.booleanbyteremoveAtAsByte(int index) Removes the item at the specified index from this list.booleanremoveIfAsByte(IntPredicate filter) Removes all the elements of this collection that satisfy the given predicate.byteRemoves the last itemreversed()bytesetAsByte(int index, byte newItem) Replaces the item at the specified index.voidsetSize(int newSize) Sets the size of this list.intsize()Returns the size of the list.voidsort()Sorts the items in ascending order.voidsort(@Nullable Comparator<? super Byte> c) Sorts this list according to the order induced by the specifiedComparator.Returns a spliterator for this list.byte[]Returns a new array containing all the elements in this collection.int[]Returns a new array containing all the elements in this collection.toString()voidTrims the capacity of the list its current size.Methods inherited from class java.util.AbstractList
add, addAll, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subListMethods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jhotdraw8.collection.primitive.ByteList
addFirstAsByte, addLastAsByte, indexOf, lastIndexOf, removeFirstAsByteMethods inherited from interface org.jhotdraw8.collection.primitive.ByteSequencedCollection
addLastAllAsByte, addLastAllAsByteMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
add, addAll, addAll, containsAll, listIterator, listIterator, remove, removeAll, replaceAll, retainAll, set, subList, toArray, toArray
-
Constructor Details
-
ByteArrayList
public ByteArrayList()Creates a new empty instance with 0 initial capacity. -
ByteArrayList
public ByteArrayList(int initialCapacity) Creates a new empty instance with the specified initial capacity.- Parameters:
initialCapacity- the initial capacity
-
ByteArrayList
Creates a new instance from the specified collection- Parameters:
collection- a collection of integers
-
-
Method Details
-
of
Creates a new instance with the specified items.- Parameters:
items- the items (the newly created instance references the provided array)- Returns:
- the new instance
-
addAsByte
public void addAsByte(byte newItem) Adds a new item to the end of the list. -
addAsByte
public void addAsByte(int index, byte newItem) Inserts a new item at the specified index into this list. -
addAllAsByte
Adds all items of the specified list to this list.- Parameters:
that- another list
-
addAllInto
Adds all items of this collection to the specified collection.- Type Parameters:
T- the type of the collection- Parameters:
out- the output collection- Returns:
- out
-
clear
public void clear()Clears the list in O(1).- Specified by:
clearin interfaceCollection<Byte>- Specified by:
clearin interfaceList<Byte>- Overrides:
clearin classAbstractList<Byte>
-
copyInto
public void copyInto(byte[] a, int offset) Copies the contents of this list into the provided array.- Parameters:
a- an arrayoffset- the offset into the array
-
equals
- Specified by:
equalsin interfaceCollection<Byte>- Specified by:
equalsin interfaceList<Byte>- Overrides:
equalsin classAbstractList<Byte>
-
getAsByte
public byte getAsByte(int index) Gets the item at the specified index. -
get
-
getLastAsByte
public byte getLastAsByte()- Specified by:
getLastAsBytein interfaceByteSequencedCollection
-
getFirstAsByte
public byte getFirstAsByte()- Specified by:
getFirstAsBytein interfaceByteSequencedCollection
-
setSize
public void setSize(int newSize) Sets the size of this list. If the new size is greater than the current size, new0items are added to the end of the list. If the new size is less than the current size, all items at indices greater or equalnewSizeare discarded.- Parameters:
newSize- the new size
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<Byte>- Specified by:
hashCodein interfaceList<Byte>- Overrides:
hashCodein classAbstractList<Byte>
-
indexOfAsByte
public int indexOfAsByte(byte item) - Specified by:
indexOfAsBytein interfaceByteList- See Also:
-
indexOfAsByte
public int indexOfAsByte(byte item, int start) -
lastIndexOfAsByte
public int lastIndexOfAsByte(byte item) - Specified by:
lastIndexOfAsBytein interfaceByteList- See Also:
-
lastIndexOfAsByte
public int lastIndexOfAsByte(byte item, int start) -
isEmpty
public boolean isEmpty()Returns true if size==0. -
contains
- Specified by:
containsin interfaceCollection<Byte>- Specified by:
containsin interfaceList<Byte>- Overrides:
containsin classAbstractCollection<Byte>
-
removeAtAsByte
public byte removeAtAsByte(int index) Removes the item at the specified index from this list.- Specified by:
removeAtAsBytein interfaceByteList- Parameters:
index- an index- Returns:
- the removed item
-
removeLastAsByte
public byte removeLastAsByte()Removes the last item- Specified by:
removeLastAsBytein interfaceByteSequencedCollection- Returns:
- the removed item
- Throws:
NoSuchElementException- if the list is empty
-
setAsByte
public byte setAsByte(int index, byte newItem) Replaces the item at the specified index.- Parameters:
index- an indexnewItem- the new item- Returns:
- the old item
-
size
public int size()Returns the size of the list.- Specified by:
sizein interfaceCollection<Byte>- Specified by:
sizein interfaceList<Byte>- Specified by:
sizein classAbstractCollection<Byte>- Returns:
- the size
-
trimToSize
public void trimToSize()Trims the capacity of the list its current size. -
iterator
Returns an iterator for this list. -
spliterator
Returns a spliterator for this list.- Specified by:
spliteratorin interfaceCollection<Byte>- Specified by:
spliteratorin interfaceIterable<Byte>- Specified by:
spliteratorin interfaceList<Byte>- Returns:
- a spliterator over the elements of this list
-
byteStream
Returns a stream for processing the items of this list.- Returns:
- a stream
-
toByteArray
public byte[] toByteArray()Returns a new array containing all the elements in this collection.- Returns:
- array
-
toIntArray
public int[] toIntArray()Returns a new array containing all the elements in this collection.- Returns:
- array
-
add
-
remove
- Specified by:
removein interfaceCollection<Byte>- Specified by:
removein interfaceList<Byte>- Overrides:
removein classAbstractCollection<Byte>
-
toString
- Overrides:
toStringin classAbstractCollection<Byte>
-
sort
public void sort()Sorts the items in ascending order. -
removeIfAsByte
Removes all the elements of this collection that satisfy the given predicate.- Parameters:
filter- a predicate which returnstruefor elements to be removed- Returns:
trueif any elements were removed
-
sort
Sorts this list according to the order induced by the specifiedComparator. The sort is stable: it does not reorder equal elements.- Specified by:
sortin interfaceList<Byte>- Parameters:
c- theComparatorused to compare list elements. Anullvalue indicates that the elements' natural ordering should be used.
-
reversed
-
getArray
public byte[] getArray() -
addFirst
- Specified by:
addFirstin interfaceByteList- Specified by:
addFirstin interfaceByteSequencedCollection- Specified by:
addFirstin interfaceList<Byte>- Specified by:
addFirstin interfaceSequencedCollection<Byte>
-
addLast
- Specified by:
addLastin interfaceByteList- Specified by:
addLastin interfaceByteSequencedCollection- Specified by:
addLastin interfaceList<Byte>- Specified by:
addLastin interfaceSequencedCollection<Byte>
-
getFirst
- Specified by:
getFirstin interfaceByteList- Specified by:
getFirstin interfaceByteSequencedCollection- Specified by:
getFirstin interfaceList<Byte>- Specified by:
getFirstin interfaceSequencedCollection<Byte>
-
getLast
- Specified by:
getLastin interfaceByteList- Specified by:
getLastin interfaceByteSequencedCollection- Specified by:
getLastin interfaceList<Byte>- Specified by:
getLastin interfaceSequencedCollection<Byte>
-
removeFirst
- Specified by:
removeFirstin interfaceByteList- Specified by:
removeFirstin interfaceByteSequencedCollection- Specified by:
removeFirstin interfaceList<Byte>- Specified by:
removeFirstin interfaceSequencedCollection<Byte>
-
removeLast
- Specified by:
removeLastin interfaceByteList- Specified by:
removeLastin interfaceByteSequencedCollection- Specified by:
removeLastin interfaceList<Byte>- Specified by:
removeLastin interfaceSequencedCollection<Byte>
-