All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tomakehurst.wiremock.common.ArrayFunctions Maven / Gradle / Ivy

package com.github.tomakehurst.wiremock.common;

import java.lang.reflect.Array;

import static java.util.Arrays.copyOf;

public final class ArrayFunctions {

    public static  T[] concat(T[] first, T[] second) {
        if (first.length + second.length == 0) {
            return first;
        }
        T[] both = copyOf(first, first.length + second.length);
        System.arraycopy(second, 0, both, first.length, second.length);
        return both;
    }

    public static  T[] prepend(T t, T[] original) {
        @SuppressWarnings("unchecked")
        T[] newArray = (T[]) Array.newInstance(original.getClass().getComponentType(), original.length + 1);
        newArray[0]= t;
        System.arraycopy(original, 0, newArray, 1, original.length);
        return newArray;
    }

    private ArrayFunctions() {
        throw new UnsupportedOperationException("not instantiable");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy