Skip to content

Commit 0b449bd

Browse files
authored
Add "values()" on search scopes (#1203)
1 parent e71f22b commit 0b449bd

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

gitlab4j-models/src/main/java/org/gitlab4j/models/Constants.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Arrays;
44
import java.util.HashMap;
55
import java.util.Map;
6+
import java.util.Set;
67
import java.util.function.Function;
78
import java.util.stream.Collectors;
89

@@ -898,7 +899,7 @@ public Class<T> getResultType() {
898899
public static final SearchScope<Commit> COMMITS = new SearchScope<>("commits", Commit.class);
899900
public static final SearchScope<SearchBlob> WIKI_BLOBS = new SearchScope<>("wiki_blobs", SearchBlob.class);
900901

901-
private static final Map<String, SearchScope> jsonLookup = Arrays.stream(new SearchScope[] {
902+
private static final Map<String, SearchScope<?>> jsonLookup = Arrays.stream(new SearchScope[] {
902903
PROJECTS,
903904
ISSUES,
904905
MERGE_REQUESTS,
@@ -913,10 +914,15 @@ public Class<T> getResultType() {
913914
.collect(Collectors.toMap(searchScope -> searchScope.jsonName, Function.identity()));
914915

915916
@JsonCreator
917+
@SuppressWarnings("unchecked")
916918
public static <T> SearchScope<T> forValue(String value) {
917919
return (SearchScope<T>) jsonLookup.get(value);
918920
}
919921

922+
public Set<String> values() {
923+
return jsonLookup.keySet();
924+
}
925+
920926
@JsonValue
921927
public String toValue() {
922928
return jsonName;
@@ -958,16 +964,21 @@ public Class<T> getResultType() {
958964
public static final GroupSearchScope<Note> NOTES = new GroupSearchScope<>("notes", Note.class);
959965
public static final GroupSearchScope<User> USERS = new GroupSearchScope<>("users", User.class);
960966

961-
private static final Map<String, GroupSearchScope> jsonLookup = Arrays.stream(new GroupSearchScope[] {
967+
private static final Map<String, GroupSearchScope<?>> jsonLookup = Arrays.stream(new GroupSearchScope[] {
962968
PROJECTS, ISSUES, MERGE_REQUESTS, MILESTONES, WIKI_BLOBS, COMMITS, BLOBS, NOTES, USERS,
963969
})
964970
.collect(Collectors.toMap(searchScope -> searchScope.jsonName, Function.identity()));
965971

966972
@JsonCreator
973+
@SuppressWarnings("unchecked")
967974
public static <T> GroupSearchScope<T> forValue(String value) {
968975
return (GroupSearchScope<T>) jsonLookup.get(value);
969976
}
970977

978+
public Set<String> values() {
979+
return jsonLookup.keySet();
980+
}
981+
971982
@JsonValue
972983
public String toValue() {
973984
return jsonName;
@@ -1008,16 +1019,21 @@ public Class<T> getResultType() {
10081019
new ProjectSearchScope<>("wiki_blobs", SearchBlob.class);
10091020
public static final ProjectSearchScope<User> USERS = new ProjectSearchScope<>("users", User.class);
10101021

1011-
private static final Map<String, ProjectSearchScope> jsonLookup = Arrays.stream(new ProjectSearchScope[] {
1022+
private static final Map<String, ProjectSearchScope<?>> jsonLookup = Arrays.stream(new ProjectSearchScope[] {
10121023
BLOBS, COMMITS, ISSUES, MERGE_REQUESTS, MILESTONES, NOTES, WIKI_BLOBS, USERS,
10131024
})
10141025
.collect(Collectors.toMap(searchScope -> searchScope.jsonName, Function.identity()));
10151026

10161027
@JsonCreator
1028+
@SuppressWarnings("unchecked")
10171029
public static <T> ProjectSearchScope<T> forValue(String value) {
10181030
return (ProjectSearchScope<T>) jsonLookup.get(value);
10191031
}
10201032

1033+
public Set<String> values() {
1034+
return jsonLookup.keySet();
1035+
}
1036+
10211037
@JsonValue
10221038
public String toValue() {
10231039
return jsonName;

0 commit comments

Comments
 (0)