类 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
  • 构造器详细资料

  • 方法详细资料

    • set

      @SafeVarargs public final void set(@Nullable E... array)
    • sort

      public void sort()
    • sort

      public void sort(Comparator<E> comparator)
    • add

      @SafeVarargs public final void add(E... array)
    • addAll

      public void addAll(Collection<E> list)
      add list at end of the array
      参数:
      list - list to add
      抛出:
      NullPointerException - input list is null
    • set

      public void set(@Nullable Collection<E> list)
    • get

      @Nullable public E[] get()
      指定者:
      get 在接口中 Supplier<E>
    • iterator

      public Iterator<E> iterator()
      指定者:
      iterator 在接口中 Iterable<E>
    • ifPresent

      public void ifPresent(Consumer<E[]> action)
      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 is null
      另请参阅:
    • ifPresentOrElse

      public void ifPresentOrElse(Consumer<E[]> action, Runnable emptyAction)
      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 present
      emptyAction - the empty-based action to be performed, if no value is present
      抛出:
      NullPointerException - if array is present and the given action is null, or no value is present and the given empty-based action is null.
      另请参阅:
    • map

      @Nullable public <U> U map(Function<? super E[],? extends U> mapper)
      类型参数:
      U - The type of the value returned from the mapping function
      参数:
      mapper - the mapping function to apply to a value, if present
      返回:
      an U describing the result of applying a mapping function to the value of this array, if a value is present, otherwise null
      抛出:
      NullPointerException - if the mapping function is null
    • 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 present
      emptySupplier - the supplier to be used if no value is present
      返回:
      an U describing the result of applying a mapping function to the value of this array, if a value is present, otherwise null
      抛出:
      NullPointerException - if the mapping function is null
    • stream

      public Stream<E> stream()
      If array is present, returns a sequential Stream containing only that value, otherwise returns an empty Stream.
      返回:
      the optional value as a Stream
      另请参阅:
    • orElse

      public E[] orElse(E[] other)
      If array is present, returns the value, otherwise returns other.
      参数:
      other - the value to be returned, if no value is present. May be null.
      返回:
      the value, if present, otherwise other
      另请参阅:
    • orElseGet

      public E[] orElseGet(Supplier<E[]> supplier)
      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 is null
      另请参阅:
    • orElseThrow

      public E[] orElseThrow()
      If array is present, returns the value, otherwise throws NoSuchElementException.
      返回:
      the non-null value described by this Optional
      抛出:
      NoSuchElementException - if no value is present
      另请参阅:
    • getOptional

      public Optional<E[]> getOptional()
    • getRequired

      public E[] getRequired()
    • getRequired

      public E[] getRequired(String message)
      If array is null, returns the value, otherwise throws IllegalStateException
      抛出:
      IllegalStateException - if array is null
    • orElseThrow

      public <X extends Throwable> E[] orElseThrow(Supplier<? extends X> exceptionSupplier) throws X
      If array is present, returns the value, otherwise throws an exception produced by the exception supplying function.
      类型参数:
      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 present
      NullPointerException - if no value is present and the exception supplying function is null
      另请参阅:
    • isPresent

      public boolean isPresent()
      If array is non-null and non-empty , returns true, otherwise false.
      返回:
      true if array is present, otherwise false
    • isEmpty

      public boolean isEmpty()
      If array is null or empty , returns true, otherwise false.
      返回:
      true if array is not present, otherwise false
    • clear

      public void clear()
      set array to null
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • equals

      public boolean equals(Object o)
      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • valueOf

      @SafeVarargs public static <E> ArrayHolder<E> valueOf(E... array)
    • valueOf

      public static <E> ArrayHolder<E> valueOf(List<E> list)
    • copyOf

      public static <E> ArrayHolder<E> copyOf(ArrayHolder<E> holder)
    • forClass

      public static <E> ArrayHolder<E> forClass(@Nullable Class<E> elementClass)
      另请参阅:
    • forGenerator

      public static <E> ArrayHolder<E> forGenerator(@Nullable IntFunction<E[]> arrayGenerator)
      另请参阅: