From: Robin Cheney Date: Tue, 25 Nov 2025 13:49:24 +0000 (+0100) Subject: reworked ArrayUtils X-Git-Url: https://git.eternal.ddnss.de/?a=commitdiff_plain;h=1a3e0e4c736bc4be3ee2f3b75738af82aa8c2647;p=utils.git reworked ArrayUtils --- diff --git a/pom.xml b/pom.xml index 8bab3be..3e18f3e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.ddnss.eternal.utils utils - 1.4.0 + 1.4.1 UTF-8 diff --git a/src/main/java/de/ddnss/eternal/utils/ArrayUtils.java b/src/main/java/de/ddnss/eternal/utils/ArrayUtils.java index e9540a4..ce46a25 100644 --- a/src/main/java/de/ddnss/eternal/utils/ArrayUtils.java +++ b/src/main/java/de/ddnss/eternal/utils/ArrayUtils.java @@ -7,18 +7,73 @@ import java.util.ArrayList; * * @author Robin Cheney * - * @since 1.1 + * @since 1.4.1 */ -public abstract class ArrayUtils { - public E[] reverse(E[] array) { +public abstract class ArrayUtils { + + /** + * Reverse and return {@code array} + * + * @apiNote This reassigns the original array that is passed to the function as + * the parameter. If you don't want this, use + * {@link #reversedCopy(Object[])} + * + * @param The class/datatype of the array + * @param array The array to reverse + * @return the reversed array with the same datatype as the original + */ + public static E[] reverse(E[] array) { ArrayList outArray = new ArrayList(); - for (int i = 0; i < array.length; i++) { + for (E i : array) { + // System.out.println(i); + outArray.add(i); + } + + return outArray.reversed().toArray(array); + } + + /** + * Reverse and return a copy of {@code array} + * + * @apiNote If you also want to reverse the original array that was passed as an + * argument, use {@link #reverse(Object[])} + * + * @param The class/datatype of the array + * @param array The array to reverse + * @return the reversed array with the same datatype as the original + */ + public static E[] reversedCopy(E[] array) { + E[] arrayCopy = array.clone(); + + ArrayList outArray = new ArrayList(); - // prepend each character - outArray.add(array[i]); + for (E i : array) { + // System.out.println(i); + outArray.add(i); } - return outArray.toArray(array); + + return outArray.reversed().toArray(arrayCopy); + } + + /** + * Reverse and return an {@code array} + * + * @param The class/datatype of the array + * @param array The array to reverse + * @return the reversed array with the same datatype as the original + * + * @since 1.4.1 + */ + public static ArrayList toArrayList(E[] array) { + + ArrayList outArray = new ArrayList(); + + for (E i : array) { + outArray.add(i); + } + + return outArray; } } diff --git a/src/main/java/de/ddnss/eternal/utils/io/error/InvalidArgumentsError.java b/src/main/java/de/ddnss/eternal/utils/io/error/InvalidArgumentsError.java index 0eb07bb..f5b14c3 100644 --- a/src/main/java/de/ddnss/eternal/utils/io/error/InvalidArgumentsError.java +++ b/src/main/java/de/ddnss/eternal/utils/io/error/InvalidArgumentsError.java @@ -4,8 +4,7 @@ import de.ddnss.eternal.utils.io.input.GenericCommandOption; /** * Thrown when an {@link GenericCommandOption} object does not fit the - * requirements of - * the function it was passed to + * requirements of the function it was passed to * * @author Robin Cheney *