package jcf_set.exercise;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Insiemistica {
	
	public static void main(String[] main) {
		
		// Insiemi di test
		Integer[] aArray = {1, -2, 3, -4, 3};
		Integer[] bArray = {1, 5, -6, -4, 5};
		
		// Input come HashSet (Ordine non garantito)
		Set<Integer> aHashSet = new HashSet<Integer>(Arrays.asList(aArray));
		Set<Integer> bHashSet = new HashSet<Integer>(Arrays.asList(bArray));
		
		
		
	}
	
	// Operazioni di insiemistica
	
	/*
	 * Per eseguire una unione, è conveniente 
	 * adoperare la Set poichè l'implementazione 
	 * TreeSet permette di non mantenere duplicati.
	 */
	public static <T extends Comparable<? super T>> Set<T> union(Set<T> s1, Set<T> s2) {
		Set<T> union = new HashSet<T>();
		union.addAll(s1);
		union.addAll(s2);
		return union;
	}
	
	/*
	 * Per eseguire una intersezione, è conveniente
	 * adoperare la Set allo stesso modo
	 */
	public static <T extends Comparable<? super T>> Set<T> union(Set<T> s1, Set<T> s2) {
		Set<T> intersection = new HashSet<T>();
		intersection.addAll(s1);
		intersection.retainAll(s2);
		return intersection;
	}
	
	/*
	 * Per eseguire la differenza, si usa 
	 * la Set
	 */
	
}
