001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.core.module.id;
019:
020: import java.util.Map;
021:
022: import org.apache.ivy.core.IvyPatternHelper;
023: import org.apache.ivy.util.extendable.UnmodifiableExtendableItem;
024:
025: /**
026: * Identifies an artifact in a particular module revision
027: *
028: * @see <a href="package-summary.html">org.apache.ivy.core.module.id</a>
029: */
030: public class ArtifactRevisionId extends UnmodifiableExtendableItem {
031: public static ArtifactRevisionId newInstance(ModuleRevisionId mrid,
032: String name, String type, String ext) {
033: return newInstance(mrid, name, type, ext, null);
034: }
035:
036: public static ArtifactRevisionId newInstance(ModuleRevisionId mrid,
037: String name, String type, String ext, Map extraAttributes) {
038: return new ArtifactRevisionId(new ArtifactId(
039: mrid.getModuleId(), name, type, ext), mrid,
040: extraAttributes);
041: }
042:
043: private ArtifactId artifactId;
044:
045: private ModuleRevisionId mrid;
046:
047: public ArtifactRevisionId(ArtifactId artifactId,
048: ModuleRevisionId mrid) {
049: this (artifactId, mrid, null);
050: }
051:
052: public ArtifactRevisionId(ArtifactId artfId,
053: ModuleRevisionId mdlRevId, Map extraAttributes) {
054: super (null, extraAttributes);
055: artifactId = artfId;
056: mrid = mdlRevId;
057:
058: setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY,
059: getModuleRevisionId().getOrganisation());
060: setStandardAttribute(IvyPatternHelper.MODULE_KEY,
061: getModuleRevisionId().getName());
062: setStandardAttribute(IvyPatternHelper.REVISION_KEY,
063: getModuleRevisionId().getRevision());
064: setStandardAttribute(IvyPatternHelper.ARTIFACT_KEY, getName());
065: setStandardAttribute(IvyPatternHelper.TYPE_KEY, getType());
066: setStandardAttribute(IvyPatternHelper.EXT_KEY, getExt());
067: }
068:
069: public boolean equals(Object obj) {
070: if (!(obj instanceof ArtifactRevisionId)) {
071: return false;
072: }
073: ArtifactRevisionId arid = (ArtifactRevisionId) obj;
074: return getArtifactId().equals(arid.getArtifactId())
075: && getModuleRevisionId().equals(
076: arid.getModuleRevisionId())
077: && getExtraAttributes().equals(
078: arid.getExtraAttributes());
079: }
080:
081: public int hashCode() {
082: // WARN: uniqueness needs to be relatively strong here
083: //CheckStyle:MagicNumber| OFF
084: int hash = 17;
085: hash += getArtifactId().hashCode() * 37;
086: hash += getModuleRevisionId().hashCode() * 37;
087: hash += getExtraAttributes().hashCode() * 37;
088: //CheckStyle:MagicNumber| ON
089:
090: return hash;
091: }
092:
093: public String toString() {
094: return getModuleRevisionId()
095: + "!"
096: + getName()
097: + "."
098: + getExt()
099: + (getType().equals(getExt()) ? "" : "(" + getType()
100: + ")");
101: }
102:
103: /**
104: * @return Returns the artifactId.
105: */
106: public ArtifactId getArtifactId() {
107: return artifactId;
108: }
109:
110: public ModuleRevisionId getModuleRevisionId() {
111: return mrid;
112: }
113:
114: public String getName() {
115: return artifactId.getName();
116: }
117:
118: public String getType() {
119: return artifactId.getType();
120: }
121:
122: public String getExt() {
123: return artifactId.getExt();
124: }
125:
126: /**
127: * @return Returns the revision.
128: */
129: public String getRevision() {
130: return mrid.getRevision();
131: }
132:
133: }
|