Class CyclicVector
- All Implemented Interfaces:
Serializable, Cloneable, Iterable<Object>, Collection<Object>, List<Object>, RandomAccess, SequencedCollection<Object>
a 'cyclic vector' that is element[0] succeeds element[nElem-1] where
nElem is size. Provides elements(startIndex) as Enumeration which iterates
through whole of Vector cyclicly. [Normal elements() is inherited from
Vector and starts from element[0]]. This class is not thread-safe. The
vector and its contents can be changed but Enumerations will be
invalidated.
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
- See Also:
-
Field Summary
Fields inherited from class Vector
capacityIncrement, elementCount, elementDataFields inherited from class AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptioncreate with an empty vectorCyclicVector(Vector<?> vector) Creates a new CyclicVector from an existing vector. -
Method Summary
Modifier and TypeMethodDescriptionelements(int startIndex) Creates an Enumeration starting at the specified index.Creates an Enumeration starting with the first element that contains startObject.static voidTest main method for CyclicVector.Methods inherited from class Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, forEach, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, iterator, lastElement, lastIndexOf, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeIf, removeRange, replaceAll, retainAll, set, setElementAt, setSize, size, sort, spliterator, subList, toArray, toArray, toString, trimToSizeMethods inherited from interface Collection
parallelStream, stream, toArrayMethods inherited from interface List
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, reversed
-
Constructor Details
-
CyclicVector
public CyclicVector()create with an empty vector -
CyclicVector
Creates a new CyclicVector from an existing vector.- Parameters:
vector- the vector to copy elements from
-
-
Method Details
-
elements
Creates an Enumeration starting with the first element that contains startObject.- Parameters:
startObject- the object to start the iteration from- Returns:
- a cyclic enumeration of the vector's elements
- Throws:
IllegalArgumentException- if the startObject is not found in the vector
-
elements
Creates an Enumeration starting at the specified index.- Parameters:
startIndex- the index to start the iteration from- Returns:
- a cyclic enumeration of the vector's elements
- Throws:
IllegalArgumentException- if the startIndex is out of bounds
-
main
Test main method for CyclicVector.- Parameters:
args- command line arguments: size and start index
-