Package org.jgroups.util
Class FastArray<T>
- java.lang.Object
-
- org.jgroups.util.FastArray<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>
public class FastArray<T> extends java.lang.Object implements java.lang.Iterable<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
-
Constructor Summary
Constructors Constructor Description FastArray(int capacity)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
add(java.util.Collection<T> list)
int
add(FastArray<T> fa)
int
add(FastArray<T> fa, boolean resize)
int
add(T el)
int
add(T... els)
int
add(T[] els, int length)
Adds elements from an array els to this arrayint
add(T el, boolean resize)
boolean
anyMatch(java.util.function.Predicate<T> pred)
int
capacity()
FastArray<T>
clear(boolean null_elements)
int
count()
Returns the number of non-null elements, should have the same result as size().protected static int
ensurePositive(int i)
T
get(int idx)
int
increment()
FastArray<T>
increment(int i)
int
index()
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 filterjava.lang.String
print()
protected java.lang.String
print(int limit)
int
printLimit()
FastArray<T>
printLimit(int l)
FastArray<T>
remove(int idx)
FastArray<T>
removeIf(java.util.function.Predicate<T> filter, boolean replace_all)
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)
FastArray<T>
set(int idx, T el)
FastArray<T>
set(T[] elements)
int
size()
java.util.stream.Stream<T>
stream()
java.lang.String
toString()
int
transferFrom(FastArray<T> other, boolean clear)
Copies the messages from the other array into this one,
-
-
-
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 int add(T el)
-
add
public int add(T el, boolean resize)
-
add
public int add(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
-
add
@SafeVarargs public final int add(T... els)
-
add
public int add(java.util.Collection<T> list)
-
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 byadd(FastArray, boolean)
, but supposedly 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
-
get
public T get(int idx)
-
anyMatch
public boolean anyMatch(java.util.function.Predicate<T> pred)
-
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
-
iterator
public FastArray.FastIterator iterator()
Iterator which iterates only over non-null elements, skipping null elements- Specified by:
iterator
in interfacejava.lang.Iterable<T>
-
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()
-
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()
-
print
protected java.lang.String print(int limit)
-
ensurePositive
protected static int ensurePositive(int i)
-
-