Class ShortObjGapList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- org.magicwerk.brownies.collections.IList<java.lang.Short>
-
- org.magicwerk.brownies.collections.primitive.ShortObjGapList
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<java.lang.Short>
,java.util.Collection<java.lang.Short>
,java.util.List<java.lang.Short>
,java.util.RandomAccess
,ICollection<java.lang.Short>
,IListable<java.lang.Short>
- Direct Known Subclasses:
ShortObjGapList.ImmutableShortObjGapList
public class ShortObjGapList extends IList<java.lang.Short>
ShortObjGapList implements the List interface and uses an instance of ShortGapList for storage. It therefore allows to use the advantages of primitive collections like saved memory and improved execution speed when standard list collections are expected.Note that this implementation is not synchronized.
- Version:
- $Id: ShortObjGapList.java 2200 2014-03-21 10:46:29Z origo $
- See Also:
GapList
,ShortGapList
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ShortObjGapList.ImmutableShortObjGapList
An immutable version of a GapList.-
Nested classes/interfaces inherited from class org.magicwerk.brownies.collections.IList
IList.IListableFromArray<E>, IList.IListableFromCollection<E>, IList.IListableFromList<E>, IList.IListableFromMult<E>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) ShortGapList
list
-
Constructor Summary
Constructors Constructor Description ShortObjGapList()
ShortObjGapList(int capacity)
ShortObjGapList(java.util.Collection<? extends java.lang.Short> elems)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addAll(int index, java.util.Collection<? extends java.lang.Short> coll)
Inserts all of the elements in the specified collection into this list, starting at the specified position.boolean
addAll(int index, IList<? extends java.lang.Short> list2)
Inserts all of the elements in the specified list into this list, starting at the specified position.boolean
addAll(java.util.Collection<? extends java.lang.Short> coll)
Adds all of the elements in the specified collection into this list.boolean
addAll(IList<? extends java.lang.Short> list2)
Adds all of the elements in the specified list into this list.boolean
addArray(int index, java.lang.Short... elems)
Inserts the specified elements into this list, starting at the specified position.boolean
addArray(java.lang.Short... elems)
Adds all specified elements into this list.<K> int
binarySearch(int index, int len, K key, java.util.Comparator<? super K> comparator)
Searches the specified range for an object using the binary search algorithm.int
capacity()
Returns capacity of this GapList.ShortObjGapList
clone()
Returns a shallow copy of this list.boolean
contains(java.lang.Object elem)
boolean
containsAll(java.util.Collection<?> coll)
boolean
containsAny(java.util.Collection<?> coll)
Returns true if any of the elements of the specified collection is contained in the list.ShortObjGapList
copy()
Returns a shallow copy of this list.static ShortObjGapList
create()
static ShortObjGapList
create(java.lang.Short... elems)
static ShortObjGapList
create(java.util.Collection<? extends java.lang.Short> elems)
protected boolean
doAdd(int index, java.lang.Short elem)
Helper method for adding an element to the list.protected void
doAssign(IList<java.lang.Short> that)
Assign this list the content of the that list.protected void
doClone(IList<java.lang.Short> that)
Initialize this object after the bitwise copy has been made by Object.clone().IList<java.lang.Short>
doCreate(int capacity)
Create list with specified capacity.protected void
doEnsureCapacity(int minCapacity)
Increases the capacity of this list instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.protected java.lang.Short
doGet(int index)
Helper method for getting an element from the list.protected void
doGetAll(java.lang.Object[] elems, int index, int len)
Helper method to fill the specified elements in an array.protected java.lang.Short
doRemove(int index)
Helper method to remove an element.protected void
doRemoveAll(int index, int len)
Remove specified range of elements from list.protected java.lang.Short
doReSet(int index, java.lang.Short elem)
Sets an element at specified position.protected java.lang.Short
doSet(int index, java.lang.Short elem)
Helper method for setting an element in the list.boolean
equals(java.lang.Object obj)
java.lang.Short
get(int index)
Return element at specified positionGapList<java.lang.Short>
getAll(int index, int len)
Returns specified range of elements from list.java.lang.Short
getDefaultElem()
int
hashCode()
ShortObjGapList
immutableList()
Returns an immutable copy of this list.int
indexOf(java.lang.Object elem)
void
init()
void
init(java.lang.Short... elems)
void
init(java.util.Collection<? extends java.lang.Short> elems)
boolean
isEmpty()
boolean
isReadOnly()
Returns true if this list is either unmodifiable or immutable, false otherwise.int
lastIndexOf(java.lang.Object elem)
void
move(int srcIndex, int dstIndex, int len)
Move specified elements.boolean
remove(java.lang.Object elem)
boolean
removeAll(java.util.Collection<?> coll)
boolean
removeAll(IList<?> coll)
boolean
removeFirstOccurrence(java.lang.Object elem)
SeeDeque.removeFirstOccurrence(java.lang.Object)
boolean
removeLastOccurrence(java.lang.Object elem)
SeeDeque.removeLastOccurrence(java.lang.Object)
boolean
retainAll(java.util.Collection<?> coll)
boolean
retainAll(IList<?> coll)
void
setAll(int index, java.util.Collection<? extends java.lang.Short> coll)
Sets the specified elements.void
setAll(int index, IList<? extends java.lang.Short> list2)
Sets the specified elements.void
setArray(int index, java.lang.Short... elems)
Sets the specified elements.int
size()
Return size of listvoid
sort(int index, int len, java.util.Comparator comparator)
Sort specified elements in the list using the specified comparator.java.lang.Object[]
toArray(int index, int len)
Returns an array containing the specified elements in this list.<T> T[]
toArray(java.lang.Class<T> clazz, int index, int len)
Returns an array containing the specified elements in this list.<T> T[]
toArray(T[] array, int index, int len)
Returns an array containing the specified elements in this list.(package private) static short[]
toPrimitive(java.lang.Short[] elems)
(package private) static short[]
toPrimitive(java.util.Collection<? extends java.lang.Short> list)
(package private) static short[]
toPrimitive(GapList<? extends java.lang.Short> list2)
java.lang.String
toString()
(package private) static java.lang.Short[]
toWrapper(short[] elems)
void
trimToSize()
An application can use this operation to minimize the storage of an instance.ShortObjGapList
unmodifiableList()
Returns an unmodifiable view of this list.-
Methods inherited from class org.magicwerk.brownies.collections.IList
add, add, addArray, addArray, addFirst, addIfAbsent, addLast, addMult, addMult, asDeque, asIListable, binarySearch, checkIndex, checkIndexAdd, checkLength, checkLengths, checkNonNull, checkRange, clear, containsIf, copy, count, countIf, crop, descendingIterator, doAddAll, doClear, doCreateArray, doIndexOf, doIndexOfIf, doInitAll, doLastIndexOf, doLastIndexOfIf, doModify, doPutAll, doReplace, doRotate, drag, element, ensureCapacity, extract, extractIf, fill, filter, filterMap, flatMap, getAll, getDistinct, getFirst, getFirstOrNull, getIf, getLast, getLastOrNull, getSingle, getSingleOrNull, indexOf, indexOfIf, indexOfIf, initAll, initAll, initArray, initMult, iterator, lastIndexOf, lastIndexOfIf, lastIndexOfIf, listIterator, listIterator, map, mapFilter, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, put, putAll, putAll, putArray, putMult, remove, remove, remove, removeAll, removeFirst, removeIf, removeLast, replace, replaceAll, replaceAll, replaceArray, replaceMult, resize, retain, retainIf, reverse, reverse, rotate, rotate, set, setArray, setMult, sort, swap, toArray, toArray, toArray, transferCopy, transferMove, transferRemove, transferSwap, transform, transformedList
-
-
-
-
Field Detail
-
list
ShortGapList list
-
-
Method Detail
-
toWrapper
static java.lang.Short[] toWrapper(short[] elems)
-
toPrimitive
static short[] toPrimitive(java.lang.Short[] elems)
-
toPrimitive
static short[] toPrimitive(GapList<? extends java.lang.Short> list2)
-
toPrimitive
static short[] toPrimitive(java.util.Collection<? extends java.lang.Short> list)
-
create
public static ShortObjGapList create()
-
create
public static ShortObjGapList create(java.lang.Short... elems)
-
create
public static ShortObjGapList create(java.util.Collection<? extends java.lang.Short> elems)
-
init
public void init()
-
init
public void init(java.lang.Short... elems)
-
init
public void init(java.util.Collection<? extends java.lang.Short> elems)
-
doClone
protected void doClone(IList<java.lang.Short> that)
Description copied from class:IList
Initialize this object after the bitwise copy has been made by Object.clone().
-
doAssign
protected void doAssign(IList<java.lang.Short> that)
Description copied from class:IList
Assign this list the content of the that list. This is done by bitwise copying so the that list should not be used afterwards.
-
isReadOnly
public boolean isReadOnly()
Description copied from class:IList
Returns true if this list is either unmodifiable or immutable, false otherwise.- Specified by:
isReadOnly
in classIList<java.lang.Short>
-
copy
public ShortObjGapList copy()
Description copied from class:IList
Returns a shallow copy of this list. The new list will contain the same elements as the source list, i.e. the elements themselves are not copied. The capacity of the list will be set to the number of elements, i.e. size and capacity are equal. This returned list will be modifiable, i.e. a read-only list will be copied and be modifiable again.- Specified by:
copy
in interfaceICollection<java.lang.Short>
- Specified by:
copy
in classIList<java.lang.Short>
- Returns:
- a modifiable copy of this list
-
clone
public ShortObjGapList clone()
Description copied from class:IList
Returns a shallow copy of this list. The new list will contain the same elements as the source list, i.e. the elements themselves are not copied. The capacity of the list will be set to the number of elements, i.e. size and capacity are equal. If the list is read-only, the same list is returned without change. UseIList.copy()
to .
-
getDefaultElem
public java.lang.Short getDefaultElem()
- Specified by:
getDefaultElem
in classIList<java.lang.Short>
-
doCreate
public IList<java.lang.Short> doCreate(int capacity)
Description copied from class:IList
Create list with specified capacity.
-
size
public int size()
Description copied from interface:IListable
Return size of list
-
capacity
public int capacity()
Returns capacity of this GapList. Note that two GapLists are considered equal even if they have a distinct capacity. Also the capacity can be changed by operations like clone() etc.
-
get
public java.lang.Short get(int index)
Description copied from interface:IListable
Return element at specified position
-
doGet
protected java.lang.Short doGet(int index)
Description copied from class:IList
Helper method for getting an element from the list. This is the only method which really gets an element. Override if you need to validity checks before getting.
-
doGetAll
protected void doGetAll(java.lang.Object[] elems, int index, int len)
Description copied from class:IList
Helper method to fill the specified elements in an array.
-
doAdd
protected boolean doAdd(int index, java.lang.Short elem)
Description copied from class:IList
Helper method for adding an element to the list. This is the only method which really adds an element. Override if you need to validity checks before adding.
-
doSet
protected java.lang.Short doSet(int index, java.lang.Short elem)
Description copied from class:IList
Helper method for setting an element in the list. This is the only method which really sets an element. Override if you need to validity checks before setting.
-
doRemove
protected java.lang.Short doRemove(int index)
Description copied from class:IList
Helper method to remove an element. This is the only method which really removes an element. Override if you need to validity checks before removing.
-
doRemoveAll
protected void doRemoveAll(int index, int len)
Description copied from class:IList
Remove specified range of elements from list.- Overrides:
doRemoveAll
in classIList<java.lang.Short>
- Parameters:
index
- index of first element to removelen
- number of elements to remove
-
doReSet
protected java.lang.Short doReSet(int index, java.lang.Short elem)
Description copied from class:IList
Sets an element at specified position. This method is used internally if existing elements will be moved etc. Override if you need to validity checks.
-
move
public void move(int srcIndex, int dstIndex, int len)
Description copied from class:IList
Move specified elements. Source and destination ranges may overlap. The elements which are moved away are set to null, so the size of the list does not change.
-
doEnsureCapacity
protected void doEnsureCapacity(int minCapacity)
Description copied from class:IList
Increases the capacity of this list instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.- Specified by:
doEnsureCapacity
in classIList<java.lang.Short>
- Parameters:
minCapacity
- the desired minimum capacity
-
trimToSize
public void trimToSize()
Description copied from class:IList
An application can use this operation to minimize the storage of an instance.- Specified by:
trimToSize
in classIList<java.lang.Short>
-
equals
public boolean equals(java.lang.Object obj)
-
hashCode
public int hashCode()
-
isEmpty
public boolean isEmpty()
-
indexOf
public int indexOf(java.lang.Object elem)
-
lastIndexOf
public int lastIndexOf(java.lang.Object elem)
- Specified by:
lastIndexOf
in interfacejava.util.List<java.lang.Short>
- Overrides:
lastIndexOf
in classIList<java.lang.Short>
-
remove
public boolean remove(java.lang.Object elem)
-
contains
public boolean contains(java.lang.Object elem)
-
containsAny
public boolean containsAny(java.util.Collection<?> coll)
Description copied from class:IList
Returns true if any of the elements of the specified collection is contained in the list.- Overrides:
containsAny
in classIList<java.lang.Short>
- Parameters:
coll
- collection with elements to be contained- Returns:
- true if any element is contained, false otherwise
-
containsAll
public boolean containsAll(java.util.Collection<?> coll)
- Specified by:
containsAll
in interfacejava.util.Collection<java.lang.Short>
- Specified by:
containsAll
in interfacejava.util.List<java.lang.Short>
- Overrides:
containsAll
in classIList<java.lang.Short>
-
removeAll
public boolean removeAll(java.util.Collection<?> coll)
-
removeAll
public boolean removeAll(IList<?> coll)
- Overrides:
removeAll
in classIList<java.lang.Short>
- See Also:
IList.removeAll(Collection)
-
retainAll
public boolean retainAll(java.util.Collection<?> coll)
-
retainAll
public boolean retainAll(IList<?> coll)
- Overrides:
retainAll
in classIList<java.lang.Short>
- See Also:
IList.retainAll(Collection)
-
toArray
public java.lang.Object[] toArray(int index, int len)
Returns an array containing the specified elements in this list.
-
toArray
public <T> T[] toArray(T[] array, int index, int len)
Returns an array containing the specified elements in this list.- Overrides:
toArray
in classIList<java.lang.Short>
- Parameters:
array
- the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purposeindex
- index of first element to copylen
- number of elements to copy- Returns:
- array containing the specified elements
- See Also:
List#toArray(Object[])
-
toArray
public <T> T[] toArray(java.lang.Class<T> clazz, int index, int len)
Returns an array containing the specified elements in this list.
-
addAll
public boolean addAll(java.util.Collection<? extends java.lang.Short> coll)
Description copied from class:IList
Adds all of the elements in the specified collection into this list. The new elements will appear in the list in the order that they are returned by the specified collection's iterator.- Specified by:
addAll
in interfacejava.util.Collection<java.lang.Short>
- Specified by:
addAll
in interfacejava.util.List<java.lang.Short>
- Overrides:
addAll
in classIList<java.lang.Short>
- Parameters:
coll
- collection containing elements to be added to this list- Returns:
- true if this list changed as a result of the call
-
addAll
public boolean addAll(int index, java.util.Collection<? extends java.lang.Short> coll)
Description copied from class:IList
Inserts all of the elements in the specified collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified collection's iterator.- Specified by:
addAll
in interfacejava.util.List<java.lang.Short>
- Overrides:
addAll
in classIList<java.lang.Short>
- Parameters:
index
- index at which to insert the first element from the specified collectioncoll
- collection containing elements to be inserted into this list- Returns:
- true if this list changed as a result of the call
-
addArray
public boolean addArray(java.lang.Short... elems)
Description copied from class:IList
Adds all specified elements into this list.
-
addArray
public boolean addArray(int index, java.lang.Short... elems)
Description copied from class:IList
Inserts the specified elements into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices).
-
addAll
public boolean addAll(IList<? extends java.lang.Short> list2)
Description copied from class:IList
Adds all of the elements in the specified list into this list.
-
addAll
public boolean addAll(int index, IList<? extends java.lang.Short> list2)
Description copied from class:IList
Inserts all of the elements in the specified list into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices).
-
removeFirstOccurrence
public boolean removeFirstOccurrence(java.lang.Object elem)
Description copied from class:IList
SeeDeque.removeFirstOccurrence(java.lang.Object)
- Overrides:
removeFirstOccurrence
in classIList<java.lang.Short>
-
removeLastOccurrence
public boolean removeLastOccurrence(java.lang.Object elem)
Description copied from class:IList
SeeDeque.removeLastOccurrence(java.lang.Object)
- Overrides:
removeLastOccurrence
in classIList<java.lang.Short>
-
getAll
public GapList<java.lang.Short> getAll(int index, int len)
Description copied from class:IList
Returns specified range of elements from list.
-
setAll
public void setAll(int index, IList<? extends java.lang.Short> list2)
Description copied from class:IList
Sets the specified elements.
-
setAll
public void setAll(int index, java.util.Collection<? extends java.lang.Short> coll)
Description copied from class:IList
Sets the specified elements.
-
setArray
public void setArray(int index, java.lang.Short... elems)
Description copied from class:IList
Sets the specified elements.
-
sort
public void sort(int index, int len, java.util.Comparator comparator)
Description copied from class:IList
Sort specified elements in the list using the specified comparator.
-
binarySearch
public <K> int binarySearch(int index, int len, K key, java.util.Comparator<? super K> comparator)
Description copied from class:IList
Searches the specified range for an object using the binary search algorithm.Note that the method is defined to work with an arbitrary type <K>. This allows to search directly for a key field in the object without the need to construct an object containing the key:
persons.binarySearch("john", new SearchByName()); class SearchByName implements Comparator<Object> { public int compare(Object o1, Object o2) { String s1 = (o1 instanceof String) ? (String) o1 : ((Name) o1).getName(); String s2 = (o2 instanceof String) ? (String) o2 : ((Name) o2).getName(); return s1.compareTo(s2); } }
/- Specified by:
binarySearch
in classIList<java.lang.Short>
- Parameters:
index
- index of first element to searchlen
- number of elements to searchkey
- the value to be searched forcomparator
- the comparator by which the list is ordered. A null value indicates that the elements' natural ordering should be used.- Returns:
- index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
- See Also:
Arrays.binarySearch(long[], long)
-
unmodifiableList
public ShortObjGapList unmodifiableList()
Description copied from class:IList
Returns an unmodifiable view of this list. This method allows modules to provide users with "read-only" access to internal lists, where changes made to the original list are visible as query operations on the returned list "read through" to the specified list. Attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException. If this list is already unmodifiable, it is returned unchanged. SeeIList.immutableList()
to get an immutable copy of a list.- Specified by:
unmodifiableList
in classIList<java.lang.Short>
- Returns:
- an unmodifiable view of the specified list
-
immutableList
public ShortObjGapList immutableList()
Description copied from class:IList
Returns an immutable copy of this list. The returned list is independent from the original list, i.e. changes done later are not seen. Attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException. If this list is already immutable, it is returned unchanged. SeeIList.unmodifiableList()
to get unmodifiable view of a list.- Specified by:
immutableList
in classIList<java.lang.Short>
- Returns:
- an immutable copy of the specified list
-
-