Package eu.simuline.util
Class CollectionsExt.ImmutableCyclicList<E>
- java.lang.Object
-
- eu.simuline.util.CollectionsExt.ImmutableCyclicList<E>
-
- Type Parameters:
E- the class of the elements of this list.
- All Implemented Interfaces:
CyclicList<E>,Iterable<E>,Collection<E>
- Enclosing class:
- CollectionsExt<E>
public static final class CollectionsExt.ImmutableCyclicList<E> extends Object implements CyclicList<E>
Represents an immutable cyclic list by throwing an exception when invoking a method which modifies this list.
-
-
Field Summary
Fields Modifier and Type Field Description private CyclicList<E>wrapped
-
Constructor Summary
Constructors Constructor Description ImmutableCyclicList(CyclicList<E> wrapped)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)Inserts the specified element at the specified position in this list (optional operation).booleanadd(E element)voidaddAll(int index, Iterator<E> iter)Inserts the cyclic list of the specified iterator at the specified position in this list (optional operation).voidaddAll(int index, List<? extends E> list)Inserts the specified list at the given position in this cyclic list (optional operation).booleanaddAll(Collection<? extends E> coll)List<E>asList()List<E>asList(int index)Returns a List containing all of the elements in this cyclic list in proper sequence.voidclear()Removes all of the elements from this list (optional operation).booleancontains(Object obj)Returnstrueif this list contains the specified element.booleancontainsAll(Collection<?> coll)CyclicList<E>cycle(int num)Returns a cyclic permutationpof this cyclic list.CyclicIterator<E>cyclicIterator(int index)Returns aCyclicIteratorof the elements in this list (in proper sequence), starting at the specified position in this list.booleanequals(Object obj)Compares the specified object with this cyclic list for equality.booleanequalsCyclic(Object obj)Compares the specified object with this cyclic list for equality.Eget(int index)Returns the element at the specified position in this list.CyclicList<E>getCopy(int len)Returns aCyclicListwhich is by copying this list step by step such that the length of the result islen.intgetIndexOf(int idx, Object obj)Returns the non-negative index in this cyclic list of the first occurrence of the specified element, or-1if this cyclic list does not contain this element.CyclicList<E>getInverse()Returns the inverse of this cyclic list: the list with inverse order.inthashCode()Returns the hash code value for this cyclic list.inthashCodeCyclic()Returns a hash code value for this cyclic list which is invariant under cyclic permutation.booleanisEmpty()Returnstrueiff this list contains no elements.Iterator<E>iterator()ReturnscyclicIterator(index)for some unspecifiedindex.Eremove(int index)Removes the element at the specified position in this list (optional operation).booleanremove(Object obj)booleanremoveAll(Collection<?> coll)voidreplace(int index, Iterator<E> iter)Replaces the element at the specified position in this list with the cyclic list of the specified iterator (optional operation).voidreplace(int index, List<E> list)Replaces the element at the specified position in this list with the specified list (optional operation).booleanretainAll(Collection<?> coll)Eset(int index, E element)Replaces the element at the specified position in this list with the specified element (optional operation).intshiftIndex(int index)intsize()Returns the number of elements in this list.Object[]toArray()Object[]toArray(int index)Returns an array containing all of the elements in this cyclic list in proper sequence, i.e. in the ordering returned by the iterator given byCyclicList.cyclicIterator(int).<E> E[]toArray(int index, E[] array)Returns an array containing all of the elements in this cyclic list in proper sequence, i.e. in the ordering returned by the iterator given byCyclicList.cyclicIterator(int); the runtime type of the returned array is that of the specified array.<E> E[]toArray(E[] ret)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Field Detail
-
wrapped
private final CyclicList<E> wrapped
-
-
Constructor Detail
-
ImmutableCyclicList
ImmutableCyclicList(CyclicList<E> wrapped)
-
-
Method Detail
-
shiftIndex
public int shiftIndex(int index)
- Specified by:
shiftIndexin interfaceCyclicList<E>
-
size
public int size()
Description copied from interface:CyclicListReturns the number of elements in this list. If this list contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceCyclicList<E>- Returns:
- the number of elements in this list.
-
isEmpty
public boolean isEmpty()
Description copied from interface:CyclicListReturnstrueiff this list contains no elements.- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceCyclicList<E>- Returns:
trueiff this list contains no elements.
-
getInverse
public CyclicList<E> getInverse()
Description copied from interface:CyclicListReturns the inverse of this cyclic list: the list with inverse order.- Specified by:
getInversein interfaceCyclicList<E>- Returns:
- The list with the same entries but inverse order.
-
contains
public boolean contains(Object obj)
Description copied from interface:CyclicListReturnstrueif this list contains the specified element. More formally, returnstrueif and only if this list contains at least one elementesuch that(o==null ? e==null : o.equals(e)).- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceCyclicList<E>- Parameters:
obj- element whose presence in this list is to be tested.- Returns:
trueif this list contains the specified element.
-
containsAll
public boolean containsAll(Collection<?> coll)
- Specified by:
containsAllin interfaceCollection<E>
-
iterator
public Iterator<E> iterator()
Description copied from interface:CyclicListReturnscyclicIterator(index)for some unspecifiedindex.- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceCyclicList<E>- Specified by:
iteratorin interfaceIterable<E>- Returns:
cyclicIterator(index)for some unspecifiedindex.
-
cyclicIterator
public CyclicIterator<E> cyclicIterator(int index)
Description copied from interface:CyclicListReturns aCyclicIteratorof the elements in this list (in proper sequence), starting at the specified position in this list. The specified index indicates the first element that would be returned by an initial call to thenextmethod. An initial call to thepreviousmethod would return the element with the specified index minus one (modulo the length of this cyclic list).- Specified by:
cyclicIteratorin interfaceCyclicList<E>- Parameters:
index- index of first element to be returned from the list iterator (by a call to thenextmethod). This is interpreted modulo the length of this cyclic list. Any index (even negative ones) are valid.- Returns:
- a cyclic iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
-
toArray
public Object[] toArray(int index)
Description copied from interface:CyclicListReturns an array containing all of the elements in this cyclic list in proper sequence, i.e. in the ordering returned by the iterator given byCyclicList.cyclicIterator(int). Modifying the return value does not modify thisCyclicList.- Specified by:
toArrayin interfaceCyclicList<E>- Parameters:
index- index of the element in the cyclic list which comes first in the array returned. This is interpreted modulo the length of this cyclic list. Any index (even negative ones) are valid.- Returns:
- an array containing all of the elements in this list in proper sequence.
-
toArray
public <E> E[] toArray(int index, E[] array)Description copied from interface:CyclicListReturns an array containing all of the elements in this cyclic list in proper sequence, i.e. in the ordering returned by the iterator given byCyclicList.cyclicIterator(int); the runtime type of the returned array is that of the specified array. Modifying the return value does not modify thisCyclicList.- Specified by:
toArrayin interfaceCyclicList<E>- Parameters:
index- index of the element in the cyclic list which comes first in the array returned. This is interpreted modulo the length of this cyclic list. Any index (even negative ones) are valid.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 purpose.- Returns:
- an array containing all of the elements in this list in proper sequence.
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<E>
-
toArray
public <E> E[] toArray(E[] ret)
- Specified by:
toArrayin interfaceCollection<E>
-
asList
public List<E> asList(int index)
Description copied from interface:CyclicListReturns a List containing all of the elements in this cyclic list in proper sequence. Modifying the return value does not modify this CyclicList.- Specified by:
asListin interfaceCyclicList<E>- Parameters:
index- index of the element in the cyclic list which comes first in the List returned. This is interpreted modulo the length of this cyclic list. Any index (even negative ones) are valid.- Returns:
- a list containing all of the elements in this cyclic list in proper sequence.
-
asList
public List<E> asList()
- Specified by:
asListin interfaceCyclicList<E>
-
cycle
public CyclicList<E> cycle(int num)
Description copied from interface:CyclicListReturns a cyclic permutationpof this cyclic list.- Specified by:
cyclein interfaceCyclicList<E>- Parameters:
num- anintvalue.- Returns:
- a cyclic permutation
pof this cyclic list. It satisfiesp.size() == this.size()andp.get(i) == this.get(i+num).
-
clear
public void clear()
Description copied from interface:CyclicListRemoves all of the elements from this list (optional operation). This list will be empty after this call returns (unless it throws an exception).- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceCyclicList<E>
-
equals
public boolean equals(Object obj)
Description copied from interface:CyclicListCompares the specified object with this cyclic list for equality. Returnstrueif and only if the specified object is also a cyclic list, both lists have the same size and all corresponding pairs of elements the two lists are equal. (Two elementse1ande2are equal if(e1==null ? e2==null : e1.equals(e2)).) In other words, two cyclic lists are defined to be equal if they contain the same elements in the same order according to their iterators. This definition ensures that the equals method works properly across different implementations of theCyclicListinterface.- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceCyclicList<E>- Overrides:
equalsin classObject- Parameters:
obj- the object to be compared for equality with this list.- Returns:
trueif the specified object is equal to this list.- See Also:
CyclicList.equalsCyclic(Object)
-
equalsCyclic
public boolean equalsCyclic(Object obj)
Description copied from interface:CyclicListCompares the specified object with this cyclic list for equality. Returnstrueif and only if the specified object is also a cyclic list, both lists have the same size, and, up to a cyclic permutation, all corresponding pairs of elements the two lists are equal. (Two elementse1ande2are equal if(e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order up to a cyclic permutation. This definition ensures that the equals method works properly across different implementations of theCyclicListinterface.- Specified by:
equalsCyclicin interfaceCyclicList<E>- Parameters:
obj- the object to be compared for equality with this list.- Returns:
trueif the specified object is equal to this list.- See Also:
CyclicList.equals(Object)
-
hashCode
public int hashCode()
Description copied from interface:CyclicListReturns the hash code value for this cyclic list. The hash code of a list is defined to be the result of the following calculation:hashCode = 1; Iterator i = list.iterator(); while (i.hasNext()) { Object obj = i.next(); hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode()); }This ensures thatlist1.equals(list2)implies thatlist1.hashCode()==list2.hashCode()for any two lists,list1andlist2, as required by the general contract ofObject.hashCode.- Specified by:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceCyclicList<E>- Overrides:
hashCodein classObject- Returns:
- the hash code value for this list.
- See Also:
CyclicList.equals(Object),CyclicList.hashCodeCyclic()
-
hashCodeCyclic
public int hashCodeCyclic()
Description copied from interface:CyclicListReturns a hash code value for this cyclic list which is invariant under cyclic permutation. This kind of hash code is conform withCyclicList.equalsCyclic(Object)and withCyclicList.equals(Object), i.e. equals objects have equal hash codes. The hash code of this cyclic list is the hash code of the underlying set. This ensures thatlist1.equalsCyclic(list2)implies thatlist1.hashCodeCyclic()==list2.hashCodeCyclic()for any two listslist1andlist2.- Specified by:
hashCodeCyclicin interfaceCyclicList<E>- Returns:
- the "cyclic hash code" value for this list.
- See Also:
CyclicList.hashCode(),CyclicList.equalsCyclic(Object)
-
get
public E get(int index)
Description copied from interface:CyclicListReturns the element at the specified position in this list.- Specified by:
getin interfaceCyclicList<E>- Parameters:
index- index of element to return. This is interpreted modulo the length of this cyclic list. Any index (even negative ones) are valid.- Returns:
- the element at the specified position in this list.
-
set
public E set(int index, E element)
Description copied from interface:CyclicListReplaces the element at the specified position in this list with the specified element (optional operation).- Specified by:
setin interfaceCyclicList<E>- Parameters:
index- index of element to replace.element- element to be stored at the specified position. This is interpreted modulo the length of this cyclic list. Any index (even negative ones) are valid.- Returns:
- the element previously at the specified position.
-
replace
public void replace(int index, Iterator<E> iter)Description copied from interface:CyclicListReplaces the element at the specified position in this list with the cyclic list of the specified iterator (optional operation). Places the elements of that list as returned byiter.nextin this list.- Specified by:
replacein interfaceCyclicList<E>- Parameters:
index- index of element to replace.iter- aCyclicIteratorwhich determines an index in a list which replacesthis.get(i).- See Also:
CyclicList.replace(int, List)
-
replace
public void replace(int index, List<E> list)Description copied from interface:CyclicListReplaces the element at the specified position in this list with the specified list (optional operation). Places the elements of that list as returned byiter.nextin this list.- Specified by:
replacein interfaceCyclicList<E>- Parameters:
index- index of element to replace.list- aListwhich determines an index in a list which replacesthis.get(i).- See Also:
CyclicList.replace(int, Iterator)
-
add
public boolean add(E element)
- Specified by:
addin interfaceCollection<E>
-
add
public void add(int index, E element)Description copied from interface:CyclicListInserts the specified element at the specified position in this list (optional operation). Contract:list.add(i,o);return list.get(i)yieldso. In contrast toCyclicList.set(int, E), the element currently at the specified position is not lost.- Specified by:
addin interfaceCyclicList<E>- Parameters:
index- index at which the specified element is to be inserted. This is interpreted modulo the length of this cyclic list plus one (The list emerging after the insertion). In contrast toList.add(int,Object)any index (even a negative one) is valid.element- element to be inserted.
-
addAll
public void addAll(int index, Iterator<E> iter)Description copied from interface:CyclicListInserts the cyclic list of the specified iterator at the specified position in this list (optional operation). In contrast toCyclicList.replace(int, Iterator), the element currently at the specified position is not lost.- Specified by:
addAllin interfaceCyclicList<E>- Parameters:
index- index at which the specified list is to be inserted. This is interpreted modulo the length of this cyclic list. Any index (even negative ones) are valid.iter- element to be inserted. *****- See Also:
CyclicList.addAll(int, List)
-
addAll
public void addAll(int index, List<? extends E> list)Description copied from interface:CyclicListInserts the specified list at the given position in this cyclic list (optional operation). In contrast toCyclicList.replace(int, Iterator), the element currently at the specified position is not lost.- Specified by:
addAllin interfaceCyclicList<E>- Parameters:
index- index at which the specified list is to be inserted. This is interpreted modulo the length of this cyclic list. Any index (even negative ones) are valid.list- the list to be inserted.- See Also:
CyclicList.addAll(int, Iterator)
-
addAll
public boolean addAll(Collection<? extends E> coll)
- Specified by:
addAllin interfaceCollection<E>
-
remove
public E remove(int index) throws EmptyCyclicListException
Description copied from interface:CyclicListRemoves the element at the specified position in this list (optional operation). Returns the element that was removed from the list.- Specified by:
removein interfaceCyclicList<E>- Parameters:
index- the index of the element to removed. This is interpreted modulo the length of this cyclic list. Any index (even negative ones) are valid.- Returns:
- the element previously at the specified position.
- Throws:
EmptyCyclicListException- if this list is empty.
-
remove
public boolean remove(Object obj)
- Specified by:
removein interfaceCollection<E>
-
removeAll
public boolean removeAll(Collection<?> coll)
- Specified by:
removeAllin interfaceCollection<E>
-
retainAll
public boolean retainAll(Collection<?> coll)
- Specified by:
retainAllin interfaceCollection<E>
-
getIndexOf
public int getIndexOf(int idx, Object obj)Description copied from interface:CyclicListReturns the non-negative index in this cyclic list of the first occurrence of the specified element, or-1if this cyclic list does not contain this element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or some negative index if there is no such index.Note that this specification slightly differs from
List.indexOf(Object).- Specified by:
getIndexOfin interfaceCyclicList<E>- Parameters:
idx- the index to start search with. Independently of this, the search comprises all entries of this cyclic list.obj- element to search for ornull.- Returns:
- the index in this cyclic list
of the first occurrence of the specified
element, or
-1if this list does not contain this element.
-
getCopy
public CyclicList<E> getCopy(int len)
Description copied from interface:CyclicListReturns aCyclicListwhich is by copying this list step by step such that the length of the result islen. For examplelen == size()*nyields an n-fold copy of this cyclic list.- Specified by:
getCopyin interfaceCyclicList<E>- Parameters:
len- a non-negativeintvalue.- Returns:
- a
CyclicListwhich is by copying this list step by step such that the length of the result is as specified.
-
-