001    /**
002     *
003     *  Licensed to the Apache Software Foundation (ASF) under one or more
004     *  contributor license agreements.  See the NOTICE file distributed with
005     *  this work for additional information regarding copyright ownership.
006     *  The ASF licenses this file to You under the Apache License, Version 2.0
007     *  (the "License"); you may not use this file except in compliance with
008     *  the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     *  Unless required by applicable law or agreed to in writing, software
013     *  distributed under the License is distributed on an "AS IS" BASIS,
014     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     *  See the License for the specific language governing permissions and
016     *  limitations under the License.
017     */
018    package org.apache.geronimo.system.plugin;
019    
020    import org.apache.geronimo.kernel.repository.Version;
021    
022    /**
023     * SnapshotVersion is like Version but holds extra fields that appear in the
024     * filename of a snapshot artifact. The toString() method is not overriden
025     * because the super implementation produces the correct string for navigating
026     * the directory structure of a plugin repository. The extra fields maintained
027     * in this class are needed for constructing the filename portion of a URL for a
028     * snapshot artifact where the qualifier and build number are replaced with a
029     * snapshot timestamp and build number.
030     * 
031     * @version $Revision: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $
032     * 
033     */
034    public class SnapshotVersion extends Version {
035        private static final long serialVersionUID = -4165276456639945508L;
036    
037        private Integer buildNumber;
038    
039        private String timestamp;
040    
041        public SnapshotVersion(Version version) {
042            super(version.toString());
043        }
044    
045        public SnapshotVersion(String version) {
046            super(version);
047        }
048    
049        public int getBuildNumber() {
050            return buildNumber != null ? buildNumber.intValue() : 0;
051        }
052    
053        public void setBuildNumber(int buildNumber) {
054            this.buildNumber = new Integer(buildNumber);
055        }
056    
057        public String getTimestamp() {
058            return timestamp;
059        }
060    
061        public void setTimestamp(String timestamp) {
062            this.timestamp = timestamp;
063        }
064    
065        public boolean equals(Object other) {
066            if (super.equals(other)) {
067                if (other instanceof SnapshotVersion) {
068                    SnapshotVersion v = (SnapshotVersion) other;
069                    if (buildNumber == null ? v.buildNumber != null : !buildNumber.equals(v.buildNumber)) {
070                        return false;
071                    }
072                    if (timestamp == null ? v.timestamp != null : !timestamp.equals(v.timestamp)) {
073                        return false;
074                    }
075                    return true;
076                }
077            }
078            return false;
079        }
080    
081        public int hashCode() {
082            int hashCode = super.hashCode();
083            if (buildNumber != null) {
084                hashCode = 37 * hashCode + buildNumber.hashCode();
085            }
086            if (timestamp != null) {
087                hashCode = 37 * hashCode + timestamp.hashCode();
088            }
089            return hashCode;
090        }
091    }