E - the class of the elements of this list.
Created: Sun Aug 26 23:25:26 2007public final class TwoSidedList<E> extends Object implements List<E>
As a consequence, one can add elements not only at the end of this list
but also at its beginning.
For details consider add(Object), addFirst(Object)
and addLast(Object).
Method add(int ind, Object obj) is not supported
because inserting an element
requires either shift of subsequent elements to the right
or preceeding elements to the left.
To determine the direction of the shift
use add(int ind, Object obj, Direction dir) instead.
Similar considerations apply to methods removing elements.
Also affected are the corresponding collections operations
like addAll.
Methods toArray() and toArray(Object[])
satisfy a generalized contract
based on the additional method firstIndex().
Essentially this two sided list wrapps a classical list.
Various constructors allow to pass that list.
This allows to determine the performance behavior.
The signatures of the constructors
generalize the constructors known
from implementations of classical Lists.
The observant reader observes
that the generics are slightly more restrictive than for classical lists.
This is for performance reasons.
Note that the constructors do not create a copy of the wrapped list
which may cause hidden dependencies.
If full generality is needed
the user is asked to use the corresponding factory methods.
Additionally methods concerning indices are provided
like firstIndex(), minFreeIndex()
and it is possible to shift a list using shiftRight(int).
| Modifier and Type | Class and Description |
|---|---|
static class |
TwoSidedList.Direction
Used as an argument for methods adding or removing elements
from this list
to determine in which direction this list has to shrink or grow.
|
| Modifier and Type | Field and Description |
|---|---|
private int |
firstIndex
The first index in this
TwoSidedList. |
private List<E> |
list
The list backed by this two-sided list.
|
| Constructor and Description |
|---|
TwoSidedList(int firstIndex)
Creates a new empty
TwoSidedList which starts growing
with index firstIndex. |
TwoSidedList(List<E> list)
Creates a new
TwoSidedList
from a List with firstIndex == 0. |
TwoSidedList(List<E> list,
int firstIndex)
Creates a new
TwoSidedList
containing the elements of list in proper sequence
with first index given by firstIndex. |
TwoSidedList(TwoSidedList<E> other)
Copy constructor with shallow copy of the wrapped list
list. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E obj)
Not supported by this implementation. **** breaks contract
|
void |
add(int ind,
E obj)
Not supported by this implementation. **** breaks contract
|
void |
add(int ind,
E obj,
TwoSidedList.Direction dir)
Inserts
obj at the specified position ind
in this list (optional operation). |
boolean |
addAll(Collection<? extends E> coll)
Not supported by this implementation.
|
boolean |
addAll(int ind,
Collection<? extends E> coll)
Not supported by this implementation.
|
boolean |
addAll(int ind,
Collection<? extends E> coll,
TwoSidedList.Direction dir)
Inserts all of the elements in
coll into this list
at the specified position (optional operation). |
boolean |
addAllFirst(Collection<? extends E> coll)
Adds
obj at the beginning of this list. |
boolean |
addAllLast(Collection<? extends E> coll)
Appends all of the elements in
coll
to the end of this list,
in the order that they are returned
by coll's iterator (optional operation). |
boolean |
addFirst(E obj)
Adds
obj at the beginning of this list. |
boolean |
addLast(E obj)
Adds
obj at the end of this list. |
(package private) void |
checkIncMinFreeIndex()
Checks whether incrementing
minFreeIndex()
would cause overrun of minFreeIndex(). |
(package private) void |
checkMinFreeIndex(int numAdded)
Checks whether adding
numAdded objects
to this list **** or at the tail of this list
would cause overrun of minFreeIndex(). |
(package private) void |
checkRange(int ind)
Checks whether index
ind is in range
and throws an appropriate exception if not. |
private void |
checkRange(int ind,
TwoSidedList.Direction dir)
Checks whether index
ind is in range
and throws an appropriate exception if not. |
private void |
checkRange(String fromToNothing,
int ind,
int min,
int maxP)
Checks whether index
ind is in range
and throws an appropriate exception if not. |
void |
clear()
Removes all of the elements from this list (optional operation).
|
boolean |
contains(Object obj)
Returns whether this list contains the specified element.
|
boolean |
containsAll(Collection<?> coll)
Replaces the element at the
indth position
in this list with the specified element (optional operation). |
static <E> TwoSidedList<E> |
create(List<? extends E> list)
Creates a new
TwoSidedList
containing the elements of list in proper sequence. |
static <E> TwoSidedList<E> |
create(List<? extends E> list,
int firstIndex)
Creates a new
TwoSidedList
containing the elements of list in proper sequence
with first index given by firstIndex. |
static <E> TwoSidedList<E> |
create(TwoSidedList<? extends E> other)
|
private void |
decFirstIndex()
Decrements
firstIndex if possible;
otherwise throws an exception. |
boolean |
equals(Object obj)
The given object equals this twosided list
if and only if it is as well a
TwoSidedList,
the two lists wrapped list coincide
and either as well the first indices firstIndex coincide. |
int |
firstIndex()
Returns
firstIndex. |
void |
firstIndex(int firstIndex)
Sets
firstIndex according to the parameter. |
E |
get(int ind)
Returns the element at the specified position in this list.
|
int |
hashCode()
Returns a hash code which conforms with
equals(Object). |
private void |
incFirstIndex()
Increments
firstIndex if possible;
otherwise throws an exception. |
int |
indexOf(Object obj)
Returns the index of the first occurrence
of the specified element
obj in this list,
or firstIndex()-1 if this list does not contain the element. |
boolean |
isEmpty()
Returns true if this list contains no elements.
|
Iterator<E> |
iterator() |
int |
lastIndexOf(Object obj)
Returns the index of the last occurrence
of the specified element
obj in this list,
or firstIndex()-1 if this list does not contain the element. |
List<E> |
list() |
ListIterator<E> |
listIterator() |
ListIterator<E> |
listIterator(int ind)
****maybe to be endowed with a direction.
|
static void |
main(String[] args) |
int |
minFreeIndex() |
E |
remove(int ind)
Not supported by this implementation. **** breaks contract
|
E |
remove(int ind,
TwoSidedList.Direction dir)
Removes the element at the specified position in this list
(optional operation).
|
boolean |
remove(Object obj)
Not supported by this implementation. **** breaks contract
|
boolean |
removeAll(Collection<?> coll)
Not supported by this implementation.
|
boolean |
removeAll(Collection<?> coll,
TwoSidedList.Direction dir)
Removes from this list all of its elements
that are contained in
coll (optional operation). |
boolean |
removeFirst(Object obj)
Removes the first occurrence of
obj from this list,
if present (optional operation). |
boolean |
removeLast(Object obj)
Removes the last occurrence of
obj from this list,
if present (optional operation). |
boolean |
retainAll(Collection<?> coll)
Not supported by this implementation.
|
boolean |
retainAll(Collection<?> coll,
TwoSidedList.Direction dir)
Retains only the elements in this list
that are contained in
coll (optional operation). |
E |
set(int ind,
E obj)
Replaces the element at the
indth position
in this list with the specified element (optional operation). |
int |
shiftRight(int num)
Shifts this list
num indices to the right. |
int |
size()
Returns the number of elements in this list.
|
private void |
subFirstIndex(int numAdded)
Subtracts
numAdded from firstIndex if possible;
otherwise throws an exception. |
List<E> |
subList(int indStart,
int indEnd)
Returns a view of the portion of this twosided list as a list
between the specified
fromIndex, inclusive,
and toIndex, exclusive. |
TwoSidedList<E> |
subList2(int indStart,
int indEnd)
Returns a view of the portion of this twosided list
between the specified
fromIndex, inclusive,
and toIndex, exclusive. |
Object[] |
toArray()
Note that this generalizes the contract of the underlying interface:
Instead of
this.toArray[i] == this.get(i)
now only this.toArray[i] == this.get(i-firstIndex()). |
<E> E[] |
toArray(E[] objArr)
Note that this generalizes the contract of the underlying interface:
Instead of
this.toArray[i] == this.get(i)
now only this.toArray[i] == this.get(i-firstIndex()). |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitreplaceAll, sort, spliteratorparallelStream, removeIf, streamprivate int firstIndex
TwoSidedList.
Note that this integer may well be negative.
The inequality
minFreeIndex() >= firstIndex
is guaranteed.
Casually, methods adding objects have to reject them
in order not to hurt this
alhough the backed list list
would allow adding further elements.public TwoSidedList(List<E> list, int firstIndex)
TwoSidedList
containing the elements of list in proper sequence
with first index given by firstIndex.
Note the difference to reference implementations such as
java.util.ArrayList where the type of the list argument
is List extends E>.
We deviate from this solution for performance reason
and provide as an alternative
the factory method create(List,int).
CAUTION:
This list backs list and so changes to one of the list
affect the other list.
list - the list wrapped by this twosided list.firstIndex - the index where this list starts growing.IllegalStateException - if list is so long
and firstIndex is so large
that minFreeIndex() would overrun.public TwoSidedList(List<E> list)
TwoSidedList
from a List with firstIndex == 0.
This is the canonical generalization of lists
as mentioned in the documentation
of indexOf(Object) and of lastIndexOf(Object).
Note the difference to reference implementations such as
java.util.ArrayList where the type of the list argument
is List extends E>.
We deviate from this solution for performance reason
and provide as an alternative
the factory method create(List,int).
CAUTION:
Changes to list influence this twosided list
and may cause malfunction.
Note that unlike TwoSidedList(List, int)
this constructor cannot throw an IllegalStateException.
list - the list wrapped by this twosided list.public TwoSidedList(TwoSidedList<E> other)
list.
As a consequence, modifications of the list created
may affect the original one and the other way round.
Note that unlike TwoSidedList(List, int)
this constructor cannot throw an IllegalStateException.other - another TwoSidedList.public TwoSidedList(int firstIndex)
TwoSidedList which starts growing
with index firstIndex.
Note that unlike TwoSidedList(List, int)
this constructor cannot throw an IllegalStateException.firstIndex - the index where this list starts growing.public static <E> TwoSidedList<E> create(List<? extends E> list, int firstIndex)
TwoSidedList
containing the elements of list in proper sequence
with first index given by firstIndex.list - the list wrapped by this twosided list.
Changes to list do not influence this twosided list.firstIndex - the index where this list starts growing.IllegalStateException - if list is so long
and firstIndex is so large
that minFreeIndex() would overrun.public static <E> TwoSidedList<E> create(List<? extends E> list)
TwoSidedList
containing the elements of list in proper sequence.list - the list wrapped by this twosided list.
Changes to list do not influence this twosided list.public static <E> TwoSidedList<E> create(TwoSidedList<? extends E> other)
TwoSidedList
as a copy of other
copying also the wrapped list list.
As a consequence, the list created and the original one
act independently.
Note that unlike TwoSidedList(List, int)
this constructor cannot throw an IllegalStateException.other - another TwoSidedList.void checkRange(int ind)
ind is in range
and throws an appropriate exception if not.ind - the index to be checked.IndexOutOfBoundsException - if not firstIndex() <= ind < minFreeIndex()
with message
"Index: <ind> Range: <firstIndex>
- <minFreeIndex()> exclusively. "
.
private void checkRange(int ind,
TwoSidedList.Direction dir)
ind is in range
and throws an appropriate exception if not.ind - the index to be checked.dir - the direction in which this twosided list may grow.IndexOutOfBoundsException - dir == Left2Right
if not firstIndex() <= ind < minFreeIndex()+1.
dir == Right2Left
if not firstIndex()-1 <= ind < minFreeIndex().
"Index: <ind>Range:<firstIndex>
- <minFreeIndex()>exclusively. "
.add(int, Object, Direction),
private void checkRange(String fromToNothing, int ind, int min, int maxP)
ind is in range
and throws an appropriate exception if not.fromToNothing - either "", "from" or "to".
The latter two cases are used only in subList(int,int)
to check the range of the start index and of the end index
of the sublist to be created.ind - the index to be checked.min - the minimal value for ind accepted.maxP - one plus the maximal value for ind accepted.IndexOutOfBoundsException - if not min >= ind < maxP.
The message is
"Index: <ind> Range: <firstIndex>
- <minFreeIndex()> exclusively. "
preceeded by fromToNothing.
private void decFirstIndex()
firstIndex if possible;
otherwise throws an exception.
This method is used by methods adding objects at the head of this list.
The error message is tailored to this usage.IllegalStateException - if firstIndex == Integer.MIN_VALUE
adding an element would cause index underrun.private void incFirstIndex()
firstIndex if possible;
otherwise throws an exception.
This method is used by methods removing objects
from the head of this list.
The error message is tailored to this usage.IllegalStateException - if firstIndex == Integer.MAX_VALUE
removing an element would cause index overrun.void checkIncMinFreeIndex()
minFreeIndex()
would cause overrun of minFreeIndex().IllegalStateException - if incrementing minFreeIndex()
would cause overrun of minFreeIndex().private void subFirstIndex(int numAdded)
numAdded from firstIndex if possible;
otherwise throws an exception.
This method is used by methods adding objects at the head of this list.
The error message is tailored to this usage.IllegalStateException - if adding numAdded objects
at the head of this list
would cause underrun of firstIndex.void checkMinFreeIndex(int numAdded)
numAdded objects
to this list **** or at the tail of this list
would cause overrun of minFreeIndex().IllegalStateException - if adding numAdded objects
to this list **** or at the tail of this list
would cause overrun of minFreeIndex().public int firstIndex()
firstIndex.public void firstIndex(int firstIndex)
firstIndex according to the parameter.public int minFreeIndex()
public int shiftRight(int num)
num indices to the right.num - the number of shifts to the right
to be performed on this list.
A negative sign signifies a shift to the left.IllegalStateException - if shifting would cause overrun of minFreeIndex()
(occuring for proper shift to the right)
or underrun of firstIndex()
(occuring for proper shift to the left).public int size()
Integer.MAX_VALUE elements,
returns Integer.MAX_VALUE.
**** gives rise to malfunction. ****public boolean isEmpty()
public boolean contains(Object obj)
true
if and only if this list contains at least one element obj
such that (o==null ? e==null : o.equals(e)).contains in interface Collection<E>contains in interface List<E>obj - an Object valueboolean valueClassCastException - if the class of obj
is incompatible with list.NullPointerException - if obj == null
and list does not permit null elements.public int indexOf(Object obj)
obj in this list,
or firstIndex()-1 if this list does not contain the element.
More formally, returns the lowest index i
such that (obj==null ? get(i)==null : obj.equals(get(i))),
or firstIndex()-1 if there is no such index.
CAUTION:
obj not in list"
is no longer this.indexOf(obj) == -1 but
this.indexOf(obj) < this.firstIndex()-1.
This is an extension in that
wrapping an ordinary list in a twosided list
is by specifying firstIndex() == 0
(see TwoSidedList(List list)).
firstIndex() == Integer.MIN_VALUE
firstIndex()-1 > firstIndex().
public int lastIndexOf(Object obj)
obj in this list,
or firstIndex()-1 if this list does not contain the element.
More formally, returns the highest index i
such that (obj==null ? get(i)==null : obj.equals(get(i))),
or firstIndex()-1 if there is no such index.
CAUTION:
obj not in list"
is no longer this.indexOf(obj) == -1 but
this.indexOf(obj) < this.firstIndex()-1.
This is an extension in that
wrapping an ordinary list in a twosided list
is by specifying firstIndex() == 0
(see TwoSidedList(List list)).
firstIndex() == Integer.MIN_VALUE
firstIndex()-1 > firstIndex().
lastIndexOf in interface List<E>obj - an Object valueobj
if this object is in this list.
In this case, the return value is within the range
firstIndex()..firstFreeIndex()-1.
firstIndex()-1 if obj is not in this list.
public Object[] toArray()
this.toArray[i] == this.get(i)
now only this.toArray[i] == this.get(i-firstIndex()).
Equality includes that the left hand side throws an exception
if and only if so does te right hand side.public <E> E[] toArray(E[] objArr)
this.toArray[i] == this.get(i)
now only this.toArray[i] == this.get(i-firstIndex()).
Equality includes that the left hand side throws an exception
if and only if so does te right hand side.public E get(int ind)
get in interface List<E>ind - the index of the element to return as an int value.IndexOutOfBoundsException - as described for checkRange(int)public E set(int ind, E obj)
indth position
in this list with the specified element (optional operation).set in interface List<E>ind - the index of the element to replace as an int value.obj - the element to be stored at the specified position.indth positionUnsupportedOperationException - if the set operation is not supported
by list.ClassCastException - if the class of obj
prevents it from being added to list.NullPointerException - if obj == null
and list does not permit null elements.IllegalArgumentException - if some property of obj
prevents it from being added to list.IndexOutOfBoundsException - as described for checkRange(int)public boolean add(E obj)
add in interface Collection<E>add in interface List<E>UnsupportedOperationException - use addFirst(E) and addLast(E) instead.public boolean addFirst(E obj)
obj at the beginning of this list.
The first index returned by firstIndex()
is decremented.obj - the E object to be added.true by specification.UnsupportedOperationException - if the add(int,E) operation is not supported
by list.ClassCastException - if the class of obj
prevents it from being added to list.NullPointerException - if obj == null
and list does not permit null elements.IllegalArgumentException - if some property of obj
prevents it from being added to list.IllegalStateException - if firstIndex == Integer.MIN_VALUE
adding an element would cause index underrun.public boolean addLast(E obj)
obj at the end of this list.
The first index returned by firstIndex() remains unchanged.obj - the E object to be added.true by specification.UnsupportedOperationException - if the add(E) operation is not supported
by list.ClassCastException - if the class of obj
prevents it from being added to list.NullPointerException - if obj == null
and list does not permit null elements.IllegalArgumentException - if some property of obj
prevents it from being added to list.IllegalStateException - if adding objects to this list
would cause overrun of minFreeIndex().public void add(int ind,
E obj)
add in interface List<E>UnsupportedOperationException - use add(int,Object,Direction) instead.public void add(int ind,
E obj,
TwoSidedList.Direction dir)
obj at the specified position ind
in this list (optional operation).
Shifts the element currently at that position (if any)
and any following/preceeding elements to the direction dir
(increments/decrements their indices).ind - the index where to insert obj.
After having performed this operation,
ind is the index of obj.obj - the E element to be inserted.dir - determines the direction to shift the list.
Left2Right:
shifts all subsequent objects in this list
starting with index ind to the right
adding one to their indices.
Right2Left:
shifts all objects in this list
to index ind to the left
subtracting one from their indices.
UnsupportedOperationException - if the add operation
is not supported by list.ClassCastException - if the class of obj
prevents it from being added to list.NullPointerException - if obj == null
and list does not permit null elements.IllegalArgumentException - if some property of obj
prevents it from being added to list.IndexOutOfBoundsException - as described for checkRange(int,Direction)public E remove(int ind)
remove in interface List<E>UnsupportedOperationException - use remove(int,Direction) instead.public E remove(int ind, TwoSidedList.Direction dir)
dir
(decrements/increments their indices).
Returns the element that was removed from the list.ind - the index of the element to be removed
as an int value.UnsupportedOperationException - if the remove(int) operation
is not supported by list.IndexOutOfBoundsException - as described for checkRange(int)public boolean remove(Object obj)
remove in interface Collection<E>remove in interface List<E>UnsupportedOperationException - use removeFirst(Object)
and removeLast(Object) instead.public boolean removeFirst(Object obj)
obj from this list,
if present (optional operation).
If this list does not contain obj, it is unchanged.
More formally, removes the element with the lowest index i
such that (obj==null ? get(i)==null : obj.equals(get(i)))
(if such an element exists).
Returns true if this list contained the specified element
(or equivalently, if this list changed as a result of the call).
The first index returned by firstIndex() remains unchanged.obj - the element to be removed from this list, if present.UnsupportedOperationException - if the remove(Object) operation is not supported
by list.public boolean removeLast(Object obj)
obj from this list,
if present (optional operation).
If this list does not contain obj, it is unchanged.
More formally,
removes the element with the highest index i
such that (obj==null ? get(i)==null : obj.equals(get(i)))
(if such an element exists).
Returns true if this list contained the specified element
(or equivalently, if this list changed as a result of the call).
The first index returned by firstIndex() is incremented
if really an object was removed.obj - the element to be removed from this list, if present.UnsupportedOperationException - if the remove(int) **** not remove(Object)
operation is not supported
by list.public void clear()
firstIndex is unmodified.clear in interface Collection<E>clear in interface List<E>UnsupportedOperationException - if the clear operation is not supported by list.public boolean addAll(Collection<? extends E> coll)
addAll in interface Collection<E>addAll in interface List<E>UnsupportedOperationException - use addAllFirst(java.util.Collection<? extends E>) and addAllLast(java.util.Collection<? extends E>) instead.public boolean addAllFirst(Collection<? extends E> coll)
obj at the beginning of this list.
in the order that they are returned
by coll's iterator (optional operation).
The behavior of this operation is undefined
if the specified collection is modified
while the operation is in progress.
(Note that this will occur if coll is this list,
and it's nonempty.)
The first index returned by firstIndex()
is reduced by coll's size.coll - a Collection valueboolean value.UnsupportedOperationException - if the addAll operation is not supported by this list.ClassCastException - if the class of an element of the specified collection
prevents it from being added to list.NullPointerException - if the specified collection contains
one or more null elements
and list does not permit null elements
or if the specified collection is nullIllegalArgumentException - if some property of an element of the specified collection
prevents it from being added to list.IllegalStateException - if adding numAdded objects
at the head of this list
would cause underrun of firstIndex.public boolean addAllLast(Collection<? extends E> coll)
coll
to the end of this list,
in the order that they are returned
by coll's iterator (optional operation).
The behavior of this operation is undefined
if the specified collection is modified
while the operation is in progress.
(Note that this will occur if coll is this list,
and it's nonempty.)
The first index returned by firstIndex() remains unchanged.coll - another Collection.boolean value.UnsupportedOperationException - if the addAll operation is not supported by this list.ClassCastException - if the class of an element of the specified collection
prevents it from being added to list.NullPointerException - if the specified collection contains
one or more null elements
and list does not permit null elements
or if the specified collection is nullIllegalArgumentException - if some property of an element of the specified collection
prevents it from being added to list.IllegalStateException - if adding numAdded objects
to this list **** or at the tail of this list
would cause overrun of minFreeIndex().public boolean addAll(int ind,
Collection<? extends E> coll)
addAll in interface List<E>UnsupportedOperationException - use addAll(int,Collection,Direction) instead.public boolean addAll(int ind,
Collection<? extends E> coll,
TwoSidedList.Direction dir)
coll into this list
at the specified position (optional operation).
Shifts the elements currently at that positions (if any)
and any following/preceeding elements to the direction dir
(increasing/decreasing their indices by coll's size).
The new elements will appear in this list in the order
that they are returned by the specified collection's iterator.
The behavior of this operation is undefined
if the specified collection is modified
while the operation is in progress.
(Note that this will occur if the specified collection is this list,
and it's nonempty.)ind - index at which to insert the first element from coll
as an int value.
CAUTION: Note that ind
always references the first element in coll
independent from dir.coll - a Collection
containing elements to be added to this list.dir - determines the direction to shift the list.
Left2Right:
shifts all subsequent objects in this list
starting with index ind to the right
adding one to their indices.
Right2Left:
shifts all objects in this list
to index ind to the left
subtracting one from their indices.
boolean value.UnsupportedOperationException - if the addAll operation
is not supported by this list.ClassCastException - if the class of an element of coll
prevents it from being added to list.NullPointerException - if the coll contains
at least one null element
and list does not permit null elements
or if coll == null.IllegalArgumentException - if some property of an element of the specified collection
prevents it from being added to list.IndexOutOfBoundsException - as described for checkRange(int,Direction)IllegalStateException - if adding coll to this list
would cause underrun of firstIndex
or overrun of minFreeIndex().public ListIterator<E> listIterator()
listIterator in interface List<E>public ListIterator<E> listIterator(int ind)
listIterator in interface List<E>ind - an int valueListIterator valueIndexOutOfBoundsException - if not firstIndex() <= ind <= minFreeIndex()
with message
"Index: <ind> Range: <firstIndex> -
<minFreeIndex()> exclusively. "
.public boolean containsAll(Collection<?> coll)
indth position
in this list with the specified element (optional operation).containsAll in interface Collection<E>containsAll in interface List<E>coll - a Collection valueboolean valueClassCastException - if the class of one or more elements of coll
is incompatible with list.NullPointerException - if coll contains at least one null element
and list is incompatible with null elements
or if coll == null.public boolean removeAll(Collection<?> coll)
removeAll in interface Collection<E>removeAll in interface List<E>UnsupportedOperationException - use removeAll(Collection,Direction) instead.public boolean removeAll(Collection<?> coll, TwoSidedList.Direction dir)
coll (optional operation).
Shifts the elements currently at that position (if any)
and any following/preceeding elements to the direction dir
(decreasing/increasing their indices
by the number of elements removed).coll - a Collection
containing elements to be removed from this list.dir - determines the direction to shift the list.
Left2Right:
to close gaps by removing elements
shifts all objects preceeding gaps to the right
adding one to their indices.
Right2Left:
to close gaps by removing elements
shifts all objects following gaps to the left
subtracting one from their indices.
boolean value.UnsupportedOperationException - if the removeAll operation
is not supported by this list.ClassCastException - if the class of an element of coll
is incompatible with list.NullPointerException - if the coll contains
at least one null element
and list does not permit null elements
or if coll == null.public boolean retainAll(Collection<?> coll)
retainAll in interface Collection<E>retainAll in interface List<E>UnsupportedOperationException - use retainAll(Collection,Direction) instead.public boolean retainAll(Collection<?> coll, TwoSidedList.Direction dir)
coll (optional operation).
In other words, removes from this list all the elements
that are not contained in coll.
Shifts the elements currently at that position (if any)
and any following/preceeding elements to the direction dir
(decreasing/increasing their indices
by the number of elements removed).coll - a Collection
containing elements to be retained in this list.dir - determines the direction to shift the list.
Left2Right:
to close gaps by removing elements
shifts all objects preceeding gaps to the right
adding one to their indices.
Right2Left:
to close gaps by removing elements
shifts all objects following gaps to the left
subtracting one from their indices.
boolean value.UnsupportedOperationException - if the retainAll operation
is not supported by this list.ClassCastException - if the class of an element of coll
is incompatible with list.NullPointerException - if the coll contains
at least one null element
and list does not permit null elements
or if coll == null.public List<E> subList(int indStart, int indEnd)
fromIndex, inclusive,
and toIndex, exclusive.subList in interface List<E>indStart - low endpoint (inclusive) of the subList to be returned.indEnd - high endpoint (exclusive) of the subList to be returned.IndexOutOfBoundsException - if not
firstIndex() <= indStart <= indEnd <= minFreeIndex()public TwoSidedList<E> subList2(int indStart, int indEnd)
fromIndex, inclusive,
and toIndex, exclusive.indStart - low endpoint (inclusive) of the subList to be returned.indEnd - high endpoint (exclusive) of the subList to be returned.IndexOutOfBoundsException - see subList(int,int)public boolean equals(Object obj)
TwoSidedList,
the two lists wrapped list coincide
and either as well the first indices firstIndex coincide.
CAUTION:
Note that two empty lists with different first index are not equal.
This is justified by the fact,
that these two become different when the same first element is added
to both lists.public int hashCode()
equals(Object).public static void main(String[] args)
Copyright © 2012–2018 Simuline Organization (l2r). All rights reserved.