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 package org.apache.geronimo.system.plugin;
018
019 import org.apache.geronimo.kernel.repository.Version;
020
021 /**
022 * SnapshotVersion is like Version but holds extra fields that appear in the
023 * filename of a snapshot artifact. The toString() method is not overriden
024 * because the super implementation produces the correct string for navigating
025 * the directory structure of a plugin repository. The extra fields maintained
026 * in this class are needed for constructing the filename portion of a URL for a
027 * snapshot artifact where the qualifier and build number are replaced with a
028 * snapshot timestamp and build number.
029 *
030 * @version $Revision: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
031 *
032 */
033 public class SnapshotVersion extends Version {
034 private static final long serialVersionUID = -4165276456639945508L;
035
036 private Integer buildNumber;
037
038 private String timestamp;
039
040 public SnapshotVersion(Version version) {
041 super(version.toString());
042 }
043
044 public SnapshotVersion(String version) {
045 super(version);
046 }
047
048 public int getBuildNumber() {
049 return buildNumber != null ? buildNumber.intValue() : 0;
050 }
051
052 public void setBuildNumber(int buildNumber) {
053 this.buildNumber = new Integer(buildNumber);
054 }
055
056 public String getTimestamp() {
057 return timestamp;
058 }
059
060 public void setTimestamp(String timestamp) {
061 this.timestamp = timestamp;
062 }
063
064 public boolean equals(Object other) {
065 if (super.equals(other)) {
066 if (other instanceof SnapshotVersion) {
067 SnapshotVersion v = (SnapshotVersion) other;
068 if (buildNumber == null ? v.buildNumber != null : !buildNumber.equals(v.buildNumber)) {
069 return false;
070 }
071 if (timestamp == null ? v.timestamp != null : !timestamp.equals(v.timestamp)) {
072 return false;
073 }
074 return true;
075 }
076 }
077 return false;
078 }
079
080 public int hashCode() {
081 int hashCode = super.hashCode();
082 if (buildNumber != null) {
083 hashCode = 37 * hashCode + buildNumber.hashCode();
084 }
085 if (timestamp != null) {
086 hashCode = 37 * hashCode + timestamp.hashCode();
087 }
088 return hashCode;
089 }
090 }