SearchArgument.java 1.4 KB

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