* @param list List instance
*/
private void addContactToList (final Contact contact, final List<Contact> list) {
+ // No null here
+ if (contact == null) {
+ // Throw exception
+ throw new NullPointerException("contact is null");
+ } else if (list == null) {
+ // Throw exception
+ throw new NullPointerException("list is null");
+ }
+
// Debug message
this.getLogger().debug(MessageFormat.format("contact={0}", contact));
StringTokenizer tokenizer;
String line;
+ // Init number/string data values
+ Long num = null;
+ Boolean bool = null;
+ Gender gender = null;
+
// Read all lines
while (!this.isEndOfFile()) {
// Then read a line
// Debug message
this.getLogger().debug(MessageFormat.format("line={0}", line));
- // Then tokenize it
+ // Then tokenize it
// @TODO Move this into separate method
tokenizer = new StringTokenizer(line, ";");
// The tokens are now available, so get all
while (tokenizer.hasMoreElements()) {
+ // Reset variables
+ num = null;
+ bool = null;
+
// Get next token
String token = tokenizer.nextToken();
// Debug message
this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken));
- // Init number/string data values
- String strData = strippedToken;
- Long num = null;
- Boolean bool = null;
- Gender gender = null;
-
// Now, let's try a number check, if no null
if (strippedToken != null) {
// Okay, no null, maybe the string bears a decimal number?
bool = Boolean.valueOf(strippedToken);
}
- // Now, let's try a boolean check, if no null
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("strippedToken={0},num={1},bool={2}", strippedToken, num, bool));
+
+ // Now, let's try a gender check, if no null
if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) {
// Get first character
gender = Gender.fromChar(strippedToken.charAt(0));
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("strippedToken={0},gender={1}", strippedToken, gender));
+
+ // This instance must be there
+ assert (gender instanceof Gender) : "gender is not set by Gender.fromChar(" + strippedToken + ")";
}
// Now it depends on the counter which position we need to check
case 2: // Surname
assert (contact instanceof Contact) : "First token was not boolean";
+ assert (gender instanceof Gender) : "gender instance is not set";
// Update data
contact.updateNameData(gender, strippedToken, null, null);
case 3: // Family name
assert (contact instanceof Contact) : "First token was not boolean";
+ assert (gender instanceof Gender) : "gender instance is not set";
// Update data
contact.updateNameData(gender, null, strippedToken, null);
case 4: // Company name
assert (contact instanceof Contact) : "First token was not boolean";
+ assert (gender instanceof Gender) : "gender instance is not set";
// Update data
contact.updateNameData(gender, null, null, strippedToken);
count++;
}
+ // The contact instance should be there now
+ assert(contact instanceof Contact) : "contact is not set: " + contact;
+
// Add contact
this.addContactToList(contact, list);
}