View Javadoc
1   package org.kuali.common.devops.jenkins.updates.model;
2   
3   import static com.google.common.collect.Lists.newArrayList;
4   import static org.kuali.common.util.ObjectUtils.equalsByToString;
5   
6   import java.util.List;
7   
8   import org.kuali.common.core.build.ValidatingBuilder;
9   import org.kuali.common.core.validate.annotation.IdiotProofImmutable;
10  
11  import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
12  import com.google.common.collect.ImmutableList;
13  
14  @IdiotProofImmutable
15  @JsonDeserialize(builder = JenkinsPlugin.Builder.class)
16  public final class JenkinsPlugin {
17  
18  	private final String name;
19  	private final String version;
20  	private final ImmutableList<JenkinsPluginDependency> dependencies;
21  	private final String identity;
22  	private final int hashcode;
23  
24  	private JenkinsPlugin(Builder builder) {
25  		this.name = builder.name;
26  		this.version = builder.version;
27  		this.dependencies = ImmutableList.copyOf(builder.dependencies);
28  		this.identity = name + ":" + version;
29  		this.hashcode = identity.hashCode();
30  	}
31  
32  	public static Builder builder() {
33  		return new Builder();
34  	}
35  
36  	public static class Builder extends ValidatingBuilder<JenkinsPlugin> {
37  
38  		private String name;
39  		private String version;
40  		private List<JenkinsPluginDependency> dependencies = newArrayList();
41  
42  		public Builder withDependencies(List<JenkinsPluginDependency> dependencies) {
43  			this.dependencies = dependencies;
44  			return this;
45  		}
46  
47  		public Builder withName(String name) {
48  			this.name = name;
49  			return this;
50  		}
51  
52  		public Builder withVersion(String version) {
53  			this.version = version;
54  			return this;
55  		}
56  
57  		@Override
58  		public JenkinsPlugin build() {
59  			return validate(new JenkinsPlugin(this));
60  		}
61  	}
62  
63  	@Override
64  	public int hashCode() {
65  		return this.hashcode;
66  	}
67  
68  	@Override
69  	public String toString() {
70  		return this.identity;
71  	}
72  
73  	@Override
74  	public boolean equals(Object other) {
75  		return equalsByToString(this, other);
76  	}
77  
78  	public String getName() {
79  		return name;
80  	}
81  
82  	public String getVersion() {
83  		return version;
84  	}
85  
86  	public List<JenkinsPluginDependency> getDependencies() {
87  		return dependencies;
88  	}
89  
90  }