how to validate if method argument belongs to a list of strings

hey guys. i have my service:
@Service
@Validated
public class ItemService {
private ItemRepository itemRepository;
public ItemService(ItemRepository itemRepository) {
this.itemRepository = itemRepository;
}
public List<Item> getItemsByDistanceAndSeason(@Min(1) double distance, String season) {

if (season.equals("all") || season.equals("winter") || season.equals("spring") || season.equals("summer") || season.equals("autumn")) {
//then ok
}

return itemRepository.getAllByDistanceAndSeason(distance, season);
}
}
@Service
@Validated
public class ItemService {
private ItemRepository itemRepository;
public ItemService(ItemRepository itemRepository) {
this.itemRepository = itemRepository;
}
public List<Item> getItemsByDistanceAndSeason(@Min(1) double distance, String season) {

if (season.equals("all") || season.equals("winter") || season.equals("spring") || season.equals("summer") || season.equals("autumn")) {
//then ok
}

return itemRepository.getAllByDistanceAndSeason(distance, season);
}
}
and idk how to validate Stringr season argument. i want it to fall into a list of strings. i was thinking of making an enum and checking if argument falls into an enum. or maybe there are other more effective ways? thanks
1 Reply
JavaBot
JavaBot11mo ago
This post has been reserved for your question.
Hey @bambyzas! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server