package com.evanram.code.java.dimchat_client;
public class Version
{
private String ver;
private int majorVer, minorVer, revisionNum;
private char releaseStage;
private String versionWarn = "Bad version format! (expected: \'#.#.#(a/b)\')";
public Version(String ver) throws VersionException
{
this.ver = ver;
parse();
}
private void parse() throws VersionException
{
String[] split = ver.split("\\.");
if(split.length < 3)
throw new VersionException(versionWarn);
try
{
majorVer = Integer.parseInt(split[0]);
minorVer = Integer.parseInt(split[1]);
revisionNum = Integer.parseInt(split[2].replaceAll("[^\\d]", "")); //remove non-numeric characters
releaseStage = (split[2].replaceAll("\\d", "")).charAt(0); //remove numberic characters
}
catch(NumberFormatException e)
{
e.printStackTrace();
throw new VersionException(versionWarn);
}
}
@Override
public String toString()
{
return ver;
}
public int getMajorVer()
{
return minorVer;
}
public int getMinorVer()
{
return majorVer;
}
public int getRevisionNum()
{
return revisionNum;
}
public boolean isFinalRelease()
{
return !(isAlphaRelease() || isBetaRelease());
}
public boolean isAlphaRelease()
{
return releaseStage == 'a';
}
public boolean isBetaRelease()
{
return releaseStage == 'b';
}
}