Class UniqueArray<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>
com.portingdeadmods.portingdeadlibs.utils.UniqueArray<E>
- Type Parameters:
E- the type of elements in this collection
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,List<E>,RandomAccess,SequencedCollection<E>,Set<E>
A collection that maintains unique elements (like a Set) while providing
indexed access (like an ArrayList).
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty UniqueArray.UniqueArray(int initialCapacity) Creates a UniqueArray with the specified initial capacity.UniqueArray(Collection<? extends E> c) Creates a UniqueArray containing the elements of the specified collection. -
Method Summary
Modifier and TypeMethodDescriptionvoidInserts the specified element at the specified position in this UniqueArray if it is not already present.booleanAppends the specified element to the end of this UniqueArray if it is not already present.booleanaddAll(int index, Collection<? extends E> c) Inserts all of the elements in the specified collection into this UniqueArray at the specified position, if they're not already present.final booleanAdds all of the elements in the specified varargs to this UniqueArray if they're not already present.booleanaddAll(Collection<? extends E> c) Adds all of the elements in the specified collection to this UniqueArray if they're not already present.static <T> com.mojang.serialization.Codec<UniqueArray<T>> CODEC(com.mojang.serialization.Codec<T> elementCodec) Returns a Codec for serializing and deserializing UniqueArray instancesReplaces the element at the specified position in this UniqueArray with the specified element if it's not already present elsewhere in the array.static <B extends io.netty.buffer.ByteBuf,T>
net.minecraft.network.codec.StreamCodec<B, UniqueArray<T>> STREAM_CODEC(net.minecraft.network.codec.StreamCodec<B, T> elementStreamCodec) Returns a StreamCodec for serializing and deserializing UniqueArray instances using a ByteBuf.Object[]toArray()Returns an array containing all of the elements in this UniqueArray in proper sequence (from first to last element).<T> T[]toArray(T[] a) Returns an array containing all of the elements in this UniqueArray in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.toList()toSet()Methods inherited from class java.util.ArrayList
addFirst, addLast, clear, clone, contains, ensureCapacity, equals, forEach, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeIf, removeLast, removeRange, replaceAll, retainAll, size, sort, spliterator, subList, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
containsAll, reversed
-
Constructor Details
-
UniqueArray
public UniqueArray()Creates an empty UniqueArray. -
UniqueArray
Creates a UniqueArray containing the elements of the specified collection. Duplicate elements are only added once.- Parameters:
c- the collection whose elements are to be added to this UniqueArray
-
UniqueArray
public UniqueArray(int initialCapacity) Creates a UniqueArray with the specified initial capacity.- Parameters:
initialCapacity- the initial capacity of the UniqueArray- Throws:
IllegalArgumentException- if the specified initial capacity is negative
-
-
Method Details
-
add
Appends the specified element to the end of this UniqueArray if it is not already present. -
add
Inserts the specified element at the specified position in this UniqueArray if it is not already present. -
addAll
Adds all of the elements in the specified collection to this UniqueArray if they're not already present.- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceList<E>- Specified by:
addAllin interfaceSet<E>- Overrides:
addAllin classArrayList<E>- Parameters:
c- collection containing elements to be added to this UniqueArray- Returns:
- true if this UniqueArray changed as a result of the call
-
addAll
Adds all of the elements in the specified varargs to this UniqueArray if they're not already present.- Parameters:
c- elements to be added to this UniqueArray- Returns:
- true if this UniqueArray changed as a result of the call
-
addAll
Inserts all of the elements in the specified collection into this UniqueArray at the specified position, if they're not already present.- Specified by:
addAllin interfaceList<E>- Overrides:
addAllin classArrayList<E>- Parameters:
index- index at which to insert the first elementc- collection containing elements to be added to this UniqueArray- Returns:
- true if this UniqueArray changed as a result of the call
- Throws:
IndexOutOfBoundsException- if the index is out of range
-
set
Replaces the element at the specified position in this UniqueArray with the specified element if it's not already present elsewhere in the array.- Specified by:
setin interfaceList<E>- Overrides:
setin classArrayList<E>- Parameters:
index- index of the element to replaceelement- element to be stored at the specified position- Returns:
- the element previously at the specified position
- Throws:
IndexOutOfBoundsException- if the index is out of range
-
toArray
Returns an array containing all of the elements in this UniqueArray in proper sequence (from first to last element). -
toArray
public <T> T[] toArray(T[] a) Returns an array containing all of the elements in this UniqueArray in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classArrayList<E>- Parameters:
a- the array into which the elements of this UniqueArray are to be stored- Returns:
- an array containing the elements of this UniqueArray
- Throws:
ArrayStoreException- if the runtime type of the specified array is not a supertype of the runtime type of every element in this UniqueArrayNullPointerException- if the specified array is null
-
toList
-
toSet
-
CODEC
public static <T> com.mojang.serialization.Codec<UniqueArray<T>> CODEC(com.mojang.serialization.Codec<T> elementCodec) Returns a Codec for serializing and deserializing UniqueArray instances- Type Parameters:
T- The type of elements in the UniqueArray- Parameters:
elementCodec- The Codec for the elements of the array
-
STREAM_CODEC
public static <B extends io.netty.buffer.ByteBuf,T> net.minecraft.network.codec.StreamCodec<B,UniqueArray<T>> STREAM_CODEC(net.minecraft.network.codec.StreamCodec<B, T> elementStreamCodec) Returns a StreamCodec for serializing and deserializing UniqueArray instances using a ByteBuf.- Type Parameters:
B- The type of ByteBuf used for serializationT- The type of elements inthe UniqueArray- Parameters:
elementStreamCodec- The StreamCodec for the elements of the array
-