public static void main(String[] args) { BuddyInfo buddy = new BuddyInfo("tom", "Carleton", "1234"); AddressBook ab = new AddressBook(); ab.addBuddy(buddy); ab.removeBuddy(buddy); // changes }
public static void main(String[] args) { BuddyInfo Jimbo = new BuddyInfo("Jimbo", "123 Fake Street", "(555) 555-5555"); BuddyInfo Name = new BuddyInfo(); AddressBook buddies = new AddressBook(); Jimbo.printName(); Name.setName("John Doe"); Name.setAddress("321 Faker Street"); Name.setPhoneNumber("(613) 555-5555"); Name.printName(); buddies.addBuddy(Jimbo); buddies.addBuddy(Name); buddies.removeBuddy(Name); }
/** * Checks to see if the delete button should be enabled based on the number of contact records. */ private void shouldEnableDelete() { if (addressbook.getNames().size() > 0) { deletebutton.setEnabled(true); } else { deletebutton.setEnabled(false); } }
private static void removeEntry(InOut in, AddressBook book) { String name = in.nextLine("Enter name: "); String key = in.nextLine("Enter key: "); String value = book.remove(name, key); if (value == null) in.message("entry not found"); else in.message("Removed entry with value: " + value); }
/** * Load the address book from the file into memory * * @param inputStream The source input stream (generic input stream to allow all kinds of streams) * from where address book entries need to be read. The validity of input stream can be * checked by the client. * @param addressBook The destination address book in memory * @throws Exception Exceptions can be thrown during writing */ public static final void load(InputStream inputStream, AddressBook addressBook) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String nextLine = br.readLine(); while (nextLine != null) { // "**********" marks the end of an entry if (nextLine.compareTo("**********") == 0) nextLine = br.readLine(); if (nextLine == null) break; String name = nextLine; String postalAddress = br.readLine(); String phoneNumber = br.readLine(); String emailAddress = br.readLine(); String note = br.readLine(); // Use the builder pattern to construct the entry from each of the properties AddressBookEntry entry = new AddressBookEntry.Builder(name) .postalAddress(postalAddress) .phoneNumber(phoneNumber) .emailAddress(emailAddress) .note(note) .build(); addressBook.addEntry(entry); nextLine = br.readLine(); } br.close(); }
private static void lookupEntry(InOut in, AddressBook book) { String name = in.nextLine("Enter name: "); String key = in.nextLine("Enter key: "); String value = book.get(name, key); if (value == null) in.message("No entry"); else in.message("Value: " + value); }
private static void addChangeEntry(InOut in, AddressBook book) { String name = in.nextLine("Enter name: "); String key = in.nextLine("Enter key: "); String value = in.nextLine("Enter value: "); String oldValue = book.put(name, key, value); if (oldValue == null) in.message("Entry added"); else in.message("Entry updated"); }
public static void main(String[] args) { String filename = null; InOut in; if (args.length > 0) { filename = args[0]; in = new ConsoleInOut(); } else { JFileChooser chooser = new JFileChooser(); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) filename = chooser.getSelectedFile().getPath(); in = new WindowInOut(); } if (filename == null) return; AddressBook book = new ArrayListAddressBook(); book.load(filename); processCommands(in, book); }
/** * Checks to see if the Previous and Next buttons should be enabled based on the number of contact * records. */ private void shouldEnablePrevAndNext() { if (addressbook.getNames().size() > 1) { nextbutton.setEnabled(true); previousbutton.setEnabled(true); } else { nextbutton.setEnabled(false); previousbutton.setEnabled(false); } }
public static void main(String[] args) throws Exception { Date dteTemp; SimpleDateFormat sdfTemp = new SimpleDateFormat("yyyy_MM_dd-E-hh:mm:ss_a"); AddressBook adbContacts = new AddressBook(); String strTempName; String strTempVMID; String strTempVMTS; Class.forName("org.sqlite.JDBC"); Connection conn = DriverManager.getConnection( "jdbc:sqlite:" + System.getenv("HOME") + "/iPhone_fake/Voicemail/voicemail.db"); Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery("SELECT * FROM voicemail ORDER BY date;"); while (rs.next()) { strTempVMID = rs.getString("ROWID"); dteTemp = SQLLiteData.convertDate(rs.getString("date")); strTempVMTS = sdfTemp.format(dteTemp); strTempName = adbContacts.lookupContact(rs.getString("sender")); createContactDir(strTempName); moveVoicemail(strTempName, strTempVMID, strTempVMTS); // dteTemp = SQLLiteData.convertDate(rs.getString("expiration")); // System.out.print(sdfTemp.format(dteTemp) + " "); // System.out.print(adbContacts.lookupContact(rs.getString("callback_num")) // + " "); // System.out.print(rs.getString("duration") + " "); // System.out.print(rs.getString("flags") + " "); // System.out.println(); } stat.close(); rs.close(); conn.close(); }
private static void processCommands(InOut in, AddressBook book) { String commands = "1: Add/Change Entry\n" + "2: Look Up Entry\n" + "3: Remove Entry\n" + "4: Save Directory\n" + "5: Exit\n" + "Enter Command: "; boolean done = false; while (!done) { String choice = in.nextLine(commands); if (choice.equals("1")) addChangeEntry(in, book); else if (choice.equals("2")) lookupEntry(in, book); else if (choice.equals("3")) removeEntry(in, book); else if (choice.equals("4")) book.save(); else if (choice.equals("5")) done = true; else System.out.println("Not a valid option:" + choice); } }
@Before public void foo() throws Exception { deptDir = new ArrayListAddressBook(); deptDir.load("deptdir.txt"); dir = new ArrayListAddressBook(); }
@Test public void deptDirContainsHorstmann() { assertNotNull(deptDir.get("Horstmann", "Phone")); }
@Test(expected = NoSuchElementException.class) public void RemoveTester3() { dir.put("Bob", "Phone", "2"); assertNull(dir.remove("Me", "Phone")); }
@Test(expected = NoSuchElementException.class) public void RemoveTester2() { assertNull(dir.remove("Me", "Phone")); }
@Test(expected = NoSuchElementException.class) public void RemoveTester() { dir.put("Horstmann", "Phone", "2"); dir.remove("Horstmann", "Phone"); assertNull(dir.get("Horstmann", "Phone")); }
/** * Save the address book from the memory into a file * * @param addressBook The source address book in memory that needs to be saved * @param outputStream The destination output stream (generic output stream so that it's not * limited to files but with streams in general). The validity of output stream can be checked * by the client. * @throws Exception could be thrown while writing */ public static final void save(AddressBook addressBook, OutputStream outputStream) throws Exception { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream)); bw.write(addressBook.toString()); bw.close(); }
protected AppData() { contacts = AddressBook.ReadContacts("appdata/addressbook"); }