Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB

  1. // See README.txt for information and build instructions.
  2. import com.example.tutorial.AddressBookProtos.AddressBook;
  3. import com.example.tutorial.AddressBookProtos.Person;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import java.io.PrintStream;
  7. class ListPeople {
  8. // Iterates though all people in the AddressBook and prints info about them.
  9. static void Print(AddressBook addressBook) {
  10. for (Person person: addressBook.getPersonList()) {
  11. System.out.println("Person ID: " + person.getId());
  12. System.out.println(" Name: " + person.getName());
  13. if (person.hasEmail()) {
  14. System.out.println(" E-mail address: " + person.getEmail());
  15. }
  16. for (Person.PhoneNumber phoneNumber : person.getPhoneList()) {
  17. switch (phoneNumber.getType()) {
  18. case MOBILE:
  19. System.out.print(" Mobile phone #: ");
  20. break;
  21. case HOME:
  22. System.out.print(" Home phone #: ");
  23. break;
  24. case WORK:
  25. System.out.print(" Work phone #: ");
  26. break;
  27. }
  28. System.out.println(phoneNumber.getNumber());
  29. }
  30. }
  31. }
  32. // Main function: Reads the entire address book from a file and prints all
  33. // the information inside.
  34. public static void main(String[] args) throws Exception {
  35. if (args.length != 1) {
  36. System.err.println("Usage: ListPeople ADDRESS_BOOK_FILE");
  37. System.exit(-1);
  38. }
  39. // Read the existing address book.
  40. AddressBook addressBook =
  41. AddressBook.parseFrom(new FileInputStream(args[0]));
  42. Print(addressBook);
  43. }
  44. }