/** * Returns the NameSurferEntry associated with this name, if one exists. If the name does not * appear in the database, this method returns null. */ public NameSurferEntry findEntry(String name) { char firstLetter = name.charAt(0); if (Character.isLowerCase(firstLetter) == true) { firstLetter = Character.toUpperCase(firstLetter); } String remainingLetters = name.substring(1); remainingLetters = remainingLetters.toLowerCase(); name = firstLetter + remainingLetters; if (namesDataBase.containsKey(name)) { return namesDataBase.get(name); } return null; }
/** * Creates a new NameSurferDataBase and initializes it using the data in the specified file. The * constructor throws an error exception if the requested file does not exist or if an error * occurs as the file is being read. */ public NameSurferDataBase(String filename) { try { BufferedReader rd = new BufferedReader(new FileReader(filename)); while (true) { String line = rd.readLine(); if (line == null) break; NameSurferEntry entry = new NameSurferEntry(line); namesDataBase.put(entry.getName(), entry); } rd.close(); } catch (IOException ex) { throw new ErrorException(ex); } }