// Arup Guha
// 10/26/26
// Use of HashMap for COP 3330

import java.util.*;

public class TestHashMap {

	public static void main(String[] args) {
	
		hardCodedTest();
	}

	public static void hardCodedTest() {
	
		// Add some stuff to the set.
		HashMap<String,String> bestFriend = new HashMap<>();
		bestFriend.put("alice", "bob");
		bestFriend.put("bob", "alice");
		bestFriend.put("caleb", "dave");
		
		// Some names to look for in the map...
		String[] names = {"alice", "benny", "bob", "caleb", "dave", "eddie"};
		
		// Go through the names array.
		for (String name: names) {
			
			// If it's in the map, print out their best friend!
			if (bestFriend.containsKey(name))
				System.out.println("We have info about "+name+". Best friends with "+bestFriend.get(name));
			
			// Very sad; they have no best friend!
			else
				System.out.println(name+" doesn't have a best friend!");
		}
		
		// How to change an entry.
		bestFriend.put("bob","jenna");
		System.out.println("Now bob's best friend is "+bestFriend.get("bob"));
		
		// And remove one.
		bestFriend.remove("caleb");
		
		// Just making sure caleb is gone!
		for (String name: bestFriend.keySet())
			System.out.println(name+" has best friend "+bestFriend.get(name));
	}
	
	// Returns a random string of 7 lowercase letters.
	public static String rndName(Random rndObj) {
	
		// This is a bit slow, maybe I should have made an array and filled it instead.
		String res = "";
		for (int i=0; i<7; i++) {
			int add = rndObj.nextInt(26);
			res = res + (char)('a'+add);
		}
		return res;
	}
	
	public static void randomTest() {
		
		Random rndObj = new Random();

		// Create my map.
		HashMap<String,Integer> nameFreq = new HashMap<>();
		
		// We'll add 5000000 random names.
		for (int i=0; i<5000000; i++) {
			
			// If it's not in the map add it.
			String tmp = rndName(rndObj);
			if (!nameFreq.containsKey(tmp))
				nameFreq.put(tmp, 1);
			
			// If it is update the frequency.
			else
				nameFreq.put(tmp, nameFreq.get(tmp)+1);
		}
			
		// Let's see how many random repeats we got!
		for (String name: nameFreq.keySet())
			if (nameFreq.get(name) > 1)
				System.out.println(name+": "+nameFreq.get(name));
	}
}