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: /**
021: * Identifies an artifact in a module, without revision information
022: *
023: * @see <a href="package-summary.html">org.apache.ivy.core.module.id</a>
024: */
025: public class ArtifactId {
026: private ModuleId mid;
027:
028: private String name;
029:
030: private String type;
031:
032: private String ext;
033:
034: /**
035: * @param mid The ModuleId, which is the base of this artifact.
036: * @param name The name of the artifact.
037: * @param type The type of the artifact.
038: */
039: public ArtifactId(ModuleId mid, String name, String type, String ext) {
040: this .mid = mid;
041: this .name = name;
042: this .type = type;
043: this .ext = ext;
044: }
045:
046: /** {@inheritDoc} */
047: public boolean equals(Object obj) {
048: if (!(obj instanceof ArtifactId)) {
049: return false;
050: }
051: ArtifactId aid = (ArtifactId) obj;
052: return getModuleId().equals(aid.getModuleId())
053: && getName().equals(aid.getName())
054: && getExt().equals(aid.getExt())
055: && getType().equals(aid.getType());
056: }
057:
058: /** {@inheritDoc} */
059: public int hashCode() {
060: //CheckStyle:MagicNumber| OFF
061: int hash = 17;
062: hash += getModuleId().hashCode() * 37;
063: hash += getName().hashCode() * 37;
064: hash += getType().hashCode() * 37;
065: //CheckStyle:MagicNumber| OFF
066: return hash;
067: }
068:
069: /** {@inheritDoc} */
070: public String toString() {
071: return getModuleId()
072: + "!"
073: + getName()
074: + "."
075: + getExt()
076: + (getType().equals(getExt()) ? "" : "(" + getType()
077: + ")");
078: }
079:
080: /**
081: * @return Returns the module id.
082: */
083: public ModuleId getModuleId() {
084: return mid;
085: }
086:
087: /**
088: * @return Returns the name.
089: */
090: public String getName() {
091: return name;
092: }
093:
094: /**
095: * @return Returns the type.
096: */
097: public String getType() {
098: return type;
099: }
100:
101: /**
102: * @return Returns the ext.
103: */
104: public String getExt() {
105: return ext;
106: }
107: }
|