import java.util.HashMap;
import java.util.Collection;
import java.util.Arrays;

class Mar15 {
	public static void main(String[] args) {

		HashMap<Integer, Foo>  map = new HashMap<>();

		Foo f1 = new Foo(3, 3.0f, "b");
		Foo f2 = new Foo(1, 1.0f, "c");
		Foo f3 = new Foo(2, 2.0f, "a");

		map.put(f1.getID(), f1);
		map.put(f2.getID(), f2);
		map.put(f3.getID(), f3);

		System.out.println(map);

		// sort and print

		Collection<Foo> col = map.values();
	
		for(Foo f : col) {
			System.out.println(f);
		}
	
		Foo[] arr = col.toArray(new Foo[0]);

		for(Foo f : arr) {
			System.out.println(f);
		}
	
		Arrays.sort(arr);

		for(Foo f : arr) {
			System.out.println(f);
		}

		// check if map has key

		System.out.println("contains 2: " + map.containsKey(2));
		System.out.println("contains 4: " + map.containsKey(4));
	
		// using varargs

		foo("har: ", 100, 1,2);
		foo("bar: ", 1000, 1,2,3);

		foo("car: ", 1, 2,3);

		bar(1);

	}

	static void bar(int x) {
		System.out.println(x);
	}

	static void bar(int ...x) {
		System.out.println("args");
	}

	static void foo(String label, int max, int ...arr) {
		int sum = 0;
		for(int x : arr) {
			sum += x;
		}
		System.out.println(label + sum);
	}

	static void foo(String label, int x, int y, int z) {
		System.out.println(x + y + z);
	}


}
