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

com.absmartly.sdk.internal.Algorithm Maven / Gradle / Ivy

There is a newer version: 1.6.3
Show newest version
package com.absmartly.sdk.internal;

import java.util.Set;
import java8.util.function.Function;

public class Algorithm {
	public static  R[] mapSetToArray(Set set, R[] array, Function mapper) {
		final int size = set.size();
		if (array.length < size) {
			array = (R[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), size);
		}

		if (array.length > size) {
			array[size] = null;
		}

		int index = 0;
		for (final T value : set) {
			array[index++] = mapper.apply(value);
		}
		return array;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy