/* File: FacePamphletDatabase.java
 * -------------------------------
 * This class keeps track of the profiles of all users in the
 * FacePamphlet application. 
 */

import java.util.*;
import java.io.*;

public class FacePamphletDatabase implements FacePamphletConstants {

	// FacePamphletDatabase works as a Hashmap that reads in a profile name and pairs it with its corresponding profile.
	private Map<String, FacePamphletProfile> database = new HashMap<String,FacePamphletProfile>();
	
	// Constructor for Database object
	public FacePamphletDatabase() {
	  
	}
	
	/*  This method adds the given profile to the database.  If the name associated with the profile 
	 *  is the same as an existing name in the database, the existing profile is replaced.
	 */
	public void addProfile(FacePamphletProfile profile) {
		// If the database doesn't have the passed profile, we add the profile to the database.
		if (!database.containsKey(profile.getName())){
			database.put(profile.getName(), profile);
		} else {
			// If we do have one, we remove the old profile and replace it with the new profile.
			database.remove(profile.getName());
			database.put(profile.getName(), profile);
		}
	}
		
	/* This method returns the profile associated with the given name 
	 * in the database.  If there is no profile, returns null.
	 */
	public FacePamphletProfile getProfile(String name) {
		/* Adjust the entry of the friend being called upon to match the format of names in our database.
		 * Ex.: "kevin KHIEU" -> "Kevin Khieu" */
		String friend = adjustEntry(name);
		
		// If we have the profile, we return that profile. If not, we return nothing.
		if (database.containsKey(friend)){
			FacePamphletProfile returnProfile = database.get(friend);
			return returnProfile;
		} else {
			return null;
		}
	}
	
	
	/* This method removes the profile associated with the given name
	 * from the database.  It also updates the list of friends of all
	 * other profiles in the database to make sure that this name is
	 * removed from the list of friends of any other profile.
	 * 
	 * If there is no profile in the database with the given name, then
	 * the database is unchanged after calling this method.
	 */
	public void deleteProfile(String name) {
		String friend = adjustEntry(name);
		
		/* If we have the a profile on hand with the given name, we remove it from our database and all friendlists
		 * who have this name as a friend. */
		if (database.containsKey(friend)){
			FacePamphletProfile removedProfile = database.get(friend);
			Iterator<String> iterator = removedProfile.getFriends();
			while (iterator.hasNext()){
				String profile = iterator.next();
				FacePamphletProfile fpfriend = database.get(profile);
				fpfriend.removeFriend(friend);
			}
			database.remove(friend);
		}
	}

	
	/** 
	 * This method returns true if there is a profile in the database 
	 * that has the given name.  It returns false otherwise.
	 */
	public boolean containsProfile(String name) {
		String friend = adjustEntry(name);
		if (database.containsKey(friend)){
			return true;
		} else {
			return false;
		}
	}
	
	/* Adjusts each entry that is read so that they are the same format.
	 / Ex: "kevIn khieu" and "KeViN kHIEu" end up as "Kevin Khieu" */ 
	private String adjustEntry(String friend){
		StringTokenizer tokenizer = new StringTokenizer(friend);
		String finalName = "";
		while (tokenizer.hasMoreTokens()){
			
			// Makes each Token in the tokenizer a new word with only the first letter of the word uppercase.
			// Ex.: "kevin" -> "Kevin"
			String next = tokenizer.nextToken();
      char first = next.charAt(0);
      first = Character.toUpperCase(first);
      String rest = next.substring(1);
      rest = rest.toLowerCase();
      String edittedName = first + rest;
	        
      // Adds the fixed name to the finalName string.
      finalName += edittedName + " ";
		}
		// Fix finalName so that it doesn't have that awkward space at the end.
		finalName = finalName.substring(0,finalName.length()-1);
    return finalName;
	}
}

@@ -1760,33 +1760,25 @@
 Profile;%0A%09%09%7D
- else %7B%0A%09
+%0A
 %09%09return nul
@@ -1780,20 +1780,16 @@
 n null;%0A
-%09%09%7D%0A
 %09%7D%0A%09%0A%09%0A%09
@@ -3030,25 +3030,24 @@
 Key(friend))
-%7B
 %0A%09%09%09return t
@@ -3051,27 +3051,16 @@
 n true;%0A
-%09%09%7D else %7B%0A
 %09%09%09retur
@@ -3068,20 +3068,16 @@
  false;%0A
-%09%09%7D%0A
 %09%7D%0A%09%0A%09/*
@@ -3551,22 +3551,19 @@
 oken();%0A
-      
+%09%09%09
 char fir
@@ -3583,22 +3583,19 @@
 rAt(0);%0A
-      
+%09%09%09
 first = 
@@ -3624,22 +3624,19 @@
 first);%0A
-      
+%09%09%09
 String r
@@ -3660,22 +3660,19 @@
 ing(1);%0A
-      
+%09%09%09
 rest = r
@@ -3690,22 +3690,19 @@
 Case();%0A
-      
+%09%09%09
 String e
@@ -3728,16 +3728,18 @@
 + rest;%0A
+%09%09
 %09       
@@ -3740,22 +3740,19 @@
        %0A
-      
+%09%09%09
 // Adds 
@@ -3791,22 +3791,19 @@
 string.%0A
-      
+%09%09%09
 finalNam
@@ -3963,20 +3963,22 @@
 h()-1);%0A
-
     
+%09%09
 return f

Update FacePamphletDatabase.java