|
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;
|
@@ -730,79 +742,147 @@ public String toString() {
|
730 | 742 | /**
|
731 | 743 | * Enum for the search scope when doing a globalSearch() with the SearchApi.
|
732 | 744 | */
|
733 |
| - public enum SearchScope { |
| 745 | + public static class SearchScope<T> { |
| 746 | + |
| 747 | + private final String jsonName; |
| 748 | + private final Class<T> resultType; |
| 749 | + |
| 750 | + private SearchScope(String jsonName, Class<T> resultType) { |
| 751 | + this.jsonName = jsonName; |
| 752 | + this.resultType = resultType; |
| 753 | + } |
734 | 754 |
|
735 |
| - PROJECTS, ISSUES, MERGE_REQUESTS, MILESTONES, SNIPPET_TITLES, SNIPPET_BLOBS, USERS, |
736 |
| - BLOBS, COMMITS, WIKI_BLOBS; |
| 755 | + public Class<T> getResultType() { |
| 756 | + return resultType; |
| 757 | + } |
| 758 | + |
| 759 | + public static final SearchScope<Project> PROJECTS = new SearchScope<>("projects", Project.class); |
| 760 | + public static final SearchScope<Issue> ISSUES = new SearchScope<>("issues", Issue.class); |
| 761 | + public static final SearchScope<MergeRequest> MERGE_REQUESTS = new SearchScope<>("merge_requests", MergeRequest.class); |
| 762 | + public static final SearchScope<Milestone> MILESTONES = new SearchScope<>("milestones", Milestone.class); |
| 763 | + public static final SearchScope<Snippet> SNIPPET_TITLES = new SearchScope<>("snippet_titles", Snippet.class); |
| 764 | + public static final SearchScope<Snippet> SNIPPET_BLOBS = new SearchScope<>("snippet_blobs", Snippet.class); |
| 765 | + public static final SearchScope<User> USERS = new SearchScope<>("users", User.class); |
| 766 | + public static final SearchScope<SearchBlob> BLOBS = new SearchScope<>("blobs", SearchBlob.class); |
| 767 | + public static final SearchScope<Commit> COMMITS = new SearchScope<>("commits", Commit.class); |
| 768 | + public static final SearchScope<SearchBlob> WIKI_BLOBS = new SearchScope<>("wiki_blobs", SearchBlob.class); |
737 | 769 |
|
738 |
| - private static JacksonJsonEnumHelper<SearchScope> enumHelper = new JacksonJsonEnumHelper<>(SearchScope.class); |
| 770 | + private static final Map<String, SearchScope> jsonLookup = Arrays.stream(new SearchScope[]{PROJECTS, PROJECTS, ISSUES, MERGE_REQUESTS, MILESTONES, SNIPPET_TITLES, SNIPPET_BLOBS, USERS, BLOBS, COMMITS, WIKI_BLOBS}) |
| 771 | + .collect(Collectors.toMap(searchScope -> searchScope.jsonName, Function.identity())); |
739 | 772 |
|
740 | 773 | @JsonCreator
|
741 |
| - public static SearchScope forValue(String value) { |
742 |
| - return enumHelper.forValue(value); |
| 774 | + public static <T> SearchScope<T> forValue(String value) { |
| 775 | + return (SearchScope<T>) jsonLookup.get(value); |
743 | 776 | }
|
744 | 777 |
|
745 | 778 | @JsonValue
|
746 | 779 | public String toValue() {
|
747 |
| - return (enumHelper.toString(this)); |
| 780 | + return jsonName; |
748 | 781 | }
|
749 | 782 |
|
750 | 783 | @Override
|
751 | 784 | public String toString() {
|
752 |
| - return (enumHelper.toString(this)); |
| 785 | + return jsonName; |
753 | 786 | }
|
754 | 787 | }
|
755 | 788 |
|
756 | 789 | /**
|
757 | 790 | * Enum for the search scope when doing a groupSearch() with the SearchApi.
|
758 | 791 | */
|
759 |
| - public enum GroupSearchScope { |
| 792 | + public static class GroupSearchScope<T> { |
| 793 | + |
| 794 | + private final String jsonName; |
| 795 | + private final Class<T> resultType; |
760 | 796 |
|
761 |
| - PROJECTS, ISSUES, MERGE_REQUESTS, MILESTONES, WIKI_BLOBS, COMMITS, BLOBS, NOTES, USERS; |
| 797 | + public GroupSearchScope(String jsonName, Class<T> resultType) { |
| 798 | + this.jsonName = jsonName; |
| 799 | + this.resultType = resultType; |
| 800 | + } |
762 | 801 |
|
763 |
| - private static JacksonJsonEnumHelper<GroupSearchScope> enumHelper = new JacksonJsonEnumHelper<>(GroupSearchScope.class); |
| 802 | + public Class<T> getResultType() { |
| 803 | + return resultType; |
| 804 | + } |
| 805 | + |
| 806 | + public static final GroupSearchScope<Project> PROJECTS = new GroupSearchScope<>("projects", Project.class); |
| 807 | + public static final GroupSearchScope<Issue> ISSUES = new GroupSearchScope<>("issues", Issue.class); |
| 808 | + public static final GroupSearchScope<MergeRequest> MERGE_REQUESTS = new GroupSearchScope<>("merge_requests", MergeRequest.class); |
| 809 | + public static final GroupSearchScope<Milestone> MILESTONES = new GroupSearchScope<>("milestones", Milestone.class); |
| 810 | + public static final GroupSearchScope<SearchBlob> WIKI_BLOBS = new GroupSearchScope<>("wiki_blobs", SearchBlob.class); |
| 811 | + public static final GroupSearchScope<Commit> COMMITS = new GroupSearchScope<>("commits", Commit.class); |
| 812 | + public static final GroupSearchScope<SearchBlob> BLOBS = new GroupSearchScope<>("blobs", SearchBlob.class); |
| 813 | + public static final GroupSearchScope<Note> NOTES = new GroupSearchScope<>("notes", Note.class); |
| 814 | + public static final GroupSearchScope<User> USERS = new GroupSearchScope<>("users", User.class); |
| 815 | + |
| 816 | + private static final Map<String, GroupSearchScope> jsonLookup = Arrays.stream(new GroupSearchScope[]{ |
| 817 | + PROJECTS, ISSUES, MERGE_REQUESTS, MILESTONES, WIKI_BLOBS, COMMITS, BLOBS, NOTES, USERS, |
| 818 | + }) |
| 819 | + .collect(Collectors.toMap(searchScope -> searchScope.jsonName, Function.identity())); |
764 | 820 |
|
765 | 821 | @JsonCreator
|
766 |
| - public static GroupSearchScope forValue(String value) { |
767 |
| - return enumHelper.forValue(value); |
| 822 | + public static <T> GroupSearchScope<T> forValue(String value) { |
| 823 | + return (GroupSearchScope<T>) jsonLookup.get(value); |
768 | 824 | }
|
769 | 825 |
|
770 | 826 | @JsonValue
|
771 | 827 | public String toValue() {
|
772 |
| - return (enumHelper.toString(this)); |
| 828 | + return jsonName; |
773 | 829 | }
|
774 | 830 |
|
775 | 831 | @Override
|
776 | 832 | public String toString() {
|
777 |
| - return (enumHelper.toString(this)); |
| 833 | + return jsonName; |
778 | 834 | }
|
779 | 835 | }
|
780 | 836 |
|
781 | 837 | /**
|
782 | 838 | * Enum for the search scope when doing a projectSearch() with the SearchApi.
|
783 | 839 | */
|
784 |
| - public enum ProjectSearchScope { |
| 840 | + public static class ProjectSearchScope<T> { |
| 841 | + |
| 842 | + private final String jsonName; |
| 843 | + private final Class<T> resultType; |
| 844 | + |
| 845 | + public ProjectSearchScope(String jsonName, Class<T> resultType) { |
| 846 | + this.jsonName = jsonName; |
| 847 | + this.resultType = resultType; |
| 848 | + } |
| 849 | + |
| 850 | + public Class<T> getResultType() { |
| 851 | + return resultType; |
| 852 | + } |
785 | 853 |
|
786 |
| - BLOBS, COMMITS, ISSUES, MERGE_REQUESTS, MILESTONES, NOTES, WIKI_BLOBS, USERS; |
| 854 | + public static final ProjectSearchScope<SearchBlob> BLOBS = new ProjectSearchScope<>("blobs", SearchBlob.class); |
| 855 | + public static final ProjectSearchScope<Commit> COMMITS = new ProjectSearchScope<>("commits", Commit.class); |
| 856 | + public static final ProjectSearchScope<Issue> ISSUES = new ProjectSearchScope<>("issues", Issue.class); |
| 857 | + public static final ProjectSearchScope<MergeRequest> MERGE_REQUESTS = new ProjectSearchScope<>("merge_requests", MergeRequest.class); |
| 858 | + public static final ProjectSearchScope<Milestone> MILESTONES = new ProjectSearchScope<>("milestones", Milestone.class); |
| 859 | + public static final ProjectSearchScope<Note> NOTES = new ProjectSearchScope<>("notes", Note.class); |
| 860 | + public static final ProjectSearchScope<SearchBlob> WIKI_BLOBS = new ProjectSearchScope<>("wiki_blobs", SearchBlob.class); |
| 861 | + public static final ProjectSearchScope<User> USERS = new ProjectSearchScope<>("users", User.class); |
787 | 862 |
|
788 |
| - private static JacksonJsonEnumHelper<ProjectSearchScope> enumHelper = new JacksonJsonEnumHelper<>(ProjectSearchScope.class); |
| 863 | + |
| 864 | + private static final Map<String, ProjectSearchScope> jsonLookup = Arrays.stream(new ProjectSearchScope[]{ |
| 865 | + BLOBS, COMMITS, ISSUES, MERGE_REQUESTS, MILESTONES, NOTES, WIKI_BLOBS, USERS, |
| 866 | + }) |
| 867 | + .collect(Collectors.toMap(searchScope -> searchScope.jsonName, Function.identity())); |
789 | 868 |
|
790 | 869 | @JsonCreator
|
791 |
| - public static ProjectSearchScope forValue(String value) { |
792 |
| - return enumHelper.forValue(value); |
| 870 | + public static <T> ProjectSearchScope<T> forValue(String value) { |
| 871 | + return (ProjectSearchScope<T>) jsonLookup.get(value); |
793 | 872 | }
|
794 | 873 |
|
795 | 874 | @JsonValue
|
796 | 875 | public String toValue() {
|
797 |
| - return (enumHelper.toString(this)); |
| 876 | + return jsonName; |
798 | 877 | }
|
799 | 878 |
|
800 | 879 | @Override
|
801 | 880 | public String toString() {
|
802 |
| - return (enumHelper.toString(this)); |
| 881 | + return jsonName; |
803 | 882 | }
|
804 | 883 | }
|
805 | 884 |
|
| 885 | + |
806 | 886 | /** Enum to use for specifying the action when doing a getTodos() with the TodosApi. */
|
807 | 887 | public enum TodoAction {
|
808 | 888 |
|
@@ -1084,10 +1164,10 @@ public enum DefaultBranchProtectionLevel {
|
1084 | 1164 | FULLY_PROTECTED(2),
|
1085 | 1165 | PROTECTED_AGAINST_PUSHES(3),
|
1086 | 1166 | FULL_PROTECTION_AFTER_INITIAL_PUSH(4);
|
1087 |
| - |
| 1167 | + |
1088 | 1168 | @JsonValue
|
1089 | 1169 | private final int value;
|
1090 |
| - |
| 1170 | + |
1091 | 1171 | private DefaultBranchProtectionLevel(int value) {
|
1092 | 1172 | this.value = value;
|
1093 | 1173 | }
|
|
0 commit comments