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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classFastArray.FastIterator
-
Constructor Summary
Constructors Constructor Description FastArray(int capacity)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intadd(java.util.Collection<T> list)intadd(FastArray<T> fa)intadd(FastArray<T> fa, boolean resize)intadd(T el)intadd(T... els)intadd(T[] els, int length)Adds elements from an array els to this arrayintadd(T el, boolean resize)booleananyMatch(java.util.function.Predicate<T> pred)intcapacity()FastArray<T>clear(boolean null_elements)intcount()Returns the number of non-null elements, should have the same result as size().protected static intensurePositive(int i)Tget(int idx)intincrement()FastArray<T>increment(int i)intindex()booleanisEmpty()FastArray.FastIteratoriterator()Iterator which iterates only over non-null elements, skipping null elementsFastArray.FastIteratoriteratorWithFilter(java.util.function.Predicate<T> filter)Iterates over all non-null elements which match filterjava.lang.Stringprint()protected java.lang.Stringprint(int limit)intprintLimit()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)intsize()java.util.stream.Stream<T>stream()java.lang.StringtoString()inttransferFrom(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:
iteratorin interfacejava.lang.Iterable<T>
-
iteratorWithFilter
public FastArray.FastIterator iteratorWithFilter(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:
toStringin classjava.lang.Object
-
print
public java.lang.String print()
-
print
protected java.lang.String print(int limit)
-
ensurePositive
protected static int ensurePositive(int i)
-
-