/** * Used to retrieve {@link NameEntry} of given state from the repository. * @param state the {@link State} of the entry * @return list of {@link NameEntry}. If state is not present, it returns an empty list */ public List<NameEntry> loadAllByState(Optional<State> state) { return state.map(s -> nameEntryRepository.findByState(s)).orElseGet(Collections::emptyList); }
/** * Used to retrieve paginated result of {@link NameEntry} of given state from the repository * @param state state the {@link State} of the entry * @param pageParam specifies page number * @param countParam specifies the count of result * @return a list of {@link org.oruko.dictionary.model.NameEntry} */ public List<NameEntry> loadByState(Optional<State> state, Optional<Integer> pageParam, Optional<Integer> countParam) { if (!state.isPresent()) { return this.loadAllNames(pageParam, countParam); } final Integer page = pageParam.map(integer -> integer - 1).orElse(1); final Integer count = countParam.orElse(COUNT_SIZE); return nameEntryRepository.findByState(state.get(), new PageRequest(page,count)); }