Package org.silverpeas.core.util
Class ListSlice<T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<T>
-
- org.silverpeas.core.util.ListSlice<T>
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<T>
,Collection<T>
,List<T>
,RandomAccess
,SilverpeasList<T>
public class ListSlice<T> extends ArrayList<T> implements SilverpeasList<T>
This list represents a slice of a more complete lists and as such contains only the items that are part of this slice.- Author:
- mmoquillon
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description ListSlice(int sliceBeginIndex, int sliceEndIndex)
Constructs a new slice for a given list.ListSlice(int sliceBeginIndex, int sliceEndIndex, long originalListSize)
Constructs a new slice for a given list.ListSlice(int sliceBeginIndex, int sliceEndIndex, List<? extends T> originalList)
Constructs a new slice for a given list.ListSlice(Collection<? extends T> collection)
Constructs a new list slice with all the items of the specified collection.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> ListSlice<T>
emptyList()
Returns an empty list.boolean
equals(Object o)
int
getFirstIndex()
Gets the first index of this slice in the original list from which it comes.int
getLastIndex()
Gets the last index of this slice in the original list from which it comes.int
hashCode()
<U> SilverpeasList<U>
newEmptyListWithSameProperties()
Builds a new emptySilverpeasList
with the same properties than this list.long
originalListSize()
Gets the size of the original list this slice comes from.void
setOriginalListSize(long size)
Sets the size of the original list this slice comes from.-
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
Methods inherited from class java.util.AbstractCollection
containsAll, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
-
Methods inherited from interface org.silverpeas.core.util.SilverpeasList
isSlice
-
-
-
-
Constructor Detail
-
ListSlice
public ListSlice(int sliceBeginIndex, int sliceEndIndex)
Constructs a new slice for a given list.- Parameters:
sliceBeginIndex
- the index in the original list at which this slice starts.sliceEndIndex
- the index in the original list at which this slice should end in the list. The value must be equal or greater than the slice beginning index; a value equal to the beginning index means the last item index in this slice isn't yet known. If the index of the last item in the original list is lesser than the specified index, then this slice ends up at the index of this last item.
-
ListSlice
public ListSlice(int sliceBeginIndex, int sliceEndIndex, long originalListSize)
Constructs a new slice for a given list.- Parameters:
sliceBeginIndex
- the index in the original list at which this slice starts.sliceEndIndex
- the index in the original list at which this slice should end in the list. The value must be equal or greater than the slice beginning index; a value equal to the beginning index means the last item index in this slice isn't yet known. If the index of the last item in the original list is lesser than the specified index, then this slice ends up at the index of this last item.originalListSize
- the size of the original list this slice comes from. It must be greater or equal to 0.
-
ListSlice
public ListSlice(int sliceBeginIndex, int sliceEndIndex, List<? extends T> originalList)
Constructs a new slice for a given list.- Parameters:
sliceBeginIndex
- the index in the original list at which this slice starts.sliceEndIndex
- the index in the original list at which this slice should end in the list. If the index of the last item in the original list is lesser than the specified index, then this slice ends up at the index of this last item. If this index is the same than the beginning index then the slice is empty.originalList
- the original list from which this slice comes from.
-
ListSlice
public ListSlice(Collection<? extends T> collection)
Constructs a new list slice with all the items of the specified collection. This slice will contain the items of the whole specified collection and as such the original list size is equal to its real size.- Parameters:
collection
- a collection of items of type T
-
-
Method Detail
-
emptyList
public static <T> ListSlice<T> emptyList()
Returns an empty list.- Type Parameters:
T
- type of the list's items.- Returns:
- an empty list slice.
-
newEmptyListWithSameProperties
public <U> SilverpeasList<U> newEmptyListWithSameProperties()
Description copied from interface:SilverpeasList
Builds a new emptySilverpeasList
with the same properties than this list.This method is mainly dedicated to be used for making a collector for the Java Stream API.
- Specified by:
newEmptyListWithSameProperties
in interfaceSilverpeasList<T>
- Type Parameters:
U
- the concrete type of the items of the returned list.- Returns:
- an empty
SilverpeasList
with the same properties than this list.
-
getFirstIndex
public int getFirstIndex()
Gets the first index of this slice in the original list from which it comes. It is the inclusive index at which this slice begins in the original list.- Returns:
- the index at which this slice begins in the original list.
-
getLastIndex
public int getLastIndex()
Gets the last index of this slice in the original list from which it comes. It is the inclusive index at which this slice ends in the original list.- Returns:
- the index at which this slice ends in the original list.
-
originalListSize
public long originalListSize()
Gets the size of the original list this slice comes from. If this slice covers all the original list thenoriginalListSize() == size()
. The size of the original list can be unknown at the time the slice is built, in this case -1 is returned.- Specified by:
originalListSize
in interfaceSilverpeasList<T>
- Returns:
- the size of the original list or -1 if such a size isn't known.
-
setOriginalListSize
public void setOriginalListSize(long size)
Sets the size of the original list this slice comes from.- Parameters:
size
- the size of the original list
-
equals
public boolean equals(Object o)
-
-