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

com.WazaBe.HoloEverywhere.util.Arrays Maven / Gradle / Ivy

The newest version!
package com.WazaBe.HoloEverywhere.util;

import java.lang.reflect.Array;

public class Arrays {
	@SuppressWarnings("unchecked")
	public static  T[] copyOfRange(T[] original, int from, int to) {
		return Arrays.copyOfRange(original, from, to,
				(Class) original.getClass());
	}

	@SuppressWarnings("unchecked")
	public static  T[] copyOfRange(U[] original, int from, int to,
			Class newType) {
		int newSize = to - from;
		if (newSize < 0) {
			throw new IllegalArgumentException(from + " > " + to);
		}
		T[] copy = (Object) newType == (Object) Object[].class ? (T[]) new Object[newSize]
				: (T[]) Array.newInstance(newType.getComponentType(), newSize);
		System.arraycopy(original, from, copy, 0,
				Math.min(original.length - from, newSize));
		return copy;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy