MCPcopy Create free account
hub / github.com/apple/coremltools / PromptForAddress

Method PromptForAddress

deps/protobuf/examples/AddPerson.java:15–57  ·  view source on GitHub ↗
(BufferedReader stdin,
                                 PrintStream stdout)

Source from the content-addressed store, hash-verified

13class AddPerson {
14 // This function fills in a Person message based on user input.
15 static Person PromptForAddress(BufferedReader stdin,
16 PrintStream stdout) throws IOException {
17 Person.Builder person = Person.newBuilder();
18
19 stdout.print("Enter person ID: ");
20 person.setId(Integer.valueOf(stdin.readLine()));
21
22 stdout.print("Enter name: ");
23 person.setName(stdin.readLine());
24
25 stdout.print("Enter email address (blank for none): ");
26 String email = stdin.readLine();
27 if (email.length() > 0) {
28 person.setEmail(email);
29 }
30
31 while (true) {
32 stdout.print("Enter a phone number (or leave blank to finish): ");
33 String number = stdin.readLine();
34 if (number.length() == 0) {
35 break;
36 }
37
38 Person.PhoneNumber.Builder phoneNumber =
39 Person.PhoneNumber.newBuilder().setNumber(number);
40
41 stdout.print("Is this a mobile, home, or work phone? ");
42 String type = stdin.readLine();
43 if (type.equals("mobile")) {
44 phoneNumber.setType(Person.PhoneType.MOBILE);
45 } else if (type.equals("home")) {
46 phoneNumber.setType(Person.PhoneType.HOME);
47 } else if (type.equals("work")) {
48 phoneNumber.setType(Person.PhoneType.WORK);
49 } else {
50 stdout.println("Unknown phone type. Using default.");
51 }
52
53 person.addPhones(phoneNumber);
54 }
55
56 return person.build();
57 }
58
59 // Main function: Reads the entire address book from a file,
60 // adds one person based on user input, then writes it back out to the same

Callers 1

mainMethod · 0.95

Calls 9

newBuilderMethod · 0.65
printMethod · 0.65
equalsMethod · 0.65
buildMethod · 0.65
valueOfMethod · 0.45
setNameMethod · 0.45
lengthMethod · 0.45
setNumberMethod · 0.45
setTypeMethod · 0.45

Tested by

no test coverage detected