001 /* 002 * Copyright (C) 2006-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.codehaus.gmaven.feature; 018 019 /** 020 * Container for version information in the form of <tt>major.minor.revision-tag</tt>. 021 * 022 * @version $Id: Version.java 9 2009-07-16 09:22:08Z user57 $ 023 * @author <a href="mailto:jason@planet57.com">Jason Dillon</a> 024 */ 025 public final class Version 026 { 027 public final int major; 028 029 public final int minor; 030 031 public final int revision; 032 033 public final String tag; 034 035 public Version(final int major, final int minor, final int revision, final String tag) { 036 assert major > 0; 037 assert minor >= 0; 038 assert revision >= 0; 039 // tag can be null 040 041 this.major = major; 042 this.minor = minor; 043 this.revision = revision; 044 this.tag = tag; 045 } 046 047 public Version(final int major, final int minor, final int revision) { 048 this(major, minor, revision, null); 049 } 050 051 public Version(final int major, final int minor) { 052 this(major, minor, 0); 053 } 054 055 public Version(final int major) { 056 this(major, 0); 057 } 058 059 public boolean equals(final Object obj) { 060 if (this == obj) { 061 return true; 062 } 063 else if (obj == null || getClass() != obj.getClass()) { 064 return false; 065 } 066 067 Version version = (Version) obj; 068 069 if (major != version.major) { 070 return false; 071 } 072 else if (minor != version.minor) { 073 return false; 074 } 075 else if (revision != version.revision) { 076 return false; 077 } 078 else if (tag != null ? !tag.equals(version.tag) : version.tag != null) { 079 return false; 080 } 081 082 return true; 083 } 084 085 public int hashCode() { 086 int result; 087 088 result = major; 089 result = 31 * result + minor; 090 result = 31 * result + revision; 091 result = 31 * result + (tag != null ? tag.hashCode() : 0); 092 093 return result; 094 } 095 096 public String toString() { 097 StringBuffer buff = new StringBuffer(); 098 099 buff.append(major); 100 101 if (minor != -1) { 102 buff.append(".").append(minor); 103 } 104 if (revision != -1) { 105 buff.append(".").append(revision); 106 } 107 if (tag != null) { 108 buff.append("-").append(tag); 109 } 110 111 return buff.toString(); 112 } 113 114 // 115 // TODO: Add some comparison methods 116 // 117 }