macintosh
macintosh

Reputation: 13

Java validating input values

 private String createSearchFieldContent(OverrideableStringValue title,
                                         OverrideableContactValue owner) {

    StringBuilder builder = new StringBuilder(getValue(title));

    if (StringUtils.isNotBlank(getValue(owner).getFamilyName())) {
        builder.append(" ").append(getValue(owner).getFamilyName());
    }

    String searchTerm = StringUtils.replaceAll(builder.toString(), "\n", " ");

    return unaccent(searchTerm);
}

There are four values, which I get from an API and they are not possible as familyName. Is there a way to don't add them to the searchTerm? I'm thinking about something like StringUtils.contain() and then there the invalid values...

Thanks for help!

Upvotes: 0

Views: 70

Answers (1)

avenger
avenger

Reputation: 156

If you know what 4 values from API should not be appended then declare as constants. Now there are 2 ways from here : 1) Either compare all those 4 constants with family name or 2) Add them in hashset then use contains check with family name

Upvotes: 1

Related Questions