0
 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!

keuleJ
  • 3,418
  • 4
  • 30
  • 51
macintosh
  • 13
  • 2
  • 1
    create exception? what exception? in which cases? is it throwing an exception? are you trying to throw one yourself?µ – Stultuske Nov 21 '19 at 07:04
  • @Stultuske exception would be the best way but I'm not pretty sure how I can do that correctly – macintosh Nov 21 '19 at 07:15
  • do what correctly, you're still not being clear about what it is you're trying to do – Stultuske Nov 21 '19 at 07:25
  • @Stultuske I got some values which are not allowed and I know these values. I like to add an exception for those four values - if I get these values, it shouldn't add them to the string – macintosh Nov 21 '19 at 08:23

1 Answers1

1

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

avenger
  • 156
  • 1
  • 10