|
|
@@ -1,7 +1,9 @@
|
|
1
|
1
|
package com.zipcodewilmington.phone;
|
|
2
|
2
|
|
|
3
|
3
|
import com.zipcodewilmington.exceptions.InvalidPhoneNumberFormatException;
|
|
|
4
|
+import com.zipcodewilmington.tools.RandomNumberFactory;
|
|
4
|
5
|
|
|
|
6
|
+import java.util.logging.Level;
|
|
5
|
7
|
import java.util.logging.Logger;
|
|
6
|
8
|
|
|
7
|
9
|
/**
|
|
|
@@ -19,15 +21,24 @@ public final class PhoneNumberFactory {
|
|
19
|
21
|
* @param phoneNumberCount - number of PhoneNumber objects to instantiate
|
|
20
|
22
|
* @return array of randomly generated PhoneNumber objects
|
|
21
|
23
|
*/ //TODO - Implement logic
|
|
22
|
|
- public static PhoneNumber[] createRandomPhoneNumberArray(int phoneNumberCount) {
|
|
23
|
|
- return null;
|
|
|
24
|
+ public static PhoneNumber[] createRandomPhoneNumberArray(int phoneNumberCount) throws InvalidPhoneNumberFormatException{
|
|
|
25
|
+ PhoneNumber[] phoneNumbers = new PhoneNumber[phoneNumberCount];
|
|
|
26
|
+ for (int i = 0; i < phoneNumberCount; i++) {
|
|
|
27
|
+ phoneNumbers[i] = createRandomPhoneNumber();
|
|
|
28
|
+ }
|
|
|
29
|
+ return phoneNumbers;
|
|
24
|
30
|
}
|
|
25
|
31
|
|
|
26
|
32
|
/**
|
|
27
|
33
|
* @return an instance of PhoneNumber with randomly generated phone number value
|
|
28
|
34
|
*/ //TODO - Implement logic
|
|
29
|
35
|
public static PhoneNumber createRandomPhoneNumber() throws InvalidPhoneNumberFormatException {
|
|
30
|
|
- return createPhoneNumberSafely(-1, -1, -1);
|
|
|
36
|
+ try {
|
|
|
37
|
+ int areaCode = RandomNumberFactory.createInteger(100, 999);
|
|
|
38
|
+ int officeCode = RandomNumberFactory.createInteger(100, 999);
|
|
|
39
|
+ int phoneLine = RandomNumberFactory.createInteger(1000, 9999);
|
|
|
40
|
+ return createPhoneNumberSafely(areaCode, officeCode, phoneLine);
|
|
|
41
|
+ } catch (InvalidPhoneNumberFormatException e) {return null;}
|
|
31
|
42
|
}
|
|
32
|
43
|
|
|
33
|
44
|
|
|
|
@@ -38,13 +49,15 @@ public final class PhoneNumberFactory {
|
|
38
|
49
|
* @return a new phone number object
|
|
39
|
50
|
*/ //TODO - if input is valid, return respective PhoneNumber object, else return null
|
|
40
|
51
|
public static PhoneNumber createPhoneNumberSafely(int areaCode, int centralOfficeCode, int phoneLineCode) throws InvalidPhoneNumberFormatException{
|
|
|
52
|
+ String tempString = "";
|
|
41
|
53
|
try {
|
|
42
|
54
|
// if (3 == String.valueOf(areaCode).length() && 3 == String.valueOf(centralOfficeCode).length() && 4 == String.valueOf(phoneLineCode).length()) {
|
|
43
|
|
- String tempString = String.valueOf(areaCode) + String.valueOf(centralOfficeCode) + String.valueOf(phoneLineCode);
|
|
|
55
|
+ tempString = String.valueOf(areaCode) + String.valueOf(centralOfficeCode) + String.valueOf(phoneLineCode);
|
|
44
|
56
|
return createPhoneNumber(tempString);
|
|
45
|
57
|
// return createPhoneNumber(tempString);
|
|
46
|
58
|
// }
|
|
47
|
59
|
} catch (InvalidPhoneNumberFormatException inv) {
|
|
|
60
|
+ logger.log(Level.FINE, (tempString + "is not a valid phone number"));
|
|
48
|
61
|
return null;
|
|
49
|
62
|
}
|
|
50
|
63
|
}
|
|
|
@@ -55,6 +68,7 @@ public final class PhoneNumberFactory {
|
|
55
|
68
|
* @throws InvalidPhoneNumberFormatException - thrown if phoneNumberString does not match acceptable format
|
|
56
|
69
|
*/ // TODO - Add throws statement to method signature
|
|
57
|
70
|
public static PhoneNumber createPhoneNumber (String phoneNumberString) throws InvalidPhoneNumberFormatException {
|
|
|
71
|
+ logger.log(Level.FINE, ("Attempting to create a new PhoneNumber object with a value of " + phoneNumberString));
|
|
58
|
72
|
return new PhoneNumber(phoneNumberString);
|
|
59
|
73
|
}
|
|
60
|
74
|
}
|