You can do something like this:
private final String myLocator = "//*[contains(@id,'username') and contains (@type,'text') and contains (text(),'exactly what I want')]";
So you can write up the locator however you wish, depending on the attributes that what you're mapping has, no need to have 5 rows for a click or select.
Also, you can use a wildcard in that locator and just replace whatever you want to use as a parameter with "%s", like this:
private final String myLocator = "//*[contains(@id,'%s') and contains (@type,'text') and contains (text(),'exactly what I want')]";
Then have a dynamic element created from that like:
private WebElement usernameSelectElement(String text) {
return driver.findElement(By.xpath(String.format(myLocator, text)));
}
And the usage would be something like:
public void clickMyElement(text){
usernameSelectElement(text).click();
}
For the example that you had, it's just overly complicated in my view.