SearchArgument.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package me.shedaniel.rei.client;
  2. import java.util.Locale;
  3. import java.util.function.Function;
  4. import java.util.regex.Pattern;
  5. public class SearchArgument {
  6. public static final Function<Integer, Boolean> INCLUDE = integer -> integer > -1;
  7. public static final Function<Integer, Boolean> NOT_INCLUDE = integer -> integer <= -1;
  8. private ArgumentType argumentType;
  9. private String text;
  10. private boolean include;
  11. private Pattern pattern;
  12. public SearchArgument(ArgumentType argumentType, String text, boolean include) {
  13. this(argumentType, text, include, true);
  14. }
  15. public SearchArgument(ArgumentType argumentType, String text, boolean include, boolean autoLowerCase) {
  16. this.argumentType = argumentType;
  17. this.text = autoLowerCase ? text.toLowerCase(Locale.ROOT) : text;
  18. this.include = include;
  19. }
  20. public static Function<Integer, Boolean> getFunction(boolean include) {
  21. return include ? SearchArgument.INCLUDE : SearchArgument.NOT_INCLUDE;
  22. }
  23. public ArgumentType getArgumentType() {
  24. return argumentType;
  25. }
  26. public String getText() {
  27. return text;
  28. }
  29. public boolean isInclude() {
  30. return include;
  31. }
  32. @Override
  33. public String toString() {
  34. return String.format("Argument[%s]: name = %s, include = %b", argumentType.name(), text, include);
  35. }
  36. public enum ArgumentType {
  37. TEXT,
  38. MOD,
  39. TOOLTIP
  40. }
  41. }