Skip to content

Commit bf27eda

Browse files
added a simple implementation of the AllowedListInputs
1 parent 91b98ac commit bf27eda

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.jetbrains.annotations.NotNull;
44
import org.jetbrains.annotations.Nullable;
55

6+
import java.util.List;
67
import java.util.Objects;
78

89
public interface AllowedInputs<T> {
@@ -19,6 +20,10 @@ public interface AllowedInputs<T> {
1920
return (Any<T>) Any.NOT_NULL;
2021
}
2122

23+
static <T> AllowedListInputs.@NotNull Values<T> values(@NotNull List<T> values) {
24+
return new AllowedListInputs.Values<>(values);
25+
}
26+
2227
final class Any<T> implements AllowedInputs<T> {
2328

2429
private static final @NotNull Any<Object> NULLABLE = new Any<>(true);

commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.jetbrains.annotations.Nullable;
55

66
import java.util.List;
7+
import java.util.Objects;
78

89
public interface AllowedListInputs<T> extends AllowedInputs<T> {
910

@@ -15,4 +16,38 @@ default boolean isAllowed(@Nullable T input) {
1516
return false;
1617
return allowedValues().contains(input);
1718
}
19+
20+
final class Values<T> implements AllowedListInputs<T> {
21+
22+
private final @NotNull List<T> values;
23+
24+
Values(@NotNull List<T> values) {
25+
this.values = List.copyOf(values);
26+
}
27+
28+
@Override
29+
public @NotNull List<T> allowedValues() {
30+
return values;
31+
}
32+
33+
@Override
34+
public boolean equals(Object o) {
35+
if (o == null || getClass() != o.getClass())
36+
return false;
37+
Values<?> values1 = (Values<?>) o;
38+
return Objects.equals(values, values1.values);
39+
}
40+
41+
@Override
42+
public int hashCode() {
43+
return Objects.hashCode(values);
44+
}
45+
46+
@Override
47+
public String toString() {
48+
return "AllowedListInputs$Values{" +
49+
"values=" + values +
50+
'}';
51+
}
52+
}
1853
}

0 commit comments

Comments
 (0)