public final class IndexRangeNegative extends Object
Negative indices, loop around the end of the range.
Constructor and Description |
---|
IndexRangeNegative(int startIndex,
int endIndex)
Create with a start and end index.
|
Modifier and Type | Method and Description |
---|---|
int |
correctedEndIndex(int size)
The end-index, maybe corrected so that it is no longer negative.
|
int |
correctedStartIndex(int size)
The start-index, maybe corrected so that it is no longer negative.
|
boolean |
equals(Object o) |
<T> List<T> |
extract(int numberElements,
java.util.function.IntFunction<T> extractIndex)
Extracts a subset of elements from a collection according to the specified index/range.
|
<T> List<T> |
extract(List<T> list)
Extracts a subset of elements from a list according to the specified index/range.
|
int |
getEndIndex()
The index if the last element to use in the subsetting range, inclusive.
|
int |
getStartIndex()
The index if the first element to use in the subsetting range, zero-indexed.
|
int |
hashCode() |
String |
toString() |
public IndexRangeNegative(int startIndex, int endIndex) throws OperationFailedException
startIndex
- the start-index (which can be negative).endIndex
- the end-index (which can be negative).OperationFailedException
- if the indices are incorrectly ordered.public <T> List<T> extract(List<T> list) throws OperationFailedException
T
- type of element in the listlist
- the list to extract a subset fromlist
corresponding to the index/range.OperationFailedException
- if an index lies outside the range (-listSize,
listSize)
or startIndex>=endIndex
.public <T> List<T> extract(int numberElements, java.util.function.IntFunction<T> extractIndex) throws OperationFailedException
Collection is any generic structure, with a fixed number of elements, that can be accessed
via extractIndex
.
T
- type of element in the listnumberElements
- the number of elements in the collection.extractIndex
- extracts an element at a particular index from the collection.
Zero-indexed.OperationFailedException
- if an index lies outside the range (-numberElements,
numberElements)
or startIndex>=endIndex
.public int correctedStartIndex(int size) throws OperationFailedException
size
- the total number of elementsOperationFailedException
- if startIndex
is invalid for a list of size size
.public int correctedEndIndex(int size) throws OperationFailedException
size
- the total number of elementsOperationFailedException
- if endIndex
is invalid for a list of size size
.public int getStartIndex()
This can be negative, in which case it goes backwards from the end of the string e.g.
index -2 is the same as size(elements) - 2
.
public int getEndIndex()
This can be negative, in which case it goes backwards from the end of the string e.g.
index -2 is the same as size(elements) - 2
.
Therefore, -1 will use the final element as the last element.
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.