1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.project.model;
17
18 import java.util.Properties;
19
20 import org.kuali.common.util.Assert;
21 import org.kuali.common.util.ObjectUtils;
22 import org.kuali.common.util.PropertyUtils;
23 import org.kuali.common.util.identify.Identifiable;
24
25 public final class ImmutableProject implements Project, Identifiable {
26
27 private final ProjectIdentifier identifier;
28 private final String version;
29 private final Properties properties;
30
31 private final String id;
32 private final int hashCode;
33
34 public ImmutableProject(ProjectIdentifier identifier, String version, Properties properties) {
35
36 Assert.noNulls(identifier, properties);
37 Assert.noBlanks(version);
38
39
40 this.identifier = identifier;
41 this.version = version;
42 this.properties = PropertyUtils.toImmutable(properties);
43 this.id = identifier.getIdentifier() + ":" + version;
44 this.hashCode = identifier.hashCode();
45 }
46
47 public ImmutableProject(String groupId, String artifactId, String version, Properties properties) {
48 this(new ProjectIdentifier(groupId, artifactId), version, properties);
49 }
50
51 @Override
52 public String getGroupId() {
53 return identifier.getGroupId();
54 }
55
56 @Override
57 public String getArtifactId() {
58 return identifier.getArtifactId();
59 }
60
61 @Override
62 public String getVersion() {
63 return version;
64 }
65
66 @Override
67 public Properties getProperties() {
68 return properties;
69 }
70
71 @Override
72 public String getIdentifier() {
73 return id;
74 }
75
76 @Override
77 public String toString() {
78 return id;
79 }
80
81 @Override
82 public int hashCode() {
83 return hashCode;
84 }
85
86 @Override
87 public boolean equals(Object other) {
88 return ObjectUtils.equalsByToString(this, other);
89 }
90
91 }