001: package org.contineo.core.document;
002:
003: /**
004: * This class represents versions.
005: *
006: * @author Michael Scholz
007: * @version 1.0
008: */
009: public class Version implements Comparable {
010:
011: /**
012: * specifies different version types
013: */
014: public enum VERSION_TYPE {
015: NEW_RELEASE, NEW_SUBVERSION, OLD_VERSION;
016: }
017:
018: private String version;
019:
020: private String versionUser = "";
021:
022: private String versionDate = "";
023:
024: private String versionComment = "";
025:
026: public Version() {
027: }
028:
029: public String getVersion() {
030: return version;
031: }
032:
033: public String getVersionUser() {
034: return versionUser;
035: }
036:
037: public String getVersionDate() {
038: return versionDate;
039: }
040:
041: public String getVersionComment() {
042: return versionComment;
043: }
044:
045: public void setVersion(String version) {
046: this .version = version;
047: }
048:
049: public void setVersionUser(String vuser) {
050: versionUser = vuser;
051: }
052:
053: public void setVersionDate(String date) {
054: versionDate = date;
055: }
056:
057: public void setVersionComment(String comment) {
058: versionComment = comment;
059: }
060:
061: /**
062: * returns a new version name
063: *
064: * @param oldVersionName name of the old version, e.g. 1.5
065: * @param versionType what kind of version, so if it should be 1.6, 2.0 or
066: * remain 1.5
067: */
068: public String getNewVersionName(String oldVersionName,
069: VERSION_TYPE versionType) {
070: String release = oldVersionName.substring(0, oldVersionName
071: .indexOf("."));
072: String version = oldVersionName.substring(oldVersionName
073: .lastIndexOf(".") + 1);
074:
075: int number;
076: switch (versionType) {
077: case NEW_RELEASE:
078: number = Integer.parseInt(release);
079: release = String.valueOf(number + 1);
080: version = "0";
081: break;
082: case NEW_SUBVERSION:
083: number = Integer.parseInt(version);
084: version = String.valueOf(number + 1);
085: break;
086: case OLD_VERSION:
087: return oldVersionName;
088: }
089:
090: return release + "." + version;
091: }
092:
093: /** for sorting a list of Version objects by the version number */
094: public int compareTo(Object obj) {
095: if (!(obj instanceof Version))
096: return 0;
097:
098: return this .getVersion().toLowerCase().compareTo(
099: ((Version) obj).getVersion().toLowerCase());
100: }
101:
102: @Override
103: public boolean equals(Object obj) {
104: if (!(obj instanceof Version))
105: return false;
106: Version other = (Version) obj;
107: return this .getVersion().equals(other.getVersion());
108: }
109:
110: @Override
111: public int hashCode() {
112: return version.hashCode();
113: }
114:
115: @Override
116: public String toString() {
117: return version.toString();
118: }
119: }
|