类 ColUtils
java.lang.Object
committee.nova.mods.avaritia.api.util.java.ColUtils
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> booleanReturns true if all elements in the provided Iterable match the given predicate.static <T> booleanReturns true if all elements in the provided array match the given predicate.static <T> booleanReturns true if any element in the provided Iterable matches the given predicate.static voidBasically a wrapper for System.arraycopy with support for Copyable'sstatic <T> booleancontains(T[] input, T element) Checks if an array contains any of the specified element.static <T> booleancontainsKeys(Map<T, ?> map, T... keys) Checks if a map contains all keys passed in.static <T> intCounts elements in the array that conform to the Function check.static <T> intcountNonNull(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> voidFills the array with the specified value.static <T> Optional<T>Finds the first element in the Iterable that matches the given predicate.static <T> TAsserts theIterableis not empty and returns the first element.static <T> Optional<T>headOption(Iterable<T> col) Attempts to get the first element of the Iterable.static <T> TheadOrDefault(Iterable<T> col) Returns the first element in theIterableotherwisenull.static <T> TheadOrDefault(Iterable<T> col, T _default) Returns the first element in theIterableotherwise the supplied default.static <T> intindexOf(T[] array, T object) Returns the index of the first occurrence of the specified element in the array.static <T> intindexOfRef(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> booleanisEmpty(T[] array) Checks if the array is all null.static <T> booleanisNullOrContainsNull(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>已过时。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> TmaxBy(Iterable<T> col, ToIntFunction<T> func) 已过时。static <T> TmaxBy(T[] col, ToIntFunction<T> func) Returns the element in the array with the highest value returned by the supplied function.static <T> TmaxByOrDefault(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[]Creates a new array form its component class.static <T> TAssert theIterablecontains a single element, and return it.static <T> T已过时。static <T> TonlyOrDefault(Iterable<T> iterable) Returns the first element found in theIterableif it's the first and only element in the iterable, otherwisenullis returned.static <T> TonlyOrDefault(Iterable<T> iterable, T _default) Returns the first element found in theIterableif it's the first and only element in the iterable, otherwise the default value is returned.static <T> TonlyOrDefault(Stream<T> stream) 已过时。static <T> TonlyOrDefault(Stream<T> stream, T _default) 已过时。static <E> Stream<E>parallelStream(Iterable<E> iter) 已过时。static <T> TrequireMaxBy(Iterable<T> col, ToIntFunction<T> func) Returns the element in the Iterable with the highest value returned by the supplied function.static <T> voidreverse(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>已过时。static <T> TAsserts theIterableis not empty and returns the last element.static <T> Optional<T>tailOption(Iterable<T> col) Attempts to get the last element of the Iterable.static <T> TtailOrDefault(Iterable<T> col) Returns the last element in theIterableotherwisenull.static <T> TtailOrDefault(Iterable<T> col, T _default) Returns the last element in theIterableotherwise the supplied default.toList(int[] arr) Convert an int array to a list of Integers.
-
构造器详细资料
-
ColUtils
public ColUtils()
-
-
方法详细资料
-
slice
public static <T> T[] slice(T[] arr, int from, int until) -
maxBy
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
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
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
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
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
Finds the first element in the Iterable that matches the given predicate.- 参数:
col- The collection.func- The predicate.- 返回:
- The Optional result.
-
headOption
Attempts to get the first element of the Iterable.- 参数:
col- The collection.- 返回:
- The optional result.
-
head
Asserts theIterableis not empty and returns the first element.- 参数:
col- TheIterable.- 返回:
- The first element.
- 抛出:
IllegalArgumentException- If theIterableis empty.
-
headOrDefault
Returns the first element in theIterableotherwisenull.- 参数:
col- TheIterable.- 返回:
- 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 theIterableotherwise the supplied default. -
tailOption
Attempts to get the last element of the Iterable.- 参数:
col- The collection.- 返回:
- The optional result.
-
tail
Asserts theIterableis not empty and returns the last element.- 参数:
col- TheIterable.- 返回:
- The last element.
- 抛出:
IllegalArgumentException- If theIterableis empty.
-
tailOrDefault
Returns the last element in theIterableotherwisenull.- 参数:
col- TheIterable.- 返回:
- 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 theIterableotherwise the supplied default. -
containsKeys
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
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
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
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
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
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 inputelement- 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
Convert an int array to a list of Integers.- 参数:
arr- in.- 返回:
- out.
-
iterable
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
Returns the first element found in theIterableif it's the first and only element in the iterable, otherwisenullis returned.- 参数:
iterable- TheIterable.- 返回:
- 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 theIterableif it's the first and only element in the iterable, otherwise the default value is returned.- 参数:
iterable- TheIterable._default- The default value, in the event the iterable is empty, or has more than one element.- 返回:
- The first element or the default.
-
only
已过时。Assert the stream contains a single element, and return it.- 参数:
stream- The stream.- 返回:
- The element.
- 抛出:
IllegalArgumentException- If theStreamcontains no or more than one element.
-
only
Assert theIterablecontains a single element, and return it.- 参数:
col- The iterable.- 返回:
- The element.
- 抛出:
IllegalArgumentException- If theIterablecontains no or more than one element.
-
iterator
Return an iterator for an array.- 参数:
arr- The array.- 返回:
- The
Iterator.
-
iterator
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.
-