java.lang.Object
committee.nova.mods.avaritia.api.util.java.ColUtils

public class ColUtils extends Object
ColUtils
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static <T> List<T>
    addAllNoNull(T[] array, List<T> list)
    Adds all elements from the array that are not null to the list.
    static <T> T[]
    addToArrayFirstNull(T[] array, T value)
    Adds the value at the first null index in the array.
    static <T> boolean
    allMatch(Iterable<T> col, Predicate<T> func)
    Returns true if all elements in the provided Iterable match the given predicate.
    static <T> boolean
    allMatch(T[] col, Predicate<T> func)
    Returns true if all elements in the provided array match the given predicate.
    static <T> boolean
    anyMatch(Iterable<T> col, Predicate<T> func)
    Returns true if any element in the provided Iterable matches the given predicate.
    static void
    arrayCopy(Object src, int srcPos, Object dst, int destPos, int length)
    Basically a wrapper for System.arraycopy with support for Copyable's
    static <T> boolean
    contains(T[] input, T element)
    Checks if an array contains any of the specified element.
    static <T> boolean
    containsKeys(Map<T,?> map, T... keys)
    Checks if a map contains all keys passed in.
    static <T> int
    count(T[] array, Function<T,Boolean> check)
    Counts elements in the array that conform to the Function check.
    static <T> int
    countNonNull(T[] array)
    Counts the elements in the array that are not null.
    static <T> T[]
    createNewArray(T[] array)
    Create a new array using the provided array as a template for both type and length.
    static <T> T[]
    createNewArray(T[] array, int length)
    Create a new array using the provided array as a template for the type and with the provided length.
    static <T> T[]
    fill(T[] array, T value)
    Fills the array with the specified value.
    static <T> void
    fillArray(T[] array, T value, Function<T,Boolean> check)
    Fills the array with the specified value.
    static <T> Optional<T>
    findFirst(Iterable<T> col, Predicate<T> func)
    Finds the first element in the Iterable that matches the given predicate.
    static <T> T
    head(Iterable<T> col)
    Asserts the Iterable is not empty and returns the first element.
    static <T> Optional<T>
    Attempts to get the first element of the Iterable.
    static <T> T
    Returns the first element in the Iterable otherwise null.
    static <T> T
    headOrDefault(Iterable<T> col, T _default)
    Returns the first element in the Iterable otherwise the supplied default.
    static <T> int
    indexOf(T[] array, T object)
    Returns the index of the first occurrence of the specified element in the array.
    static <T> int
    indexOfRef(T[] array, T object)
    Returns the index of the first occurrence of the specified element in the array with the same identity.
    static <T> T[]
    inverse(T[] input, T[] allElements)
    Creates the inverse of an array.
    static <T> boolean
    isEmpty(T[] array)
    Checks if the array is all null.
    static <T> boolean
    isNullOrContainsNull(T @Nullable [] input)
    Checks if the specified array is empty or contains a null entry.
    static <E> Iterable<E>
    iterable(Enumeration<E> enumeration)
    Represents this Enumeration as an Iterable.
    static <E> Iterable<E>
    iterable(Stream<E> stream)
    已过时。
    static <T> Iterator<T>
    iterator(T[] arr)
    Return an iterator for an array.
    static <T> Iterator<T>
    iterator(T[] arr, int from, int until)
    Return an iterator for an array slice.
    static <T> T
    maxBy(Iterable<T> col, ToIntFunction<T> func)
    已过时。
    static <T> T
    maxBy(T[] col, ToIntFunction<T> func)
    Returns the element in the array with the highest value returned by the supplied function.
    static <T> T
    maxByOrDefault(Iterable<T> col, ToIntFunction<T> func, T default_)
    Returns the element in the Iterable with the highest value returned by the supplied function.
    static <T> T[]
    newArray(Class<T> arrayClass, int length)
    Creates a new array form its component class.
    static <T> T
    only(Iterable<T> col)
    Assert the Iterable contains a single element, and return it.
    static <T> T
    only(Stream<T> stream)
    已过时。
    static <T> T
    onlyOrDefault(Iterable<T> iterable)
    Returns the first element found in the Iterable if it's the first and only element in the iterable, otherwise null is returned.
    static <T> T
    onlyOrDefault(Iterable<T> iterable, T _default)
    Returns the first element found in the Iterable if it's the first and only element in the iterable, otherwise the default value is returned.
    static <T> T
    onlyOrDefault(Stream<T> stream)
    已过时。
    static <T> T
    onlyOrDefault(Stream<T> stream, T _default)
    已过时。
    static <E> Stream<E>
    已过时。
    static <T> T
    Returns the element in the Iterable with the highest value returned by the supplied function.
    static <T> void
    reverse(T[] array)
    Reverse the provided array.
    static <T> T[]
    rollArray(T[] input, int shift)
    Rolls the array based on the shift.
    static <T> T[]
    slice(T[] arr, int from, int until)
     
    static <E> Stream<E>
    stream(Iterable<E> iter)
    已过时。
    static <T> T
    tail(Iterable<T> col)
    Asserts the Iterable is not empty and returns the last element.
    static <T> Optional<T>
    Attempts to get the last element of the Iterable.
    static <T> T
    Returns the last element in the Iterable otherwise null.
    static <T> T
    tailOrDefault(Iterable<T> col, T _default)
    Returns the last element in the Iterable otherwise the supplied default.
    static List<Integer>
    toList(int[] arr)
    Convert an int array to a list of Integers.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • ColUtils

      public ColUtils()
  • 方法详细资料

    • slice

      public static <T> T[] slice(T[] arr, int from, int until)
    • maxBy

      @Nullable public static <T> T maxBy(T[] col, ToIntFunction<T> func)
      Returns the element in the array with the highest value returned by the supplied function.
      参数:
      col - The array.
      func - The function.
      返回:
      The max element or null.
    • maxBy

      @Nullable @Deprecated @ScheduledForRemoval(inVersion="0.5.0") public static <T> T maxBy(Iterable<T> col, ToIntFunction<T> func)
      已过时。
      Returns the element in the Iterable with the highest value returned by the supplied function.
      参数:
      col - The array.
      func - The function.
      返回:
      The max element or null.
    • requireMaxBy

      public static <T> T requireMaxBy(Iterable<T> col, ToIntFunction<T> func)
      Returns the element in the Iterable with the highest value returned by the supplied function.
      参数:
      col - The collection.
      func - The function.
      返回:
      The max element.
    • maxByOrDefault

      @Nullable @Contract("_,_,!null -> !null") public static <T> T maxByOrDefault(Iterable<T> col, ToIntFunction<T> func, @Nullable T default_)
      Returns the element in the Iterable with the highest value returned by the supplied function.
      参数:
      col - The collection.
      func - The function.
      default_ - The default value to return if the collection is empty.
      返回:
      The max element or the default value.
    • allMatch

      public static <T> boolean allMatch(T[] col, Predicate<T> func)
      Returns true if all elements in the provided array match the given predicate.
      参数:
      col - The collection to match.
      func - The function to apply.
      返回:
      If all elements match.
    • allMatch

      public static <T> boolean allMatch(Iterable<T> col, Predicate<T> func)
      Returns true if all elements in the provided Iterable match the given predicate.
      参数:
      col - The collection to match.
      func - The function to apply.
      返回:
      If all elements match.
    • anyMatch

      public static <T> boolean anyMatch(Iterable<T> col, Predicate<T> func)
      Returns true if any element in the provided Iterable matches the given predicate.
      参数:
      col - The collection to match.
      func - The function to apply.
      返回:
      If any elements match.
    • findFirst

      public static <T> Optional<T> findFirst(Iterable<T> col, Predicate<T> func)
      Finds the first element in the Iterable that matches the given predicate.
      参数:
      col - The collection.
      func - The predicate.
      返回:
      The Optional result.
    • headOption

      public static <T> Optional<T> headOption(Iterable<T> col)
      Attempts to get the first element of the Iterable.
      参数:
      col - The collection.
      返回:
      The optional result.
    • head

      public static <T> T head(Iterable<T> col)
      Asserts the Iterable is not empty and returns the first element.
      参数:
      col - The Iterable.
      返回:
      The first element.
      抛出:
      IllegalArgumentException - If the Iterable is empty.
    • headOrDefault

      @Nullable public static <T> T headOrDefault(Iterable<T> col)
      Returns the first element in the Iterable otherwise null.
      参数:
      col - The Iterable.
      返回:
      The first element, or null.
    • headOrDefault

      @Nullable @Contract("_,!null -> !null") public static <T> T headOrDefault(Iterable<T> col, @Nullable T _default)
      Returns the first element in the Iterable otherwise the supplied default.
      参数:
      col - The Iterable.
      _default - The default if the Iterable is empty.
      返回:
      The first element, or the default.
    • tailOption

      public static <T> Optional<T> tailOption(Iterable<T> col)
      Attempts to get the last element of the Iterable.
      参数:
      col - The collection.
      返回:
      The optional result.
    • tail

      public static <T> T tail(Iterable<T> col)
      Asserts the Iterable is not empty and returns the last element.
      参数:
      col - The Iterable.
      返回:
      The last element.
      抛出:
      IllegalArgumentException - If the Iterable is empty.
    • tailOrDefault

      @Nullable public static <T> T tailOrDefault(Iterable<T> col)
      Returns the last element in the Iterable otherwise null.
      参数:
      col - The Iterable.
      返回:
      The last element, or null.
    • tailOrDefault

      @Nullable @Contract("_,!null -> !null") public static <T> T tailOrDefault(Iterable<T> col, @Nullable T _default)
      Returns the last element in the Iterable otherwise the supplied default.
      参数:
      col - The Iterable.
      _default - The default if the Iterable is empty.
      返回:
      The last element, or the default.
    • containsKeys

      @SafeVarargs public static <T> boolean containsKeys(Map<T,?> map, T... keys)
      Checks if a map contains all keys passed in.
      类型参数:
      T - The type of data in the map key.
      参数:
      map - Map to check.
      keys - Keys that must exist.
      返回:
      False if fail.
    • addToArrayFirstNull

      public static <T> T[] addToArrayFirstNull(T[] array, T value)
      Adds the value at the first null index in the array.
      类型参数:
      T - Type of value.
      参数:
      array - Array to add to.
      value - Value to add.
      返回:
      Returns a new array in the event the input was expanded.
    • addAllNoNull

      public static <T> List<T> addAllNoNull(T[] array, List<T> list)
      Adds all elements from the array that are not null to the list.
      类型参数:
      T - What we are dealing with.
      参数:
      array - Array to grab from.
      list - List to add to.
      返回:
      The modified list.
    • isEmpty

      public static <T> boolean isEmpty(T[] array)
      Checks if the array is all null.
      类型参数:
      T - What we are dealing with.
      参数:
      array - The array to check.
      返回:
      True if the array only contains nulls.
    • countNonNull

      public static <T> int countNonNull(T[] array)
      Counts the elements in the array that are not null.
      类型参数:
      T - What we are dealing with.
      参数:
      array - The array to check.
      返回:
      The count of non-null objects in the array.
    • count

      public static <T> int count(T[] array, Function<T,Boolean> check)
      Counts elements in the array that conform to the Function check.
      类型参数:
      T - What we are dealing with.
      参数:
      array - The array to check.
      check - The Function to apply to each element.
      返回:
      The count.
    • fill

      public static <T> T[] fill(T[] array, T value)
      Fills the array with the specified value. If the value is an instance of Copyable it will call copy.
      类型参数:
      T - What we are dealing with.
      参数:
      array - Array to fill.
      value - Value to fill with.
    • fillArray

      public static <T> void fillArray(T[] array, T value, Function<T,Boolean> check)
      Fills the array with the specified value. A Function is used to check if the value should be replaced. If the value is an instance of Copyable it will call copy.
      类型参数:
      T - What we are dealing with.
      参数:
      array - Array to fill.
      value - Value to fill with.
      check - Called to decide if the value should be replaced.
    • arrayCopy

      public static void arrayCopy(Object src, int srcPos, Object dst, int destPos, int length)
      Basically a wrapper for System.arraycopy with support for Copyable's
      参数:
      src - The source array.
      srcPos - Starting position in the source array.
      dst - The destination array.
      destPos - Starting position in the destination array.
      length - The number of elements to copy.
    • indexOf

      public static <T> int indexOf(T[] array, T object)
      Returns the index of the first occurrence of the specified element in the array. Will return -1 if the element is non existent in the array.
      类型参数:
      T - What we are dealing with.
      参数:
      array - The array to search.
      object - Element to find.
      返回:
      The index in the array of the object.
    • indexOfRef

      public static <T> int indexOfRef(T[] array, T object)
      Returns the index of the first occurrence of the specified element in the array with the same identity. (Ref compare). Will return -1 if the element is non existent in the array.
      参数:
      array - The array to search.
      object - Element to find.
      返回:
      The index in the array of the object.
    • createNewArray

      public static <T> T[] createNewArray(T[] array)
      Create a new array using the provided array as a template for both type and length.
      类型参数:
      T - The type.
      参数:
      array - The template.
      返回:
      The new array.
    • createNewArray

      public static <T> T[] createNewArray(T[] array, int length)
      Create a new array using the provided array as a template for the type and with the provided length.
      类型参数:
      T - The type.
      参数:
      array - The type template.
      length - The new array's length.
      返回:
      The new array.
    • newArray

      public static <T> T[] newArray(Class<T> arrayClass, int length)
      Creates a new array form its component class.
      类型参数:
      T - The thing.
      参数:
      arrayClass - The component class.
      length - The length.
      返回:
      The new array.
    • rollArray

      public static <T> T[] rollArray(T[] input, int shift)
      Rolls the array based on the shift. Positive shift means the array will roll to the right. Negative shift means the array will roll to the left.
      类型参数:
      T - The thing.
      参数:
      input - The input array.
      shift - The shift amount.
      返回:
      The new array.
    • contains

      public static <T> boolean contains(T[] input, T element)
      Checks if an array contains any of the specified element.
      类型参数:
      T - The thing.
      参数:
      input - The input
      element - The thing to test against.
      返回:
      If the element exists at all.
    • inverse

      public static <T> T[] inverse(T[] input, T[] allElements)
      Creates the inverse of an array. If the input array does not contain an element from the allElements array, then it is added to the output.
      类型参数:
      T - The thing.
      参数:
      input - The input.
      allElements - All possible values.
      返回:
      The inverse array.
    • isNullOrContainsNull

      public static <T> boolean isNullOrContainsNull(T @Nullable [] input)
      Checks if the specified array is empty or contains a null entry.
      类型参数:
      T - The thing.
      参数:
      input - The input.
      返回:
      If the array is null or contains null.
    • toList

      public static List<Integer> toList(int[] arr)
      Convert an int array to a list of Integers.
      参数:
      arr - in.
      返回:
      out.
    • iterable

      public static <E> Iterable<E> iterable(Enumeration<E> enumeration)
      Represents this Enumeration as an Iterable.
      参数:
      enumeration - The Enumeration.
      返回:
      The Iterable.
    • iterable

      @Deprecated @ScheduledForRemoval(inVersion="0.5.0") public static <E> Iterable<E> iterable(Stream<E> stream)
      已过时。
      Shorthand for converting a stream to an Iterable.

      It is important to note, that a Stream can only be consumed once, and thus, the returned Iterable can only be consumed once.

      参数:
      stream - The Stream.
      返回:
      The Iterable.
    • stream

      @Deprecated @ScheduledForRemoval(inVersion="0.5.0") public static <E> Stream<E> stream(Iterable<E> iter)
      已过时。
      Shorthand util for streaming an Iterable.
      参数:
      iter - The iterable.
      返回:
      The Stream.
    • parallelStream

      @Deprecated @ScheduledForRemoval(inVersion="0.5.0") public static <E> Stream<E> parallelStream(Iterable<E> iter)
      已过时。
      Shorthand util for streaming an Iterable in parallel.
      参数:
      iter - The iterable.
      返回:
      The Parallel Stream.
    • onlyOrDefault

      @Deprecated @ScheduledForRemoval(inVersion="0.5.0") @Nullable public static <T> T onlyOrDefault(Stream<T> stream)
      已过时。
    • onlyOrDefault

      @Deprecated @ScheduledForRemoval(inVersion="0.5.0") @Nullable @Contract("_,!null -> !null") public static <T> T onlyOrDefault(Stream<T> stream, @Nullable T _default)
      已过时。
      Returns the first element found in the Stream if it is the only element in the stream, otherwise the default value is returned.
      参数:
      stream - The stream.
      _default - The default value, in the event the stream is empty, or has more than one element.
      返回:
      The first element or the default.
    • onlyOrDefault

      @Nullable public static <T> T onlyOrDefault(Iterable<T> iterable)
      Returns the first element found in the Iterable if it's the first and only element in the iterable, otherwise null is returned.
      参数:
      iterable - The Iterable.
      返回:
      The first and only element, or null
    • onlyOrDefault

      @Nullable @Contract("_,!null -> !null") public static <T> T onlyOrDefault(Iterable<T> iterable, @Nullable T _default)
      Returns the first element found in the Iterable if it's the first and only element in the iterable, otherwise the default value is returned.
      参数:
      iterable - The Iterable.
      _default - The default value, in the event the iterable is empty, or has more than one element.
      返回:
      The first element or the default.
    • only

      @Deprecated @ScheduledForRemoval(inVersion="0.5.0") public static <T> T only(Stream<T> stream)
      已过时。
      Assert the stream contains a single element, and return it.
      参数:
      stream - The stream.
      返回:
      The element.
      抛出:
      IllegalArgumentException - If the Stream contains no or more than one element.
    • only

      public static <T> T only(Iterable<T> col)
      Assert the Iterable contains a single element, and return it.
      参数:
      col - The iterable.
      返回:
      The element.
      抛出:
      IllegalArgumentException - If the Iterable contains no or more than one element.
    • iterator

      public static <T> Iterator<T> iterator(T[] arr)
      Return an iterator for an array.
      参数:
      arr - The array.
      返回:
      The Iterator.
    • iterator

      public static <T> Iterator<T> iterator(T[] arr, int from, int until)
      Return an iterator for an array slice.
      参数:
      arr - The array to iterate.
      from - The offset in the array.
      until - The end offset in the array.
      返回:
      The Iterator.
    • reverse

      public static <T> void reverse(T[] array)
      Reverse the provided array.
      参数:
      array - The array to reverse.