Class ByteList
- All Implemented Interfaces:
 java.lang.Iterable<byte[]>,java.util.Collection<byte[]>,java.util.List<byte[]>,java.util.RandomAccess
public class ByteList
extends java.util.AbstractList<byte[]>
implements java.util.RandomAccess
List<byte[]>. Some caveats about
 breaking some corners of the List contract for sake of usability.- See Also:
 equals(Object),contains(Object),indexOf(Object),lastIndexOf(Object)
- 
Field Summary
Fields Modifier and Type Field Description protected java.util.List<byte[]>sourceFields inherited from class java.util.AbstractList
modCount - 
Constructor Summary
Constructors Constructor Description ByteList(java.util.List<byte[]> source)Creates an instance from the given source instance. - 
Method Summary
Modifier and Type Method Description booleancontains(java.lang.Object o)booleanequals(java.lang.Object o)Equality here is implemented using Arrays.equals(byte[], byte[]).byte[]get(int index)inthashCode()intindexOf(java.lang.Object o)intlastIndexOf(java.lang.Object o)static ByteListnewInstance(byte[][] arrays)Creates a new instance.static ByteListnewInstance(byte[][] arrays, boolean copy)Creates a new instance.intsize()Methods inherited from class java.util.AbstractList
add, add, addAll, clear, iterator, listIterator, listIterator, remove, removeRange, set, subListMethods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.lang.Iterable
forEachMethods inherited from interface java.util.List
addAll, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray 
- 
Field Details
- 
source
protected final java.util.List<byte[]> source 
 - 
 - 
Constructor Details
- 
ByteList
public ByteList(java.util.List<byte[]> source)Creates an instance from the given source instance. Modifications in the source are visible in this view. 
 - 
 - 
Method Details
- 
newInstance
Creates a new instance. Defensively copies.- See Also:
 newInstance(byte[][], boolean)
 - 
newInstance
Creates a new instance.- Parameters:
 arrays- non-null sourcecopy- if true then the array is defensively copied; if false then modifications in the sub arrays (byte[]) are visible in the new instance- Returns:
 - a List view of arrays.
 
 - 
get
public byte[] get(int index)- Specified by:
 getin interfacejava.util.List<byte[]>- Specified by:
 getin classjava.util.AbstractList<byte[]>- Returns:
 - a copy of the item at the specified index
 
 - 
size
public int size()- Specified by:
 sizein interfacejava.util.Collection<byte[]>- Specified by:
 sizein interfacejava.util.List<byte[]>- Specified by:
 sizein classjava.util.AbstractCollection<byte[]>
 - 
contains
public boolean contains(java.lang.Object o)Note
This implementation uses Arrays.equals(byte[], byte[]) in lieu of Object.equals(o), so in this sense, it breaks the above formal contract. Strictly, the contract for List.equals(Object) (and List.hashCode()) is also violated.
- Specified by:
 containsin interfacejava.util.Collection<byte[]>- Specified by:
 containsin interfacejava.util.List<byte[]>- Overrides:
 containsin classjava.util.AbstractCollection<byte[]>
 - 
indexOf
public int indexOf(java.lang.Object o)Note
This implementation uses Arrays.equals(byte[], byte[]) in lieu of Object.equals(o), so in this sense, it breaks the above formal contract. Strictly, the contract for List.equals(Object) (and List.hashCode()) is also violated.
- Specified by:
 indexOfin interfacejava.util.List<byte[]>- Overrides:
 indexOfin classjava.util.AbstractList<byte[]>
 - 
lastIndexOf
public int lastIndexOf(java.lang.Object o)Note
This implementation uses Arrays.equals(byte[], byte[]) in lieu of Object.equals(o), so in this sense, it breaks the above formal contract. Strictly, the contract for List.equals(Object) (and List.hashCode()) is also violated.
- Specified by:
 lastIndexOfin interfacejava.util.List<byte[]>- Overrides:
 lastIndexOfin classjava.util.AbstractList<byte[]>
 - 
equals
public final boolean equals(java.lang.Object o)Equality here is implemented using Arrays.equals(byte[], byte[]). An instance of this class may only equal another instance of itself.Programmer's Note
Technically, per the List.equals(Object) contract, this List should not equal any other List instance but itself. This is because Java array objects implement equality by reference (or rather, don't override Object.equals(Object)), and since this class returns a new byte array on each read, its elements equal no other.
Generally, if no other class of object thinks it's equal to instances of your class, your class is free to redefine equality (the reflexitivity requirement). You usually only have one shot at it; it's a rare case where Object.equals(Object) can be overridden twice.
- Specified by:
 equalsin interfacejava.util.Collection<byte[]>- Specified by:
 equalsin interfacejava.util.List<byte[]>- Overrides:
 equalsin classjava.util.AbstractList<byte[]>- See Also:
 hashCode()
 - 
hashCode
public final int hashCode()- Specified by:
 hashCodein interfacejava.util.Collection<byte[]>- Specified by:
 hashCodein interfacejava.util.List<byte[]>- Overrides:
 hashCodein classjava.util.AbstractList<byte[]>- Returns:
 - a hash code consistent with equals(Object)
 
 
 -