Package org.jgroups.util
Class FastArray<T>
- java.lang.Object
-
- org.jgroups.util.FastArray<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.List<T>
public class FastArray<T> extends java.lang.Object implements java.lang.Iterable<T>, java.util.List<T>
Simpleunsynchronized
array. The array can only grow, but never shrinks (no arraycopy()). Elements are removed by nulling them. A size variable is maintained for quick size() / isEmpty().- Since:
- 5.2
- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
FastArray.FastIterator
class
FastArray.FastListIterator
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int idx, T el)
boolean
add(T el)
boolean
add(T el, boolean resize)
boolean
addAll(int idx, java.util.Collection<? extends T> c)
boolean
addAll(java.util.Collection<? extends T> list)
boolean
addAll(FastArray<T> fa)
boolean
addAll(FastArray<T> fa, boolean resize)
boolean
addAll(T... els)
boolean
addAll(T[] els, int length)
Adds elements from an array els to this arrayboolean
anyMatch(java.util.function.Predicate<T> pred)
int
capacity()
protected int
checkIndex(int idx)
void
clear()
FastArray<T>
clear(boolean null_elements)
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
int
count()
Returns the number of non-null elements, should have the same result as size().boolean
equals(java.lang.Object obj)
protected boolean
equalsArrayList(FastArray<?> other)
protected boolean
equalsRange(java.util.List<?> other, int from, int to)
T
get(int idx)
int
increment()
FastArray<T>
increment(int i)
int
index()
int
indexOf(java.lang.Object o)
boolean
isEmpty()
FastArray.FastIterator
iterator()
Iterator which iterates only over non-null elements, skipping null elementsFastArray.FastIterator
iterator(java.util.function.Predicate<T> filter)
Iterates over all non-null elements which match filterint
lastIndexOf(java.lang.Object o)
java.util.ListIterator<T>
listIterator()
java.util.ListIterator<T>
listIterator(int index)
java.lang.String
print()
protected java.lang.String
print(int limit)
int
printLimit()
FastArray<T>
printLimit(int l)
T
remove(int idx)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
T
removeFirst()
Removes the first non-null element starting at index 0FastArray<T>
removeIf(java.util.function.Predicate<T> filter, boolean replace_all)
T
removeLast()
FastArray<T>
replaceIf(java.util.function.Predicate<T> filter, T new_el, boolean replace_all)
Replaces any or all elements matching filter with a new elementFastArray<T>
resize(int new_capacity)
boolean
retainAll(java.util.Collection<?> c)
T
set(int idx, T el)
FastArray<T>
set(T[] elements)
int
size()
java.util.stream.Stream<T>
stream()
java.util.List<T>
subList(int fromIndex, int toIndex)
java.lang.Object[]
toArray()
<T1> T1[]
toArray(T1[] a)
java.lang.String
toString()
int
transferFrom(FastArray<T> other, boolean clear)
Copies the messages from the other array into this one,FastArray<T>
trimTo(int new_capacity)
Attempts to reduce the current capacity to new_capacity
-
-
-
Field Detail
-
elements
protected T[] elements
-
index
protected int index
-
size
protected int size
-
increment
protected int increment
-
print_limit
protected int print_limit
-
-
Method Detail
-
capacity
public int capacity()
-
index
public int index()
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
increment
public int increment()
-
printLimit
public int printLimit()
-
add
public boolean add(T el)
-
add
public boolean add(T el, boolean resize)
-
addAll
public boolean addAll(T[] els, int length)
Adds elements from an array els to this array- Parameters:
els
- The other array, can have null elementslength
- The number of elements to add. must be <= els.length- Returns:
- The number of elements added
-
addAll
@SafeVarargs public final boolean addAll(T... els)
-
addAll
public boolean addAll(java.util.Collection<? extends T> list)
-
addAll
public boolean addAll(int idx, java.util.Collection<? extends T> c)
- Specified by:
addAll
in interfacejava.util.List<T>
-
transferFrom
public int transferFrom(FastArray<T> other, boolean clear)
Copies the messages from the other array into this one,including
null elements (usingSystem.arraycopy(Object, int, Object, int, int)
. This is the same as callingclear(boolean)
followed byaddAll(FastArray, boolean)
, but faster.- Parameters:
other
- The other arrayclear
- Clears the other array after the transfer when true- Returns:
- The number of non-null elements transferred from other
-
contains
public boolean contains(java.lang.Object o)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
equals
public boolean equals(java.lang.Object obj)
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOf
in interfacejava.util.List<T>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOf
in interfacejava.util.List<T>
-
anyMatch
public boolean anyMatch(java.util.function.Predicate<T> pred)
-
remove
public boolean remove(java.lang.Object o)
-
removeFirst
public T removeFirst()
Removes the first non-null element starting at index 0
-
removeLast
public T removeLast()
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
replaceIf
public FastArray<T> replaceIf(java.util.function.Predicate<T> filter, T new_el, boolean replace_all)
Replaces any or all elements matching filter with a new element- Parameters:
filter
- The filter, must ne non-null or no replacements will take placenew_el
- The new element, can be nullreplace_all
- When false, the method returns after the first match (if any). Otherwise, all matching elements are replaced
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
clear
public void clear()
-
trimTo
public FastArray<T> trimTo(int new_capacity)
Attempts to reduce the current capacity to new_capacity- Parameters:
new_capacity
- The new capacity. If greater than the current capacity, this will be a no-op. If smaller than the current size, the current size will be taken instead as new capacity.- Returns:
-
iterator
public FastArray.FastIterator iterator()
Iterator which iterates only over non-null elements, skipping null elements
-
iterator
public FastArray.FastIterator iterator(java.util.function.Predicate<T> filter)
Iterates over all non-null elements which match filter
-
stream
public java.util.stream.Stream<T> stream()
- Specified by:
stream
in interfacejava.util.Collection<T>
-
listIterator
public java.util.ListIterator<T> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<T>
-
listIterator
public java.util.ListIterator<T> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<T>
-
subList
public java.util.List<T> subList(int fromIndex, int toIndex)
- Specified by:
subList
in interfacejava.util.List<T>
-
toArray
public java.lang.Object[] toArray()
-
toArray
public <T1> T1[] toArray(T1[] a)
-
count
public int count()
Returns the number of non-null elements, should have the same result as size(). Only used for testing!
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
print
public java.lang.String print()
-
equalsArrayList
protected boolean equalsArrayList(FastArray<?> other)
-
equalsRange
protected boolean equalsRange(java.util.List<?> other, int from, int to)
-
print
protected java.lang.String print(int limit)
-
checkIndex
protected int checkIndex(int idx)
-
-