package jcf_set.example;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

public class InteriRipetuti {
	
	public static void main(String[] Args) {
		new InteriRipetuti().run();
	}
	
	public void run() {
		int N = 20;
		int MAX_INT = 50;
		
		// HASHSET (non ordinato)
		Set<Integer> hashset = new HashSet<Integer>();
		
		// Genero i numeri casuali inserendoli in nel set di hashset
		Random generator = new Random();
		for (int i = 0; i < N; i++) {
			Integer x = generator.nextInt(MAX_INT + 1);
			if (!hashset.add(x)) {
				System.out.println("[NON INSERITO] Causa: Intero ripetuto: " + x);
			} else System.out.println("Intero inserito: " + x);
		}
		
		// Stampa di hashset
		System.out.println("Hashset");
		for (Integer x : hashset) System.out.println(x + " ");
		System.out.println(); System.out.println(hashset);
		
		// TREESET (ordinato)
		Set<Integer> treeset = new TreeSet<Integer>(hashset);
		
		// Stampa di treeset
		System.out.println("Treeset");
		for (Integer x : treeset) System.out.println(x + " ");
		System.out.println(); System.out.println(treeset);
	}
	
}
