public void validateCity(String cityCode) { Optional<City> city = findCity(cityCode); if (city.isPresent()) { return; } setError(CITY_INVALID, cityCode); } public Optional<City> findCity(String cityCode) { City city = cityRepository.get(cityCode); return Optional.ofNullable(city); }