Class LongObjBigList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- org.magicwerk.brownies.collections.IList<java.lang.Long>
-
- org.magicwerk.brownies.collections.primitive.LongObjBigList
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<java.lang.Long>,java.util.Collection<java.lang.Long>,java.util.List<java.lang.Long>,java.util.RandomAccess,ICollection<java.lang.Long>,IListable<java.lang.Long>
- Direct Known Subclasses:
LongObjBigList.ImmutableLongObjBigList
public class LongObjBigList extends IList<java.lang.Long>
LongObjBigList implements the List interface and uses an instance of LongBigList 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: LongObjBigList.java 2200 2014-03-21 10:46:29Z origo $
- See Also:
BigList,LongBigList, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classLongObjBigList.ImmutableLongObjBigListAn immutable version of a BigList.-
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) LongBigListlist
-
Constructor Summary
Constructors Constructor Description LongObjBigList()LongObjBigList(int capacity)LongObjBigList(java.util.Collection<? extends java.lang.Long> elems)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddAll(int index, java.util.Collection<? extends java.lang.Long> coll)Inserts all of the elements in the specified collection into this list, starting at the specified position.booleanaddAll(int index, IList<? extends java.lang.Long> list2)Inserts all of the elements in the specified list into this list, starting at the specified position.booleanaddAll(java.util.Collection<? extends java.lang.Long> coll)Adds all of the elements in the specified collection into this list.booleanaddAll(IList<? extends java.lang.Long> list2)Adds all of the elements in the specified list into this list.booleanaddArray(int index, java.lang.Long... elems)Inserts the specified elements into this list, starting at the specified position.booleanaddArray(java.lang.Long... elems)Adds all specified elements into this list.<K> intbinarySearch(int index, int len, K key, java.util.Comparator<? super K> comparator)Searches the specified range for an object using the binary search algorithm.intcapacity()Returns capacity of this BigList.LongObjBigListclone()Returns a shallow copy of this list.booleancontains(java.lang.Object elem)booleancontainsAll(java.util.Collection<?> coll)booleancontainsAny(java.util.Collection<?> coll)Returns true if any of the elements of the specified collection is contained in the list.LongObjBigListcopy()Returns a shallow copy of this list.static LongObjBigListcreate()static LongObjBigListcreate(java.lang.Long... elems)static LongObjBigListcreate(java.util.Collection<? extends java.lang.Long> elems)protected booleandoAdd(int index, java.lang.Long elem)Helper method for adding an element to the list.protected voiddoAssign(IList<java.lang.Long> that)Assign this list the content of the that list.protected voiddoClone(IList<java.lang.Long> that)Initialize this object after the bitwise copy has been made by Object.clone().IList<java.lang.Long>doCreate(int capacity)Create list with specified capacity.protected voiddoEnsureCapacity(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.LongdoGet(int index)Helper method for getting an element from the list.protected voiddoGetAll(java.lang.Object[] elems, int index, int len)Helper method to fill the specified elements in an array.protected java.lang.LongdoRemove(int index)Helper method to remove an element.protected voiddoRemoveAll(int index, int len)Remove specified range of elements from list.protected java.lang.LongdoReSet(int index, java.lang.Long elem)Sets an element at specified position.protected java.lang.LongdoSet(int index, java.lang.Long elem)Helper method for setting an element in the list.booleanequals(java.lang.Object obj)java.lang.Longget(int index)Return element at specified positionBigList<java.lang.Long>getAll(int index, int len)Returns specified range of elements from list.java.lang.LonggetDefaultElem()inthashCode()LongObjBigListimmutableList()Returns an immutable copy of this list.intindexOf(java.lang.Object elem)voidinit()voidinit(java.lang.Long... elems)voidinit(java.util.Collection<? extends java.lang.Long> elems)booleanisEmpty()booleanisReadOnly()Returns true if this list is either unmodifiable or immutable, false otherwise.intlastIndexOf(java.lang.Object elem)voidmove(int srcIndex, int dstIndex, int len)Move specified elements.booleanremove(java.lang.Object elem)booleanremoveAll(java.util.Collection<?> coll)booleanremoveAll(IList<?> coll)booleanremoveFirstOccurrence(java.lang.Object elem)SeeDeque.removeFirstOccurrence(java.lang.Object)booleanremoveLastOccurrence(java.lang.Object elem)SeeDeque.removeLastOccurrence(java.lang.Object)booleanretainAll(java.util.Collection<?> coll)booleanretainAll(IList<?> coll)voidsetAll(int index, java.util.Collection<? extends java.lang.Long> coll)Sets the specified elements.voidsetAll(int index, IList<? extends java.lang.Long> list2)Sets the specified elements.voidsetArray(int index, java.lang.Long... elems)Sets the specified elements.intsize()Return size of listvoidsort(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 long[]toPrimitive(java.lang.Long[] elems)(package private) static long[]toPrimitive(java.util.Collection<? extends java.lang.Long> list)(package private) static long[]toPrimitive(BigList<? extends java.lang.Long> list2)java.lang.StringtoString()(package private) static java.lang.Long[]toWrapper(long[] elems)voidtrimToSize()An application can use this operation to minimize the storage of an instance.LongObjBigListunmodifiableList()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
LongBigList list
-
-
Method Detail
-
toWrapper
static java.lang.Long[] toWrapper(long[] elems)
-
toPrimitive
static long[] toPrimitive(java.lang.Long[] elems)
-
toPrimitive
static long[] toPrimitive(BigList<? extends java.lang.Long> list2)
-
toPrimitive
static long[] toPrimitive(java.util.Collection<? extends java.lang.Long> list)
-
create
public static LongObjBigList create()
-
create
public static LongObjBigList create(java.lang.Long... elems)
-
create
public static LongObjBigList create(java.util.Collection<? extends java.lang.Long> elems)
-
init
public void init()
-
init
public void init(java.lang.Long... elems)
-
init
public void init(java.util.Collection<? extends java.lang.Long> elems)
-
doClone
protected void doClone(IList<java.lang.Long> that)
Description copied from class:IListInitialize this object after the bitwise copy has been made by Object.clone().
-
doAssign
protected void doAssign(IList<java.lang.Long> that)
Description copied from class:IListAssign 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:IListReturns true if this list is either unmodifiable or immutable, false otherwise.- Specified by:
isReadOnlyin classIList<java.lang.Long>
-
copy
public LongObjBigList copy()
Description copied from class:IListReturns 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:
copyin interfaceICollection<java.lang.Long>- Specified by:
copyin classIList<java.lang.Long>- Returns:
- a modifiable copy of this list
-
clone
public LongObjBigList clone()
Description copied from class:IListReturns 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.Long getDefaultElem()
- Specified by:
getDefaultElemin classIList<java.lang.Long>
-
doCreate
public IList<java.lang.Long> doCreate(int capacity)
Description copied from class:IListCreate list with specified capacity.
-
size
public int size()
Description copied from interface:IListableReturn size of list
-
capacity
public int capacity()
Returns capacity of this BigList. Note that two BigLists 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.Long get(int index)
Description copied from interface:IListableReturn element at specified position
-
doGet
protected java.lang.Long doGet(int index)
Description copied from class:IListHelper 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:IListHelper method to fill the specified elements in an array.
-
doAdd
protected boolean doAdd(int index, java.lang.Long elem)Description copied from class:IListHelper 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.Long doSet(int index, java.lang.Long elem)Description copied from class:IListHelper 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.Long doRemove(int index)
Description copied from class:IListHelper 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:IListRemove specified range of elements from list.- Overrides:
doRemoveAllin classIList<java.lang.Long>- Parameters:
index- index of first element to removelen- number of elements to remove
-
doReSet
protected java.lang.Long doReSet(int index, java.lang.Long elem)Description copied from class:IListSets 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:IListMove 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:IListIncreases 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:
doEnsureCapacityin classIList<java.lang.Long>- Parameters:
minCapacity- the desired minimum capacity
-
trimToSize
public void trimToSize()
Description copied from class:IListAn application can use this operation to minimize the storage of an instance.- Specified by:
trimToSizein classIList<java.lang.Long>
-
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:
lastIndexOfin interfacejava.util.List<java.lang.Long>- Overrides:
lastIndexOfin classIList<java.lang.Long>
-
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:IListReturns true if any of the elements of the specified collection is contained in the list.- Overrides:
containsAnyin classIList<java.lang.Long>- 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:
containsAllin interfacejava.util.Collection<java.lang.Long>- Specified by:
containsAllin interfacejava.util.List<java.lang.Long>- Overrides:
containsAllin classIList<java.lang.Long>
-
removeAll
public boolean removeAll(java.util.Collection<?> coll)
-
removeAll
public boolean removeAll(IList<?> coll)
- Overrides:
removeAllin classIList<java.lang.Long>- See Also:
IList.removeAll(Collection)
-
retainAll
public boolean retainAll(java.util.Collection<?> coll)
-
retainAll
public boolean retainAll(IList<?> coll)
- Overrides:
retainAllin classIList<java.lang.Long>- 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:
toArrayin classIList<java.lang.Long>- 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.Long> coll)
Description copied from class:IListAdds 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:
addAllin interfacejava.util.Collection<java.lang.Long>- Specified by:
addAllin interfacejava.util.List<java.lang.Long>- Overrides:
addAllin classIList<java.lang.Long>- 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.Long> coll)Description copied from class:IListInserts 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:
addAllin interfacejava.util.List<java.lang.Long>- Overrides:
addAllin classIList<java.lang.Long>- 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.Long... elems)
Description copied from class:IListAdds all specified elements into this list.
-
addArray
public boolean addArray(int index, java.lang.Long... elems)Description copied from class:IListInserts 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.Long> list2)
Description copied from class:IListAdds all of the elements in the specified list into this list.
-
addAll
public boolean addAll(int index, IList<? extends java.lang.Long> list2)Description copied from class:IListInserts 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:IListSeeDeque.removeFirstOccurrence(java.lang.Object)- Overrides:
removeFirstOccurrencein classIList<java.lang.Long>
-
removeLastOccurrence
public boolean removeLastOccurrence(java.lang.Object elem)
Description copied from class:IListSeeDeque.removeLastOccurrence(java.lang.Object)- Overrides:
removeLastOccurrencein classIList<java.lang.Long>
-
getAll
public BigList<java.lang.Long> getAll(int index, int len)
Description copied from class:IListReturns specified range of elements from list.
-
setAll
public void setAll(int index, IList<? extends java.lang.Long> list2)Description copied from class:IListSets the specified elements.
-
setAll
public void setAll(int index, java.util.Collection<? extends java.lang.Long> coll)Description copied from class:IListSets the specified elements.
-
setArray
public void setArray(int index, java.lang.Long... elems)Description copied from class:IListSets the specified elements.
-
sort
public void sort(int index, int len, java.util.Comparator comparator)Description copied from class:IListSort 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:IListSearches 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:
binarySearchin classIList<java.lang.Long>- 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 LongObjBigList unmodifiableList()
Description copied from class:IListReturns 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:
unmodifiableListin classIList<java.lang.Long>- Returns:
- an unmodifiable view of the specified list
-
immutableList
public LongObjBigList immutableList()
Description copied from class:IListReturns 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:
immutableListin classIList<java.lang.Long>- Returns:
- an immutable copy of the specified list
-
-