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 classFastArray.FastIteratorclassFastArray.FastListIterator
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int idx, T el)booleanadd(T el)booleanadd(T el, boolean resize)booleanaddAll(int idx, java.util.Collection<? extends T> c)booleanaddAll(java.util.Collection<? extends T> list)booleanaddAll(FastArray<T> fa)booleanaddAll(FastArray<T> fa, boolean resize)booleanaddAll(T... els)booleanaddAll(T[] els, int length)Adds elements from an array els to this arraybooleananyMatch(java.util.function.Predicate<T> pred)intcapacity()protected intcheckIndex(int idx)voidclear()FastArray<T>clear(boolean null_elements)booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)intcount()Returns the number of non-null elements, should have the same result as size().booleanequals(java.lang.Object obj)protected booleanequalsArrayList(FastArray<?> other)protected booleanequalsRange(java.util.List<?> other, int from, int to)Tget(int idx)intincrement()FastArray<T>increment(int i)intindex()intindexOf(java.lang.Object o)booleanisEmpty()FastArray.FastIteratoriterator()Iterator which iterates only over non-null elements, skipping null elementsFastArray.FastIteratoriterator(java.util.function.Predicate<T> filter)Iterates over all non-null elements which match filterintlastIndexOf(java.lang.Object o)java.util.ListIterator<T>listIterator()java.util.ListIterator<T>listIterator(int index)java.lang.Stringprint()protected java.lang.Stringprint(int limit)intprintLimit()FastArray<T>printLimit(int l)Tremove(int idx)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)TremoveFirst()Removes the first non-null element starting at index 0FastArray<T>removeIf(java.util.function.Predicate<T> filter, boolean replace_all)TremoveLast()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)booleanretainAll(java.util.Collection<?> c)Tset(int idx, T el)FastArray<T>set(T[] elements)intsize()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.StringtoString()inttransferFrom(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:
addAllin 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:
indexOfin interfacejava.util.List<T>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOfin 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:
streamin interfacejava.util.Collection<T>
-
listIterator
public java.util.ListIterator<T> listIterator()
- Specified by:
listIteratorin interfacejava.util.List<T>
-
listIterator
public java.util.ListIterator<T> listIterator(int index)
- Specified by:
listIteratorin interfacejava.util.List<T>
-
subList
public java.util.List<T> subList(int fromIndex, int toIndex)
- Specified by:
subListin 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:
toStringin 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)
-
-