spring-hateoas-examples
spring-hateoas-examples copied to clipboard
A simpler splitting logic from name to first and last name
The current code has the following method for splitting name to two:
public void setName(String wholeName) {
String[] parts = wholeName.split(" ");
this.firstName = parts[0];
if (parts.length > 1) {
this.lastName = StringUtils.arrayToDelimitedString(Arrays.copyOfRange(parts, 1, parts.length), " ");
} else {
this.lastName = "";
}
}
IMHO, the same could be done without using arrays and 3rd party libraries:
public void setName(String wholeName) {
final int i = wholeName.indexOf(" ");
if (i > 0) {
this.firstName = wholeName.substring(0, i);
this.lastName = wholeName.substring(i + 1);
} else {
this.firstName = wholeName;
this.lastName = "";
}
}
Should I submit a PR for this?