Package com.jcabi.immutable
Class Array<T>
- java.lang.Object
-
- com.jcabi.immutable.Array<T>
-
- Type Parameters:
T
- Value key type
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,List<T>
@Immutable @Loggable(1) public final class Array<T> extends Object implements List<T>
Array as an object.This class is truly immutable. This means that it never changes its encapsulated values and is annotated with
@Immutable
annotation.Limitation: Encapsulated objects with exposed mutators can mutate their state.
- Since:
- 0.1
- Suppressed Checkstyle violations:
- MissingDeprecatedCheck (430 lines)
-
-
Constructor Summary
Constructors Constructor Description Array()
Public ctor, for an zero-length empty array.Array(Array<T> array)
Public ctor, from a generic array.Array(Iterable<T> list)
Public ctor.Array(Collection<T> collection)
Public ctor, from a generic collection.Array(T... list)
Public ctor, from an array of values.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(int index, T element)
Deprecated.boolean
add(T element)
Deprecated.boolean
addAll(int index, Collection<? extends T> col)
Deprecated.boolean
addAll(Collection<? extends T> col)
Deprecated.void
clear()
Deprecated.boolean
contains(Object key)
boolean
containsAll(Collection<?> col)
boolean
equals(Object object)
T
get(int index)
int
hashCode()
int
indexOf(Object obj)
boolean
isEmpty()
Iterator<T>
iterator()
int
lastIndexOf(Object obj)
ListIterator<T>
listIterator()
ListIterator<T>
listIterator(int index)
T
remove(int index)
Deprecated.boolean
remove(Object obj)
Deprecated.boolean
removeAll(Collection<?> col)
Deprecated.boolean
retainAll(Collection<?> col)
Deprecated.T
set(int index, T element)
Deprecated.int
size()
List<T>
subList(int from, int till)
Object[]
toArray()
<T> T[]
toArray(T[] array)
String
toString()
Array<T>
with(int pos, T value)
Make a new one with an extra entry at the given position.Array<T>
with(Iterable<T> vals)
Make a new extra entries, at the end of array.Array<T>
with(Collection<T> vals)
Make a new extra entries, at the end of array.Array<T>
with(T value)
Make a new one with an extra entry, at the end of array (will be extended by one extra element).Array<T>
without(T item)
Make a new array, without this element (or the same array if such an element is absent).Array<T>
withoutIndex(int idx)
Make a new array, without element on specific index.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
-
-
-
Constructor Detail
-
Array
public Array()
Public ctor, for an zero-length empty array.
-
Array
public Array(T... list)
Public ctor, from an array of values.- Parameters:
list
- Items to encapsulate
-
Array
public Array(Iterable<T> list)
Public ctor.- Parameters:
list
- Items to encapsulate- Since:
- 0.12
-
Array
public Array(Array<T> array)
Public ctor, from a generic array.- Parameters:
array
- Array with items to encapsulate
-
Array
public Array(Collection<T> collection)
Public ctor, from a generic collection.- Parameters:
collection
- Collection with items to encapsulate
-
-
Method Detail
-
with
public Array<T> with(T value)
Make a new one with an extra entry, at the end of array (will be extended by one extra element).- Parameters:
value
- The value- Returns:
- New vector
-
with
public Array<T> with(Collection<T> vals)
Make a new extra entries, at the end of array.- Parameters:
vals
- The values- Returns:
- New vector
-
with
public Array<T> with(Iterable<T> vals)
Make a new extra entries, at the end of array.- Parameters:
vals
- The values- Returns:
- New vector
-
with
public Array<T> with(int pos, T value)
Make a new one with an extra entry at the given position.- Parameters:
pos
- Position to replacevalue
- The value- Returns:
- New array
-
withoutIndex
public Array<T> withoutIndex(int idx)
Make a new array, without element on specific index.The method throws
ArrayIndexOutOfBoundsException
if such position is absent in the array.- Parameters:
idx
- The position to remove- Returns:
- New array
-
without
public Array<T> without(T item)
Make a new array, without this element (or the same array if such an element is absent).- Parameters:
item
- The element to remove- Returns:
- New array
- Since:
- 1.4
-
hashCode
public int hashCode()
-
equals
public boolean equals(Object object)
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(Object key)
-
toArray
public Object[] toArray()
-
toArray
public <T> T[] toArray(T[] array)
-
add
@Deprecated public boolean add(T element)
Deprecated.
-
remove
@Deprecated public boolean remove(Object obj)
Deprecated.
-
containsAll
public boolean containsAll(Collection<?> col)
- Specified by:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceList<T>
-
addAll
@Deprecated public boolean addAll(Collection<? extends T> col)
Deprecated.
-
retainAll
@Deprecated public boolean retainAll(Collection<?> col)
Deprecated.
-
removeAll
@Deprecated public boolean removeAll(Collection<?> col)
Deprecated.
-
clear
@Deprecated public void clear()
Deprecated.
-
addAll
@Deprecated public boolean addAll(int index, Collection<? extends T> col)
Deprecated.
-
set
@Deprecated public T set(int index, T element)
Deprecated.
-
add
@Deprecated public void add(int index, T element)
Deprecated.
-
remove
@Deprecated public T remove(int index)
Deprecated.
-
lastIndexOf
public int lastIndexOf(Object obj)
- Specified by:
lastIndexOf
in interfaceList<T>
-
listIterator
public ListIterator<T> listIterator()
- Specified by:
listIterator
in interfaceList<T>
-
listIterator
public ListIterator<T> listIterator(int index)
- Specified by:
listIterator
in interfaceList<T>
-
-