Skip to content

Commit bb8e63d

Browse files
committed
Added CompleterHelper#equalsAny methods
1 parent 2d739c4 commit bb8e63d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/main/java/me/despical/commandframework/CompleterHelper.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,49 @@ public List<String> empty() {
8080
return List.of();
8181
}
8282

83+
/**
84+
* Checks if the given input string matches any of the provided candidate strings.
85+
* <p>
86+
* This method performs a <b>case-sensitive</b> comparison.
87+
* If the input is {@code null}, it returns {@code false} immediately.
88+
* </p>
89+
*
90+
* @param input The string to check.
91+
* @param matches The potential matching strings.
92+
* @return {@code true} if the input equals any of the matches; {@code false} otherwise.
93+
*/
94+
@Contract(pure = true)
95+
public boolean equalsAny(String input, String... matches) {
96+
if (input == null) {
97+
return false;
98+
}
99+
100+
for (String match : matches) {
101+
if (input.equals(match)) {
102+
return true;
103+
}
104+
}
105+
106+
return false;
107+
}
108+
109+
/**
110+
* Checks if the argument at the specified index matches any of the provided candidate strings.
111+
* <p>
112+
* This method retrieves the argument from the internal arguments list at the given index
113+
* and delegates the comparison to {@link #equalsAny(String, String...)}.
114+
* </p>
115+
*
116+
* @param index The index of the argument to check.
117+
* @param matches The potential matching strings.
118+
* @return {@code true} if the argument at the specified index matches any of the candidates.
119+
*/
120+
@Contract(pure = true)
121+
public boolean equalsAny(int index, String... matches) {
122+
String input = arguments.getArgument(index);
123+
return equalsAny(input, matches);
124+
}
125+
83126
/**
84127
* Filters a collection of strings based on the argument at the specified index.
85128
* <p>

0 commit comments

Comments
 (0)