-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* AND / OR can now be autocompleted * Spaces are inserted before and after where necessary * Newlines are properly preserved * The lambda that glues together some of the autocompletion info is now a general class that takes any filter
- Loading branch information
1 parent
f5d3a5a
commit 0b31e61
Showing
6 changed files
with
64 additions
and
40 deletions.
There are no files selected for viewing
10 changes: 8 additions & 2 deletions
10
src/main/java/link/biosmarcel/baka/filter/BinaryExpressionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
package link.biosmarcel.baka.filter; | ||
|
||
public enum BinaryExpressionType { | ||
AND, | ||
OR, | ||
AND("AND"), | ||
OR("OR"), | ||
; | ||
|
||
public final String text; | ||
|
||
BinaryExpressionType(String text) { | ||
this.text = text; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/link/biosmarcel/baka/view/AutocompleteGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package link.biosmarcel.baka.view; | ||
|
||
import link.biosmarcel.baka.filter.BinaryExpressionType; | ||
import link.biosmarcel.baka.filter.Filter; | ||
import link.biosmarcel.baka.filter.IncompleteQueryException; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class AutocompleteGenerator { | ||
private final Filter<?> filter; | ||
|
||
public AutocompleteGenerator(final Filter<?> filter) { | ||
this.filter = filter; | ||
} | ||
|
||
public List<String> generate(final String value) { | ||
try { | ||
filter.setQuery(value); | ||
if (value.endsWith(")") || value.endsWith(" ") || value.endsWith("\n")) { | ||
// If the query is valid so far, we can always attach another via binary operators. | ||
return Arrays.stream(BinaryExpressionType.values()).map(bo -> bo.text).toList(); | ||
} | ||
return Collections.EMPTY_LIST; | ||
} catch (final IncompleteQueryException exception) { | ||
if ((value.endsWith("(") && exception.token.isBlank()) || | ||
(value.endsWith(exception.token) && | ||
(!exception.token.isEmpty() || value.isEmpty() || !value.stripTrailing().equalsIgnoreCase(value))) | ||
) { | ||
return exception.options; | ||
} | ||
return Collections.EMPTY_LIST; | ||
} catch (final RuntimeException exception) { | ||
System.out.println(exception.getMessage()); | ||
return Collections.EMPTY_LIST; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters