public interface MutableIndexable<T> extends Indexable<T>
Modifier and Type | Interface and Description |
---|---|
static class |
MutableIndexable.Base<TT>
Abstract base class which provides useful implementations
for
Object.equals(Object) , Object.hashCode() ,
Object.toString() . |
static class |
MutableIndexable.ListView<T>
Helper class for viewing a mutable indexable as a standard list.
|
Indexable.IndexableSpliterator<TElem>
Modifier and Type | Field and Description |
---|---|
static MutableIndexable<java.lang.Object> |
EMPTY
Empty mutable indexable.
|
EMPTY_INDEXABLE_STRING
Modifier and Type | Method and Description |
---|---|
default void |
applyOnEach(java.util.function.Function<? super T,? extends T> operator)
Apply the given operator on each element.
|
default java.util.List<T> |
asList()
View this indexable as a standard list.
|
static <E,IN> MutableIndexable<E> |
copy(java.util.Collection<IN> collection,
java.util.function.Function<IN,E> copier)
Create a mutable indexable which is initialized from copied elements of
a given collection.
|
default void |
copyInternally(int fromIndex,
int toIndex,
int numElements)
Copy elements inside this indexable.
|
static <E> MutableIndexable<E> |
copyOf(java.util.Collection<E> collection)
Create a mutable indexable which is intialized from a
given collection.
|
static <E> MutableIndexable<E> |
empty()
Get an empty mutable indexable.
|
static <E> MutableIndexable<E> |
filled(int size,
java.util.function.IntFunction<? extends E> provider)
Deprecated.
inconsistently named, use
initByIndex(int, IntFunction) instead |
default void |
fillFrom(java.util.function.IntFunction<? extends T> provider)
Fill this indexable from a provider.
|
static <E> MutableIndexable<E> |
fromArray(E... elements)
Create a mutable indexable which is initialized from elements
of the given array.
|
static <E> MutableIndexable<E> |
fromArray(E[] elements,
int startIndex,
int length)
Create a mutable indexable which is initialized from elements
of the given array.
|
static <E,B> MutableIndexable<E> |
fromIndexable(Indexable<B> indexable,
java.util.function.Function<B,E> converter)
Create a mutable indexable which is the copy of a standard indexable.
|
static <E> MutableIndexable<E> |
fromIndexable(Indexable<E> indexable)
Create a mutable indexable which is the copy of a standard indexable.
|
static <E> MutableIndexable<E> |
fromIterable(int size,
java.lang.Iterable<E> iter)
Create a mutable indexable from an iterable or a part of it.
|
default MutableIndexable<T> |
getCopy()
Get a flat copy of this mutable indexable.
|
default MutableIndexable<T> |
getCopy(java.util.function.Function<? super T,? extends T> elementCloner)
Get a copy of this object, allowing to define a copy method for the elements.
|
default MutableIndexable<T> |
headSet(int toIndex)
Create an indexable subset from the last elements of this indexable set.
|
static <E> MutableIndexable<E> |
init(int size,
java.util.function.Supplier<E> creator)
Initialize a mutable indexable to a given size.
|
static <E> MutableIndexable<E> |
initByIndex(int size,
java.util.function.IntFunction<? extends E> producer)
Create a mutable indexable of a given size, and initialize its elements by index.
|
static <E,X extends java.lang.Exception> |
initFragile(int size,
FragileFunction0<E,X> creator)
Initialize a mutable indexable to a given size while allowing exceptions.
|
default java.util.ListIterator<T> |
listIterator()
Overridden to allow setting via the returned iterator.
|
static <E> MutableIndexable<E> |
nulled(int size)
Get a mutable indexable of a given size filled with
null values. |
default void |
order(Ordering<? super T> ordering)
Order the elements in this indexable by the given ordering.
|
default MutableIndexable<T> |
reverse()
Get this indexable but with inverted order.
|
default void |
revert()
Revert the elements in this indexable.
|
default void |
revert(int from,
int to)
Revert the order of all elements in the given range.
|
void |
set(int index,
T elem)
Set the element at the given index.
|
default int |
setFrom(java.lang.Iterable<? extends T> iterable)
Set the elements of this mutable indexable one after
the other from the given iterable until either the
iterable is emptied or
Sizeable.size() elements are set. |
default int |
setFrom(java.lang.Iterable<? extends T> iterable,
int startIndex,
int numElements)
Set the elements of this mutable indexable one after
the other from the given iterable until either the
iterable is emptied or
numElements elements are set. |
default void |
setFromArray(T[] array,
int arrayIndex,
int startIndex,
int numElements)
Set consecutive entries from an array.
|
default void |
setMulti(int from,
int len,
T value)
Set multiple elements to the same value.
|
default void |
shuffle(java.util.Random random)
Randomize the content of this mutable indexable.
|
default MutableIndexable<T> |
subSet(int fromIndex,
int toIndex)
Get an indexable subset.
|
default void |
swap(int idx1,
int idx2)
Swap the values at two indices.
|
default void |
swyp(int idx1,
int idx2)
Swap the values at two indices using Pythonesque indices.
|
default MutableIndexable<T> |
sybSet(int fromIndex,
int toIndex)
Get an indexable subset.
|
default void |
syt(int index,
T elem)
Pythonesque set.
|
default MutableIndexable<T> |
tailSet(int fromIndex)
Create an indexable subset from the last elements of this indexable set.
|
static <E> MutableIndexable<E> |
viewArray(E... array)
Mutable indexable view which operates on the given array.
|
static <E> MutableIndexable<E> |
viewArray(E[] array,
int start,
int len)
View a slice of an array.
|
static <IT,OT> MutableIndexable.Base<OT> |
viewIndexable(Indexable<IT> indexable,
java.util.function.Function<? super IT,OT> getter,
java.util.function.BiConsumer<? super IT,? super OT> setter)
View a generic indexable as a mutable indexable by accessing
a property of the elements of the underlying generic indexable.
|
static <E> MutableIndexable<E> |
viewList(java.util.List<E> list)
Mutable indexable view which operates on the given array.
|
addToArray, addToArray, addToCollection, asBase, asCollection, binarySearch, checkIndex, combine, compare, downCast, emptyIndexable, equal, findAll, findAllX, findFirst, findFirst, findFirst, findFirstX, findLast, findLast, findLast, findNext, findNext, findNext, findNextX, findPrevious, findPrevious, findPrevious, first, firstMatch, firstMatch, firstMatchX, forEachEntry, forEachEntryFragile, fromCollection, fromCollection, fromCountable, fromCountable, fromEnumeration, fromEnumeration, fromIterable, fromIterable, fromIterable, fromIterable, fromIterator, fromList, fromOptional, frozenSpliterator, get, getMod, gyt, hash, indexedView, indexes, init, initByIndex, intIndexes, isEmpty, isOrdered, isStrictlyOrdered, iterator, iterator, last, mapArray, optional, ordered, rotated, singleton, spliterator, toString, view, view, viewAsBooleanIndexable, viewAsByteIndexable, viewAsCharIndexable, viewAsDoubleIndexable, viewAsFloatIndexable, viewAsIntIndexable, viewAsLongIndexable, viewAsShortIndexable, viewByIndex, viewFragile, viewList, viewList, viewListN, viewListN, viewTuple, viewTuple, viewTuple, viewTuple, viewTuple, viewTuple, viewTuple, viewTuple, withAppendedItem, withCachedHash, withExchangedItemAt, withInsertedItemAt, withRemovedItemAt, withSwappedItemsAt
addAllTo, combined, combined, containsEq, containsRef, downCast, equal, equals, filtered, filteredToIndexable, filterToCountable, firstOrNull, foldLeft, forEachFragile, freeze, frozen, frozen, groupingBy, groupingBy, hasAll, hasAny, isSorted, isStrictlySorted, lastOrNull, mappingBy, mappingBy, optFirst, optLast, orderedCombination, sorted, toArray, toArray, toList, toString, uniform, viewCollection, viewCollection, viewCollectionN, viewCollectionN
static final MutableIndexable<java.lang.Object> EMPTY
empty()
instead.void set(int index, T elem)
index
- index between 0
and size() - 1
elem
- element to put to the given indexdefault void syt(int index, T elem)
-1
references the last element, -2
its predecessor, and so on.index
- index between -size()
and size() - 1
elem
- element to put to the given indexdefault int setFrom(@NotNull java.lang.Iterable<? extends T> iterable)
Sizeable.size()
elements are set.iterable
- iterable from which this indexable is filleddefault int setFrom(@NotNull java.lang.Iterable<? extends T> iterable, int startIndex, int numElements)
numElements
elements are set.iterable
- iterable from which this indexable is filledstartIndex
- start index where the setting beginsnumElements
- number of elements to setdefault void setFromArray(@NotNull T[] array, int arrayIndex, int startIndex, int numElements)
array
- array with elements to set fromarrayIndex
- start index in the arraystartIndex
- start index in this mutable indexablenumElements
- number of elements to copyjava.lang.IndexOutOfBoundsException
- if this mutable indexable would overflow by this operationjava.lang.ArrayIndexOutOfBoundsException
- if array overflows by this operationdefault void setMulti(int from, int len, T value)
from
- first index to be set (Pythonesque)len
- number of elements to be set (non-negative)value
- value to be setdefault void copyInternally(int fromIndex, int toIndex, int numElements)
fromIndex
- start index from where elements are copied (Pythonesque)toIndex
- start index to where elements are copied (Pythonesque)numElements
- number of elements to copydefault void fillFrom(@NotNull java.util.function.IntFunction<? extends T> provider)
provider
- provider which is called for each index and provides the element for that indexdefault void swap(int idx1, int idx2)
idx1
- first indexidx2
- second indexdefault void swyp(int idx1, int idx2)
idx1
- first index (Pythonesque
)idx2
- second index (Pythonesque
)@NotNull default MutableIndexable<T> subSet(int fromIndex, int toIndex)
Indexable
fromIndex
to toIndex - 1
.@NotNull default MutableIndexable<T> sybSet(int fromIndex, int toIndex)
Indexable
@NotNull default MutableIndexable<T> tailSet(int fromIndex)
Indexable
@NotNull default MutableIndexable<T> headSet(int toIndex)
Indexable
@NotNull default java.util.ListIterator<T> listIterator()
listIterator
in interface Indexable<T>
setting
,
but not adding
or deleting
@NotNull default MutableIndexable<T> reverse()
Indexable
default void revert(int from, int to)
to
element is also included in the reversion to allow easy
reversion at the end by using -1
.from
- start element of reversion (Pythonesque), includedto
- end element of reversion (Pythonesque), includeddefault void revert()
default void order(@NotNull Ordering<? super T> ordering)
Indexable.isOrdered(Ordering)
returns true
for the given ordering
.
Introduced by the overhead due to accessing elements via this interface
ordering via this method is some 1% slower than sorting an array
with standard Arrays.sort(Object[], Comparator)
. Sort the array
first, if this is a problem for you.
ordering
- ordering to applydefault void shuffle(@NotNull java.util.Random random)
random
- random number generator@NotNull default java.util.List<T> asList()
List.set(int, Object)
method,
but neither any adding nor deleting methods. Standard sorting algorithms will work
on the returned list as a sorting algorithm is expected to neither add nor delete
elements.asList
in interface Indexable<T>
Countable.toList()
default void applyOnEach(@NotNull java.util.function.Function<? super T,? extends T> operator)
operator
- operator to apply@NotNull default MutableIndexable<T> getCopy()
getCopy(Function)
which allows to define how elements are copied.@NotNull default MutableIndexable<T> getCopy(@Nullable java.util.function.Function<? super T,? extends T> elementCloner)
elementCloner
- function for cloning each element before adding it to the copy,
if null
elements are copied directly, which will couple
this mutable indexable and the returned copy if the elemtns are mutable:
when an element is changed this is reflected in both.@NotNull static <E> MutableIndexable<E> init(int size, @NotNull java.util.function.Supplier<E> creator)
E
- element typesize
- size of indexablecreator
- creator for the initial elements, called in order for each element@NotNull static <E,X extends java.lang.Exception> MutableIndexable<E> initFragile(int size, @NotNull FragileFunction0<E,X> creator) throws X extends java.lang.Exception
E
- element typeX
- exception typesize
- size of indexablecreator
- creator for the initial elements, called in order for each element, may throw an exceptionX
- if creator
throwsX extends java.lang.Exception
@NotNull static <E> MutableIndexable<E> initByIndex(int size, @NotNull java.util.function.IntFunction<? extends E> producer)
E
- element typesize
- size of returned indexableproducer
- element producer which will be called for each index@NotNull @Deprecated static <E> MutableIndexable<E> filled(int size, @NotNull java.util.function.IntFunction<? extends E> provider)
initByIndex(int, IntFunction)
insteadE
- element typesize
- size of returned indexableprovider
- provider called for each index to set the element at that index@NotNull static <E> MutableIndexable<E> nulled(int size)
null
values.E
- element type of the returned indexablesize
- size of the returned indexablenull
@NotNull static <E> MutableIndexable<E> copyOf(@NotNull java.util.Collection<E> collection)
E
- list and result element typecollection
- collection@NotNull static <E,IN> MutableIndexable<E> copy(@NotNull java.util.Collection<IN> collection, @NotNull java.util.function.Function<IN,E> copier)
E
- result element typeIN
- incoming element typecollection
- collectioncopier
- element copier@NotNull static <E> MutableIndexable<E> empty()
@SafeVarargs @NotNull static <E> MutableIndexable<E> fromArray(@NotNull E... elements)
@NotNull static <E> MutableIndexable<E> fromArray(@NotNull E[] elements, int startIndex, int length)
E
- element typeelements
- array of elementsstartIndex
- index of first element used in the returned indxablelength
- length number of elements used in the returned indexableeleements
@NotNull @SafeVarargs static <E> MutableIndexable<E> viewArray(@NotNull E... array)
@NotNull static <E> MutableIndexable<E> viewArray(@NotNull E[] array, int start, int len)
viewArray
in interface Countable<T>
viewArray
in interface Indexable<T>
E
- array typearray
- array to viewstart
- start of array slice represented by the returned indexablelen
- length of array slice represented by the returned indexableMutableIndexable.viewArray(array).subset(start, start + len)
@NotNull static <E> MutableIndexable<E> viewList(@NotNull java.util.List<E> list)
E
- element typelist
- list@NotNull static <E> MutableIndexable<E> fromIndexable(@NotNull Indexable<E> indexable)
E
- element typeindexable
- standard indexable@NotNull static <E,B> MutableIndexable<E> fromIndexable(@NotNull Indexable<B> indexable, @NotNull java.util.function.Function<B,E> converter)
E
- element type of returned mutable indexableB
- element type of incoming idexableindexable
- base indexableconverter
- converter from base indexable type to result element type,@NotNull static <IT,OT> MutableIndexable.Base<OT> viewIndexable(@NotNull Indexable<IT> indexable, @NotNull java.util.function.Function<? super IT,OT> getter, @NotNull java.util.function.BiConsumer<? super IT,? super OT> setter)
This is useful if you have complex items, but are interested into only one property of each item.
IT
- element type of the underlying indexableOT
- element type of the returned indexableindexable
- underlying generic indexablegetter
- function used to extract the property of interestsetter
- procedure used to set the property of interest@NotNull static <E> MutableIndexable<E> fromIterable(int size, @NotNull java.lang.Iterable<E> iter)
E
- element typesize
- maximum size of returned indexableiter
- iterable used for initializing the indexable