001package org.kuali.common.devops.jenkins.updates.model;
002
003import static com.google.common.collect.Lists.newArrayList;
004import static org.kuali.common.util.ObjectUtils.equalsByToString;
005
006import java.util.List;
007
008import org.kuali.common.core.build.ValidatingBuilder;
009import org.kuali.common.core.validate.annotation.IdiotProofImmutable;
010
011import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
012import com.google.common.collect.ImmutableList;
013
014@IdiotProofImmutable
015@JsonDeserialize(builder = JenkinsPlugin.Builder.class)
016public final class JenkinsPlugin {
017
018        private final String name;
019        private final String version;
020        private final ImmutableList<JenkinsPluginDependency> dependencies;
021        private final String identity;
022        private final int hashcode;
023
024        private JenkinsPlugin(Builder builder) {
025                this.name = builder.name;
026                this.version = builder.version;
027                this.dependencies = ImmutableList.copyOf(builder.dependencies);
028                this.identity = name + ":" + version;
029                this.hashcode = identity.hashCode();
030        }
031
032        public static Builder builder() {
033                return new Builder();
034        }
035
036        public static class Builder extends ValidatingBuilder<JenkinsPlugin> {
037
038                private String name;
039                private String version;
040                private List<JenkinsPluginDependency> dependencies = newArrayList();
041
042                public Builder withDependencies(List<JenkinsPluginDependency> dependencies) {
043                        this.dependencies = dependencies;
044                        return this;
045                }
046
047                public Builder withName(String name) {
048                        this.name = name;
049                        return this;
050                }
051
052                public Builder withVersion(String version) {
053                        this.version = version;
054                        return this;
055                }
056
057                @Override
058                public JenkinsPlugin build() {
059                        return validate(new JenkinsPlugin(this));
060                }
061        }
062
063        @Override
064        public int hashCode() {
065                return this.hashcode;
066        }
067
068        @Override
069        public String toString() {
070                return this.identity;
071        }
072
073        @Override
074        public boolean equals(Object other) {
075                return equalsByToString(this, other);
076        }
077
078        public String getName() {
079                return name;
080        }
081
082        public String getVersion() {
083                return version;
084        }
085
086        public List<JenkinsPluginDependency> getDependencies() {
087                return dependencies;
088        }
089
090}