space is too much
/**
* Return the concatenation of first name and last name separated by a space.
*/
public String getFullname() {
String s = "";
if (this.getFirstName() != null) {
s += this.getFirstName() + " ";
}
if (this.getLastName() != null) {
s += this.getLastName();
}
return s;
}
Let's say that firstName = 'Pitt' and lastName = 'Dirk'. We got "Pitt Dirk". And what if the firstName is null, we got " Dirk". Hum, less good.
And what if both are null, we got " ", a space!
This f**king space mess up our database. The better, this kind of method are copied/pasted every where the same behavior was needed.
What do we need then ? A nice join method that concatenate elements of an Object array inserting a separator between elements and ignoring null and/or empty string.
No comments:
Post a Comment