Skip to content

Add "values()" on search scopes #1203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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