package com.github.qrokodial.sparkle.utilities.collections;

public class ArrayUtils {
    /**
     * Checks to see if an array contains any specified elements.
     *
     * @param haystack
     * @param needles
     * @return true if a match was found, false otherwise
     */
    public static boolean contains(Object[] haystack, Object... needles) {
        for (Object element : haystack) {
            for (Object needle : needles) {
                if (element.equals(needle)) {
                    return true;
                }
            }
        }

        return false;
    }

    /**
     * Gets the classes backing the array.
     *
     * @param objects
     * @return the class array
     */
    public static Class[] getTypes(Object... objects) {
        Class[] types = new Class[objects.length];

        for (int i = 0; i < objects.length; i++) {
            types[i] = objects[i].getClass();
        }

        return types;
    }
}

@@ -54,16 +54,141 @@
 tions;%0A%0A
+import com.github.qrokodial.sparkle.utilities.casting.SafeCast;%0A%0Aimport java.lang.reflect.Array;%0Aimport java.util.Optional;%0A%0A
 public c
@@ -1071,11 +1071,702 @@
 s;%0A    %7D
+%0A%0A    /**%0A     * Attempts to cast an array to a given type.%0A     *%0A     * @param type%0A     * @param objects%0A     * @param %3CT%3E%0A     * @return the optional-wrapped version of the casted array, if the cast was successful%0A     */%0A    public static %3CT%3E Optional%3CT%5B%5D%3E cast(Class%3CT%3E type, Object... objects) %7B%0A        T%5B%5D casted = (T%5B%5D)Array.newInstance(type, objects.length);%0A        for (int i = 0; i %3C objects.length; i++) %7B%0A            Optional%3CT%3E cast = SafeCast.toType(objects%5Bi%5D, type);%0A%0A            if (cast.isPresent()) %7B%0A                casted%5Bi%5D = cast.get();%0A            %7D else %7B%0A                return Optional.empty();%0A            %7D%0A        %7D%0A        return Optional.of(casted);%0A    %7D
 %0A%7D%0A

Add ArrayUtils#cast