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;
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.<br/>
26   * <strong>Please note</strong> that all setters for fields sets given value instead of adding it
27   * to previously set. For example doing:<br/>
28   * <code>new GetCreateIssueMetadataOptionsBuilder().withExpandos("ONE", "TWO").withExpandos("THREE").build()</code><br/>
29   * will result in creating new GetCreateIssueMetadataOptions with only one field marked to be expanded - "THREE"
30   *
31   * @since v1.0
32   */
33  public class GetCreateIssueMetadataOptionsBuilder {
34  	private Iterable<String> expandos = Sets.newHashSet();
35  	private Iterable<String> issueTypeNames;
36  	private Iterable<Long> issueTypeIds;
37  	private Iterable<String> projectKeys;
38  	private Iterable<Long> projectIds;
39  
40  	public GetCreateIssueMetadataOptionsBuilder withExpandos(Iterable<String> expandos) {
41  		this.expandos = expandos;
42  		return this;
43  	}
44  
45  	@SuppressWarnings("UnusedDeclaration")
46  	public GetCreateIssueMetadataOptionsBuilder withExpandos(String ... expandos) {
47  		return withExpandos(ImmutableList.copyOf(expandos));
48  	}
49  
50  	public GetCreateIssueMetadataOptionsBuilder withExpandedIssueTypesFields() {
51  		return withExpandos(ImmutableList.of(GetCreateIssueMetadataOptions.EXPAND_PROJECTS_ISSUETYPES_FIELDS));
52  	}
53  
54  	public GetCreateIssueMetadataOptionsBuilder withIssueTypeNames(Iterable<String> issueTypeNames) {
55  		this.issueTypeNames = issueTypeNames;
56  		return this;
57  	}
58  
59  	@SuppressWarnings("UnusedDeclaration")
60  
61  	public GetCreateIssueMetadataOptionsBuilder withIssueTypeNames(String ... issueTypeNames) {
62  		return withIssueTypeNames(ImmutableList.copyOf(issueTypeNames));
63  	}
64  
65  	public GetCreateIssueMetadataOptionsBuilder withIssueTypeIds(Iterable<Long> issueTypeIds) {
66  		this.issueTypeIds = issueTypeIds;
67  		return this;
68  	}
69  
70  	@SuppressWarnings("UnusedDeclaration")
71  	public GetCreateIssueMetadataOptionsBuilder withIssueTypeIds(Long ... issueTypeIds) {
72  		return withIssueTypeIds(ImmutableList.copyOf(issueTypeIds));
73  	}
74  
75  	public GetCreateIssueMetadataOptionsBuilder withProjectKeys(Iterable<String> projectKeys) {
76  		this.projectKeys = projectKeys;
77  		return this;
78  	}
79  
80  	public GetCreateIssueMetadataOptionsBuilder withProjectKeys(String ... projectKeys) {
81  		return withProjectKeys(ImmutableList.copyOf(projectKeys));
82  	}
83  
84  	public GetCreateIssueMetadataOptionsBuilder withProjectIds(Iterable<Long> projectIds) {
85  		this.projectIds = projectIds;
86  		return this;
87  	}
88  
89  	@SuppressWarnings("UnusedDeclaration")
90  	public GetCreateIssueMetadataOptionsBuilder withProjectIds(Long ... projectIds) {
91  		return withProjectIds(ImmutableList.copyOf(projectIds));
92  	}
93  
94  	public GetCreateIssueMetadataOptions build() {
95  		return new GetCreateIssueMetadataOptions(expandos, issueTypeNames, issueTypeIds, projectKeys, projectIds);
96  	}
97  }