View Javadoc

1   /*
2    * Copyright (C) 2012 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.atlassian.jira.rest.client.api;
18  
19  import com.google.common.collect.ImmutableList;
20  import com.google.common.collect.Sets;
21  
22  /**
23   * Builder class for {@link GetCreateIssueMetadataOptions}. All fields are optional so set only those that
24   * you need and use {@link GetCreateIssueMetadataOptionsBuilder#build()} method to build new
25   * {@link GetCreateIssueMetadataOptions} class.
26   * <p>
27   * <strong>Please note</strong> that all setters for fields sets given value instead of adding it.it
28   * to previously set. For example doing:<br>
29   * <code>new GetCreateIssueMetadataOptionsBuilder().withExpandos("ONE", "TWO").withExpandos("THREE").build()</code><br>
30   * will result in creating new GetCreateIssueMetadataOptions with only one field marked to be expanded - "THREE"
31   *
32   * @since v1.0
33   */
34  public class GetCreateIssueMetadataOptionsBuilder {
35      private Iterable<String> expandos = Sets.newHashSet();
36      private Iterable<String> issueTypeNames;
37      private Iterable<Long> issueTypeIds;
38      private Iterable<String> projectKeys;
39      private Iterable<Long> projectIds;
40  
41      public GetCreateIssueMetadataOptionsBuilder withExpandos(Iterable<String> expandos) {
42          this.expandos = expandos;
43          return this;
44      }
45  
46      @SuppressWarnings("UnusedDeclaration")
47      public GetCreateIssueMetadataOptionsBuilder withExpandos(String... expandos) {
48          return withExpandos(ImmutableList.copyOf(expandos));
49      }
50  
51      public GetCreateIssueMetadataOptionsBuilder withExpandedIssueTypesFields() {
52          return withExpandos(ImmutableList.of(GetCreateIssueMetadataOptions.EXPAND_PROJECTS_ISSUETYPES_FIELDS));
53      }
54  
55      public GetCreateIssueMetadataOptionsBuilder withIssueTypeNames(Iterable<String> issueTypeNames) {
56          this.issueTypeNames = issueTypeNames;
57          return this;
58      }
59  
60      @SuppressWarnings("UnusedDeclaration")
61  
62      public GetCreateIssueMetadataOptionsBuilder withIssueTypeNames(String... issueTypeNames) {
63          return withIssueTypeNames(ImmutableList.copyOf(issueTypeNames));
64      }
65  
66      public GetCreateIssueMetadataOptionsBuilder withIssueTypeIds(Iterable<Long> issueTypeIds) {
67          this.issueTypeIds = issueTypeIds;
68          return this;
69      }
70  
71      @SuppressWarnings("UnusedDeclaration")
72      public GetCreateIssueMetadataOptionsBuilder withIssueTypeIds(Long... issueTypeIds) {
73          return withIssueTypeIds(ImmutableList.copyOf(issueTypeIds));
74      }
75  
76      public GetCreateIssueMetadataOptionsBuilder withProjectKeys(Iterable<String> projectKeys) {
77          this.projectKeys = projectKeys;
78          return this;
79      }
80  
81      public GetCreateIssueMetadataOptionsBuilder withProjectKeys(String... projectKeys) {
82          return withProjectKeys(ImmutableList.copyOf(projectKeys));
83      }
84  
85      public GetCreateIssueMetadataOptionsBuilder withProjectIds(Iterable<Long> projectIds) {
86          this.projectIds = projectIds;
87          return this;
88      }
89  
90      @SuppressWarnings("UnusedDeclaration")
91      public GetCreateIssueMetadataOptionsBuilder withProjectIds(Long... projectIds) {
92          return withProjectIds(ImmutableList.copyOf(projectIds));
93      }
94  
95      public GetCreateIssueMetadataOptions build() {
96          return new GetCreateIssueMetadataOptions(expandos, issueTypeNames, issueTypeIds, projectKeys, projectIds);
97      }
98  }