Skip to content

Commit

Permalink
Add "values()" on search scopes (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini authored Dec 2, 2024
1 parent e71f22b commit 0b449bd
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions gitlab4j-models/src/main/java/org/gitlab4j/models/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

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

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

@JsonCreator
@SuppressWarnings("unchecked")
public static <T> SearchScope<T> forValue(String value) {
return (SearchScope<T>) jsonLookup.get(value);
}

public Set<String> values() {
return jsonLookup.keySet();
}

@JsonValue
public String toValue() {
return jsonName;
Expand Down Expand Up @@ -958,16 +964,21 @@ public Class<T> getResultType() {
public static final GroupSearchScope<Note> NOTES = new GroupSearchScope<>("notes", Note.class);
public static final GroupSearchScope<User> USERS = new GroupSearchScope<>("users", User.class);

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

@JsonCreator
@SuppressWarnings("unchecked")
public static <T> GroupSearchScope<T> forValue(String value) {
return (GroupSearchScope<T>) jsonLookup.get(value);
}

public Set<String> values() {
return jsonLookup.keySet();
}

@JsonValue
public String toValue() {
return jsonName;
Expand Down Expand Up @@ -1008,16 +1019,21 @@ public Class<T> getResultType() {
new ProjectSearchScope<>("wiki_blobs", SearchBlob.class);
public static final ProjectSearchScope<User> USERS = new ProjectSearchScope<>("users", User.class);

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

@JsonCreator
@SuppressWarnings("unchecked")
public static <T> ProjectSearchScope<T> forValue(String value) {
return (ProjectSearchScope<T>) jsonLookup.get(value);
}

public Set<String> values() {
return jsonLookup.keySet();
}

@JsonValue
public String toValue() {
return jsonName;
Expand Down

0 comments on commit 0b449bd

Please sign in to comment.