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.cache;
019:
020: /**
021: * This class contains information about the origin of an artifact.
022: *
023: * @see org.apache.ivy.plugins.resolver.BasicResolver
024: * @see org.apache.ivy.plugins.resolver.util.ResolvedResource
025: */
026: public class ArtifactOrigin {
027: /**
028: * ArtifactOrigin instance used when the origin is unknown.
029: */
030: public static final ArtifactOrigin UNKNOWN = new ArtifactOrigin(
031: false, "UNKNOWN");
032:
033: private static final int MAGIC_HASH_VALUE = 31;
034:
035: private boolean isLocal;
036:
037: private String location;
038:
039: /**
040: * Create a new instance
041: *
042: * @param isLocal
043: * <code>boolean</code> value indicating if the resource is local (on the
044: * filesystem).
045: * @param location
046: * the location of the resource (normally a url)
047: */
048: public ArtifactOrigin(boolean isLocal, String location) {
049: this .isLocal = isLocal;
050: this .location = location;
051: }
052:
053: /**
054: * Is this resource local to this host, i.e. is it on the file system?
055: *
056: * @return <code>boolean</code> value indicating if the resource is local.
057: */
058: public boolean isLocal() {
059: return isLocal;
060: }
061:
062: /**
063: * Return the location of the resource (normally a url)
064: *
065: * @return the location of the resource
066: */
067: public String getLocation() {
068: return location;
069: }
070:
071: public String toString() {
072: return "ArtifactOrigin { isLocal=" + isLocal + ", location="
073: + location + "}";
074: }
075:
076: public boolean equals(Object o) {
077: if (this == o) {
078: return true;
079: }
080: if (o == null || getClass() != o.getClass()) {
081: return false;
082: }
083:
084: ArtifactOrigin that = (ArtifactOrigin) o;
085:
086: if (isLocal != that.isLocal) {
087: return false;
088: }
089: if (!location.equals(that.location)) {
090: return false;
091: }
092:
093: return true;
094: }
095:
096: public int hashCode() {
097: int result;
098: result = (isLocal ? 1 : 0);
099: result = MAGIC_HASH_VALUE * result + location.hashCode();
100: return result;
101: }
102: }
|