src/main/java/com/danielezihe/controllers/ToDoController.java
/**
     * Finds a todo from the todos BidiMap. Searches only the Todo Id, Title & Description properties
     * @param query Query text to be searched
     * @param property Todo Property to be searched
     * @param useStrict boolean flag to decide how the search should be performed
     * @return an {@link OrderedMap} containing the query result
     * @throws IllegalStateException if a User inputs an unexpected value for @Param(property)
     */
Finds a todo from the todos BidiMap.
Finds a todo from the todos BidiMap .
public OrderedMap<Integer, ToDoEntity> findTodo(String query, TodoEntityProperties property, boolean useStrict) {
        OrderedMap<Integer, ToDoEntity> queryTodos = new LinkedMap<>();
        Stream<ToDoEntity> todosStream;
        todosList = new ArrayList<>(todos.values());
        switch (property) {
            case ID -> {
                ToDoEntity todo = this.todos.get(Integer.parseInt(query));
                queryTodos.put(todo.getId(), todo);
                return queryTodos;
            }
            case TITLE -> {
                if(useStrict)
                    todosStream = todosList.stream().filter(todo -> IOCase.INSENSITIVE.checkEquals(todo.getTitle(), query));
                else
                    todosStream = todosList.stream().filter(todo -> todo.getTitle().toLowerCase().contains(query.toLowerCase()));
            }
            case DESCRIPTION -> {
                if(useStrict)
                    todosStream = todosList.stream().filter(todo -> IOCase.INSENSITIVE.checkEquals(todo.getDescription(), query));
                else
                    todosStream = todosList.stream().filter(todo -> todo.getDescription().toLowerCase().contains(query.toLowerCase()));
            }
            default -> throw new IllegalStateException("Unexpected value: " + property);
        }
        todosStream.forEach(
                todo -> {
                    queryTodos.put(todo.getId(), todo);
                }
        );
        return queryTodos;
    }
public OrderedMap < Integer , ToDoEntity > findTodo ( String query , TodoEntityProperties property , boolean useStrict ) { OrderedMap < Integer , ToDoEntity > queryTodos = new LinkedMap < > ( ) ; Stream < ToDoEntity > todosStream ; todosList = new ArrayList < > ( todos . values ( ) ) ; switch ( property ) { case ID -> { ToDoEntity todo = this . todos . get ( Integer . parseInt ( query ) ) ; queryTodos . put ( todo . getId ( ) , todo ) ; return queryTodos ; } case TITLE -> { if ( useStrict ) todosStream = todosList . stream ( ) . filter ( todo -> IOCase . INSENSITIVE . checkEquals ( todo . getTitle ( ) , query ) ) ; else todosStream = todosList . stream ( ) . filter ( todo -> todo . getTitle ( ) . toLowerCase ( ) . contains ( query . toLowerCase ( ) ) ) ; } case DESCRIPTION -> { if ( useStrict ) todosStream = todosList . stream ( ) . filter ( todo -> IOCase . INSENSITIVE . checkEquals ( todo . getDescription ( ) , query ) ) ; else todosStream = todosList . stream ( ) . filter ( todo -> todo . getDescription ( ) . toLowerCase ( ) . contains ( query . toLowerCase ( ) ) ) ; } default -> throw new IllegalStateException ( "Unexpected value: " + property ) ; } todosStream . forEach ( todo -> { queryTodos . put ( todo . getId ( ) , todo ) ; } ) ; return queryTodos ; }
Finds a todo from the todos BidiMap.
Finds a todo from the todos BidiMap .