|
1 | 1 | package org.gitlab4j.api;
|
2 | 2 |
|
| 3 | +import java.util.Arrays; |
3 | 4 | import java.util.HashMap;
|
4 | 5 | import java.util.Map;
|
5 |
| - |
| 6 | +import java.util.function.Function; |
| 7 | +import java.util.stream.Collectors; |
| 8 | + |
| 9 | +import org.gitlab4j.api.models.Commit; |
| 10 | +import org.gitlab4j.api.models.Issue; |
| 11 | +import org.gitlab4j.api.models.MergeRequest; |
| 12 | +import org.gitlab4j.api.models.Milestone; |
| 13 | +import org.gitlab4j.api.models.Note; |
| 14 | +import org.gitlab4j.api.models.Project; |
| 15 | +import org.gitlab4j.api.models.SearchBlob; |
| 16 | +import org.gitlab4j.api.models.Snippet; |
| 17 | +import org.gitlab4j.api.models.User; |
6 | 18 | import org.gitlab4j.api.utils.JacksonJsonEnumHelper;
|
7 | 19 |
|
8 | 20 | import com.fasterxml.jackson.annotation.JsonCreator;
|
@@ -753,79 +765,147 @@ public String toString() {
|
753 | 765 | /**
|
754 | 766 | * Enum for the search scope when doing a globalSearch() with the SearchApi.
|
755 | 767 | */
|
756 |
| - public enum SearchScope { |
| 768 | + public static class SearchScope<T> { |
| 769 | + |
| 770 | + private final String jsonName; |
| 771 | + private final Class<T> resultType; |
| 772 | + |
| 773 | + private SearchScope(String jsonName, Class<T> resultType) { |
| 774 | + this.jsonName = jsonName; |
| 775 | + this.resultType = resultType; |
| 776 | + } |
757 | 777 |
|
758 |
| - PROJECTS, ISSUES, MERGE_REQUESTS, MILESTONES, SNIPPET_TITLES, SNIPPET_BLOBS, USERS, |
759 |
| - BLOBS, COMMITS, WIKI_BLOBS; |
| 778 | + public Class<T> getResultType() { |
| 779 | + return resultType; |
| 780 | + } |
| 781 | + |
| 782 | + public static final SearchScope<Project> PROJECTS = new SearchScope<>("projects", Project.class); |
| 783 | + public static final SearchScope<Issue> ISSUES = new SearchScope<>("issues", Issue.class); |
| 784 | + public static final SearchScope<MergeRequest> MERGE_REQUESTS = new SearchScope<>("merge_requests", MergeRequest.class); |
| 785 | + public static final SearchScope<Milestone> MILESTONES = new SearchScope<>("milestones", Milestone.class); |
| 786 | + public static final SearchScope<Snippet> SNIPPET_TITLES = new SearchScope<>("snippet_titles", Snippet.class); |
| 787 | + public static final SearchScope<Snippet> SNIPPET_BLOBS = new SearchScope<>("snippet_blobs", Snippet.class); |
| 788 | + public static final SearchScope<User> USERS = new SearchScope<>("users", User.class); |
| 789 | + public static final SearchScope<SearchBlob> BLOBS = new SearchScope<>("blobs", SearchBlob.class); |
| 790 | + public static final SearchScope<Commit> COMMITS = new SearchScope<>("commits", Commit.class); |
| 791 | + public static final SearchScope<SearchBlob> WIKI_BLOBS = new SearchScope<>("wiki_blobs", SearchBlob.class); |
760 | 792 |
|
761 |
| - private static JacksonJsonEnumHelper<SearchScope> enumHelper = new JacksonJsonEnumHelper<>(SearchScope.class); |
| 793 | + private static final Map<String, SearchScope> jsonLookup = Arrays.stream(new SearchScope[]{PROJECTS, ISSUES, MERGE_REQUESTS, MILESTONES, SNIPPET_TITLES, SNIPPET_BLOBS, USERS, BLOBS, COMMITS, WIKI_BLOBS}) |
| 794 | + .collect(Collectors.toMap(searchScope -> searchScope.jsonName, Function.identity())); |
762 | 795 |
|
763 | 796 | @JsonCreator
|
764 |
| - public static SearchScope forValue(String value) { |
765 |
| - return enumHelper.forValue(value); |
| 797 | + public static <T> SearchScope<T> forValue(String value) { |
| 798 | + return (SearchScope<T>) jsonLookup.get(value); |
766 | 799 | }
|
767 | 800 |
|
768 | 801 | @JsonValue
|
769 | 802 | public String toValue() {
|
770 |
| - return (enumHelper.toString(this)); |
| 803 | + return jsonName; |
771 | 804 | }
|
772 | 805 |
|
773 | 806 | @Override
|
774 | 807 | public String toString() {
|
775 |
| - return (enumHelper.toString(this)); |
| 808 | + return jsonName; |
776 | 809 | }
|
777 | 810 | }
|
778 | 811 |
|
779 | 812 | /**
|
780 | 813 | * Enum for the search scope when doing a groupSearch() with the SearchApi.
|
781 | 814 | */
|
782 |
| - public enum GroupSearchScope { |
| 815 | + public static class GroupSearchScope<T> { |
| 816 | + |
| 817 | + private final String jsonName; |
| 818 | + private final Class<T> resultType; |
783 | 819 |
|
784 |
| - PROJECTS, ISSUES, MERGE_REQUESTS, MILESTONES, WIKI_BLOBS, COMMITS, BLOBS, NOTES, USERS; |
| 820 | + public GroupSearchScope(String jsonName, Class<T> resultType) { |
| 821 | + this.jsonName = jsonName; |
| 822 | + this.resultType = resultType; |
| 823 | + } |
785 | 824 |
|
786 |
| - private static JacksonJsonEnumHelper<GroupSearchScope> enumHelper = new JacksonJsonEnumHelper<>(GroupSearchScope.class); |
| 825 | + public Class<T> getResultType() { |
| 826 | + return resultType; |
| 827 | + } |
| 828 | + |
| 829 | + public static final GroupSearchScope<Project> PROJECTS = new GroupSearchScope<>("projects", Project.class); |
| 830 | + public static final GroupSearchScope<Issue> ISSUES = new GroupSearchScope<>("issues", Issue.class); |
| 831 | + public static final GroupSearchScope<MergeRequest> MERGE_REQUESTS = new GroupSearchScope<>("merge_requests", MergeRequest.class); |
| 832 | + public static final GroupSearchScope<Milestone> MILESTONES = new GroupSearchScope<>("milestones", Milestone.class); |
| 833 | + public static final GroupSearchScope<SearchBlob> WIKI_BLOBS = new GroupSearchScope<>("wiki_blobs", SearchBlob.class); |
| 834 | + public static final GroupSearchScope<Commit> COMMITS = new GroupSearchScope<>("commits", Commit.class); |
| 835 | + public static final GroupSearchScope<SearchBlob> BLOBS = new GroupSearchScope<>("blobs", SearchBlob.class); |
| 836 | + public static final GroupSearchScope<Note> NOTES = new GroupSearchScope<>("notes", Note.class); |
| 837 | + public static final GroupSearchScope<User> USERS = new GroupSearchScope<>("users", User.class); |
| 838 | + |
| 839 | + private static final Map<String, GroupSearchScope> jsonLookup = Arrays.stream(new GroupSearchScope[]{ |
| 840 | + PROJECTS, ISSUES, MERGE_REQUESTS, MILESTONES, WIKI_BLOBS, COMMITS, BLOBS, NOTES, USERS, |
| 841 | + }) |
| 842 | + .collect(Collectors.toMap(searchScope -> searchScope.jsonName, Function.identity())); |
787 | 843 |
|
788 | 844 | @JsonCreator
|
789 |
| - public static GroupSearchScope forValue(String value) { |
790 |
| - return enumHelper.forValue(value); |
| 845 | + public static <T> GroupSearchScope<T> forValue(String value) { |
| 846 | + return (GroupSearchScope<T>) jsonLookup.get(value); |
791 | 847 | }
|
792 | 848 |
|
793 | 849 | @JsonValue
|
794 | 850 | public String toValue() {
|
795 |
| - return (enumHelper.toString(this)); |
| 851 | + return jsonName; |
796 | 852 | }
|
797 | 853 |
|
798 | 854 | @Override
|
799 | 855 | public String toString() {
|
800 |
| - return (enumHelper.toString(this)); |
| 856 | + return jsonName; |
801 | 857 | }
|
802 | 858 | }
|
803 | 859 |
|
804 | 860 | /**
|
805 | 861 | * Enum for the search scope when doing a projectSearch() with the SearchApi.
|
806 | 862 | */
|
807 |
| - public enum ProjectSearchScope { |
| 863 | + public static class ProjectSearchScope<T> { |
| 864 | + |
| 865 | + private final String jsonName; |
| 866 | + private final Class<T> resultType; |
| 867 | + |
| 868 | + public ProjectSearchScope(String jsonName, Class<T> resultType) { |
| 869 | + this.jsonName = jsonName; |
| 870 | + this.resultType = resultType; |
| 871 | + } |
| 872 | + |
| 873 | + public Class<T> getResultType() { |
| 874 | + return resultType; |
| 875 | + } |
808 | 876 |
|
809 |
| - BLOBS, COMMITS, ISSUES, MERGE_REQUESTS, MILESTONES, NOTES, WIKI_BLOBS, USERS; |
| 877 | + public static final ProjectSearchScope<SearchBlob> BLOBS = new ProjectSearchScope<>("blobs", SearchBlob.class); |
| 878 | + public static final ProjectSearchScope<Commit> COMMITS = new ProjectSearchScope<>("commits", Commit.class); |
| 879 | + public static final ProjectSearchScope<Issue> ISSUES = new ProjectSearchScope<>("issues", Issue.class); |
| 880 | + public static final ProjectSearchScope<MergeRequest> MERGE_REQUESTS = new ProjectSearchScope<>("merge_requests", MergeRequest.class); |
| 881 | + public static final ProjectSearchScope<Milestone> MILESTONES = new ProjectSearchScope<>("milestones", Milestone.class); |
| 882 | + public static final ProjectSearchScope<Note> NOTES = new ProjectSearchScope<>("notes", Note.class); |
| 883 | + public static final ProjectSearchScope<SearchBlob> WIKI_BLOBS = new ProjectSearchScope<>("wiki_blobs", SearchBlob.class); |
| 884 | + public static final ProjectSearchScope<User> USERS = new ProjectSearchScope<>("users", User.class); |
810 | 885 |
|
811 |
| - private static JacksonJsonEnumHelper<ProjectSearchScope> enumHelper = new JacksonJsonEnumHelper<>(ProjectSearchScope.class); |
| 886 | + |
| 887 | + private static final Map<String, ProjectSearchScope> jsonLookup = Arrays.stream(new ProjectSearchScope[]{ |
| 888 | + BLOBS, COMMITS, ISSUES, MERGE_REQUESTS, MILESTONES, NOTES, WIKI_BLOBS, USERS, |
| 889 | + }) |
| 890 | + .collect(Collectors.toMap(searchScope -> searchScope.jsonName, Function.identity())); |
812 | 891 |
|
813 | 892 | @JsonCreator
|
814 |
| - public static ProjectSearchScope forValue(String value) { |
815 |
| - return enumHelper.forValue(value); |
| 893 | + public static <T> ProjectSearchScope<T> forValue(String value) { |
| 894 | + return (ProjectSearchScope<T>) jsonLookup.get(value); |
816 | 895 | }
|
817 | 896 |
|
818 | 897 | @JsonValue
|
819 | 898 | public String toValue() {
|
820 |
| - return (enumHelper.toString(this)); |
| 899 | + return jsonName; |
821 | 900 | }
|
822 | 901 |
|
823 | 902 | @Override
|
824 | 903 | public String toString() {
|
825 |
| - return (enumHelper.toString(this)); |
| 904 | + return jsonName; |
826 | 905 | }
|
827 | 906 | }
|
828 | 907 |
|
| 908 | + |
829 | 909 | /** Enum to use for specifying the action when doing a getTodos() with the TodosApi. */
|
830 | 910 | public enum TodoAction {
|
831 | 911 |
|
@@ -1107,10 +1187,10 @@ public enum DefaultBranchProtectionLevel {
|
1107 | 1187 | FULLY_PROTECTED(2),
|
1108 | 1188 | PROTECTED_AGAINST_PUSHES(3),
|
1109 | 1189 | FULL_PROTECTION_AFTER_INITIAL_PUSH(4);
|
1110 |
| - |
| 1190 | + |
1111 | 1191 | @JsonValue
|
1112 | 1192 | private final int value;
|
1113 |
| - |
| 1193 | + |
1114 | 1194 | private DefaultBranchProtectionLevel(int value) {
|
1115 | 1195 | this.value = value;
|
1116 | 1196 | }
|
|
0 commit comments