aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/client/SearchArgument.java
blob: 0f9449c8528547d835392f4c878f69424ce80765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package me.shedaniel.rei.client;

import java.util.function.Function;
import java.util.regex.Pattern;

public class SearchArgument {
    
    public static final Function<Integer, Boolean> INCLUDE = integer -> integer > -1;
    public static final Function<Integer, Boolean> NOT_INCLUDE = integer -> integer <= -1;
    private ArgumentType argumentType;
    private String text;
    private boolean include;
    private Pattern pattern;
    public static final SearchArgument ALWAYS = new SearchArgument(ArgumentType.ALWAYS, "", true);
    
    public SearchArgument(ArgumentType argumentType, String text, boolean include) {
        this(argumentType, text, include, true);
    }
    
    public SearchArgument(ArgumentType argumentType, String text, boolean include, boolean autoLowerCase) {
        this.argumentType = argumentType;
        this.text = autoLowerCase ? text.toLowerCase() : text;
        this.include = include;
    }
    
    public static Function<Integer, Boolean> getFunction(boolean include) {
        return include ? SearchArgument.INCLUDE : SearchArgument.NOT_INCLUDE;
    }
    
    public ArgumentType getArgumentType() {
        return argumentType;
    }
    
    public String getText() {
        return text;
    }
    
    public boolean isInclude() {
        return include;
    }
    
    @Override
    public String toString() {
        return String.format("Argument[%s]: name = %s, include = %b", argumentType.name(), text, include);
    }
    
    public enum ArgumentType {
        TEXT,
        MOD,
        TOOLTIP,
        ALWAYS
    }
    
}