package speiger.src.coreengine.utils.collections;

import java.util.Collection;
import java.util.List;
import java.util.Set;

import speiger.src.collections.ints.maps.impl.hash.Int2ObjectLinkedOpenHashMap;
import speiger.src.collections.ints.maps.impl.hash.Int2ObjectOpenHashMap;
import speiger.src.collections.ints.maps.interfaces.Int2ObjectMap;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.lists.ObjectList;
import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet;
import speiger.src.collections.objects.sets.ObjectOpenHashSet;

public class CollectionUtils {
	public static <T, K extends Collection<T>> K createSubCollection(List<T> list, int[] indecies, K result) {
		for(int i = 0;i < indecies.length;i++) {
			result.add(list.get(indecies[i]));
		}
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> Set<T>[] createSets(int size, boolean linked) {
		Set<T>[] sets = new Set[size];
		for(int i = 0;i < size;i++) {
			sets[i] = linked ? new ObjectLinkedOpenHashSet<T>() : new ObjectOpenHashSet<T>();
		}
		return sets;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> ObjectList<T>[] createList(int size) {
		ObjectList<T>[] list = new ObjectList[size];
		for(int i = 0;i < size;i++) {
			list[i] = new ObjectArrayList<>();
		}
		return list;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> Int2ObjectMap<T>[] createInt2ObjectMap(int size, boolean linked) {
		Int2ObjectMap<T>[] maps = new Int2ObjectMap[size];
		for(int i = 0;i < size;i++) {
			maps[i] = linked ? new Int2ObjectLinkedOpenHashMap<T>() : new Int2ObjectOpenHashMap<T>();
		}
		return maps;
	}
}
