类 ArrayHolder<E>
java.lang.Object
cn.taketoday.util.ArrayHolder<E>
- 所有已实现的接口:
Iterable<E>,Supplier<E[]>,RandomAccess
public final class ArrayHolder<E>
extends Object
implements Supplier<E[]>, Iterable<E>, RandomAccess
It is used for the scenario of changing less and reading more frequently.
- 从以下版本开始:
- 4.0 2022/1/12 15:28
- 作者:
- Harry Yang
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidvoidfinal voidvoidaddAll(Collection<E> list) add list at end of the arrayvoidclear()set array tonullstatic <E> ArrayHolder<E>copyOf(ArrayHolder<E> holder) booleanstatic <E> ArrayHolder<E>static <E> ArrayHolder<E>forGenerator(IntFunction<E[]> arrayGenerator) E[]get()E[]E[]getRequired(String message) If array isnull, returns the value, otherwise throwsIllegalStateExceptioninthashCode()voidIf array is present, performs the given action with the value, otherwise does nothing.voidifPresentOrElse(Consumer<E[]> action, Runnable emptyAction) If array is present, performs the given action with the value, otherwise performs the given empty-based action.booleanisEmpty()If array is null or empty , returnstrue, otherwisefalse.booleanIf array is non-null and non-empty , returnstrue, otherwisefalse.iterator()<U> U<U> UE[]If array is present, returns the value, otherwise returnsother.E[]If array is present, returns the value, otherwise returns the result produced by the supplying function.E[]If array is present, returns the value, otherwise throwsNoSuchElementException.orElseThrow(Supplier<? extends X> exceptionSupplier) If array is present, returns the value, otherwise throws an exception produced by the exception supplying function.voidfinal voidvoidset(Collection<E> list) intsize()voidsort()voidsort(Comparator<E> comparator) stream()If array is present, returns a sequentialStreamcontaining only that value, otherwise returns an emptyStream.toString()static <E> ArrayHolder<E>valueOf(E... array) static <E> ArrayHolder<E>从接口继承的方法 java.lang.Iterable
forEach, spliterator
-
字段详细资料
-
array
-
elementClass
-
arrayGenerator
-
-
构造器详细资料
-
ArrayHolder
public ArrayHolder() -
ArrayHolder
-
-
方法详细资料
-
set
-
sort
public void sort() -
sort
-
add
- 参数:
element- element to add- 抛出:
NullPointerException- element is null
-
add
-
set
-
add
-
addAll
add list at end of the array- 参数:
list- list to add- 抛出:
NullPointerException- input list is null
-
set
-
get
-
iterator
-
ifPresent
If array is present, performs the given action with the value, otherwise does nothing.- 参数:
action- the action to be performed, if array is present- 抛出:
NullPointerException- if value is present and the given action isnull- 另请参阅:
-
ifPresentOrElse
If array is present, performs the given action with the value, otherwise performs the given empty-based action.- 参数:
action- the action to be performed, if array is presentemptyAction- the empty-based action to be performed, if no value is present- 抛出:
NullPointerException- if array is present and the given action isnull, or no value is present and the given empty-based action isnull.- 另请参阅:
-
map
- 类型参数:
U- The type of the value returned from the mapping function- 参数:
mapper- the mapping function to apply to a value, if present- 返回:
- an
Udescribing the result of applying a mapping function to the value of thisarray, if a value is present, otherwisenull - 抛出:
NullPointerException- if the mapping function isnull
-
map
@Nullable public <U> U map(Function<? super E[], ? extends U> mapper, @Nullable Supplier<U> emptySupplier) - 类型参数:
U- The type of the value returned from the mapping function- 参数:
mapper- the mapping function to apply to a value, if presentemptySupplier- the supplier to be used if no value is present- 返回:
- an
Udescribing the result of applying a mapping function to the value of thisarray, if a value is present, otherwisenull - 抛出:
NullPointerException- if the mapping function isnull
-
stream
If array is present, returns a sequentialStreamcontaining only that value, otherwise returns an emptyStream.This method can be used to transform a
Streamof optional elements to aStreamof present value elements:Stream<Optional<T>> os = .. Stream<T> s = os.flatMap(ArrayHolder::stream)- 返回:
- the optional value as a
Stream - 另请参阅:
-
orElse
If array is present, returns the value, otherwise returnsother.- 参数:
other- the value to be returned, if no value is present. May benull.- 返回:
- the value, if present, otherwise
other - 另请参阅:
-
orElseGet
If array is present, returns the value, otherwise returns the result produced by the supplying function.- 参数:
supplier- the supplying function that produces array to be returned- 返回:
- the value, if present, otherwise the result produced by the supplying function
- 抛出:
NullPointerException- if no value is present and the supplying function isnull- 另请参阅:
-
orElseThrow
If array is present, returns the value, otherwise throwsNoSuchElementException.- 返回:
- the non-
nullvalue described by thisOptional - 抛出:
NoSuchElementException- if no value is present- 另请参阅:
-
getOptional
-
getRequired
-
getRequired
If array isnull, returns the value, otherwise throwsIllegalStateException- 抛出:
IllegalStateException- if array isnull
-
orElseThrow
If array is present, returns the value, otherwise throws an exception produced by the exception supplying function.A method reference to the exception constructor with an empty argument list can be used as the supplier. For example,
IllegalStateException::new- 类型参数:
X- Type of the exception to be thrown- 参数:
exceptionSupplier- the supplying function that produces an exception to be thrown- 返回:
- the value, if present
- 抛出:
X- if no value is presentNullPointerException- if no value is present and the exception supplying function isnull- 另请参阅:
-
isPresent
public boolean isPresent()If array is non-null and non-empty , returnstrue, otherwisefalse.- 返回:
trueif array is present, otherwisefalse
-
isEmpty
public boolean isEmpty()If array is null or empty , returnstrue, otherwisefalse.- 返回:
trueif array is not present, otherwisefalse
-
size
public int size() -
clear
public void clear()set array tonull -
toString
-
equals
-
hashCode
public int hashCode() -
valueOf
-
valueOf
-
copyOf
-
forClass
- 另请参阅:
-
forGenerator
- 另请参阅:
-