View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  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  		// Make sure we are being configured correctly
36  		Assert.noNulls(identifier, properties);
37  		Assert.noBlanks(version);
38  
39  		// Finish setting things up
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  }