public class Revision {
- private int major;
- private int minor;
- private int branch;
+ private transient int _major;
+ private transient int _minor;
+ private transient int _branch;
public static class Format {
-// --------------------------
- private String pattern;
+ private transient final String _pattern;
- public Format (String pattern) {
- this.pattern = pattern;
+ public Format (final String pattern) {
+ this._pattern = pattern;
}
- public String format (String verstring) {
- CharBuffer version = CharBuffer.allocate(pattern.length() + 2*2); // Maximum possible size
- char[] format = pattern.toCharArray();
+ public String format (final String verstring) {
+ CharBuffer version = CharBuffer.allocate(_pattern.length() + 2*2); // Maximum possible size
+ char[] format = _pattern.toCharArray();
String[] vernum = verstring.split("\\x2E"); // version is suposed of the internal form (m.n.s)
int branch = Integer.valueOf(vernum[2]);
version.put(vernum[2]);
}
} else if (token == '[') {
- if (branch == 0) while (format[i] != ']') i += 1;
+ if (branch == 0) {
+ while (format[i] != ']') {
+ i += 1;
+ }
+ }
} else if (token == ']') {
continue;
} else {
return new String(version.array(), 0, version.position());
}
- public Revision parse (String verstring) throws ParseException {
- char[] format = pattern.toCharArray();
+ public Revision parse (final String verstring) throws ParseException {
+ char[] format = _pattern.toCharArray();
char[] version = verstring.toCharArray();
CharBuffer major = CharBuffer.allocate(4);
CharBuffer minor = CharBuffer.allocate(4);
token = format[i];
if (token == 'M') {
while (cursor < version.length) {
- if (!Character.isDigit(version[cursor])) break;
+ if (!Character.isDigit(version[cursor])) {
+ break;
+ }
major.put(version[cursor]);
cursor += 1;
}
} else if (token == 'm') {
while (cursor < version.length) {
- if (!Character.isDigit(version[cursor])) break;
+ if (!Character.isDigit(version[cursor])) {
+ break;
+ }
minor.put(version[cursor]);
cursor += 1;
}
} else if (token == 's') {
while (cursor < version.length) {
- if (!Character.isDigit(version[cursor])) break;
+ if (!Character.isDigit(version[cursor])) {
+ break;
+ }
branch.put(version[cursor]);
cursor += 1;
}
} else if (token == '[' || token == ']') {
continue;
} else {
- if (version[cursor] != token) throw new ParseException(verstring, cursor);
+ if (version[cursor] != token) {
+ throw new ParseException(verstring, cursor);
+ }
cursor += 1;
}
- if (cursor >= version.length) break;
+ if (cursor >= version.length) {
+ break;
+ }
}
- if (major.position() == 0) throw new ParseException(verstring, 0);
+ if (major.position() == 0) {
+ throw new ParseException(verstring, 0);
+ }
String majnum = new String(major.array(), 0, major.position());
if (minor.position() == 0) {
}
public String toPattern () {
- return pattern;
+ return _pattern;
}
}
/**
* Constructs a Revision object from the internal representation of a version number (m.n.s).
*/
- public Revision (String value) {
+ public Revision (final String value) {
// ------------------------------
String[] vernum = value.split("\\x2E");
try {
- this.major = Integer.valueOf(vernum[0]);
- this.minor = Integer.valueOf(vernum[1]);
- this.branch = Integer.valueOf(vernum[2]);
+ this._major = Integer.valueOf(vernum[0]);
+ this._minor = Integer.valueOf(vernum[1]);
+ this._branch = Integer.valueOf(vernum[2]);
}
catch (Exception e) { // NumberFormat or OutOfBound exception if value is not of the form m.n.s
- this.major = 0;
- this.minor = 0;
- this.branch = 0;
+ this._major = 0;
+ this._minor = 0;
+ this._branch = 0;
}
}
public Revision () {
// ------------------
- this.major = 0;
- this.minor = 0;
- this.branch = 0;
+ this._major = 0;
+ this._minor = 0;
+ this._branch = 0;
}
- private Revision (int major, int minor) {
+ private Revision (final int major, final int minor) {
// ---------------------------------------
- this.major = major;
- this.minor = minor;
- this.branch = 0;
+ this._major = major;
+ this._minor = minor;
+ this._branch = 0;
}
- private Revision (int major, int minor, String branch) {
+ private Revision (final int major, final int minor, final String branch) {
// ------------------------------------------------------
- this.major = major;
- this.minor = minor;
- this.branch = Integer.valueOf(branch);
+ this._major = major;
+ this._minor = minor;
+ this._branch = Integer.valueOf(branch);
}
// ==============================================================================================================================
// Public member function
// ==============================================================================================================================
- public Revision incrementAs (ProgressState state) {
+ public Revision incrementAs (final ProgressState state) {
// -------------------------------------------------
- if (state == ProgressState.inWORK || state == ProgressState.inDRAFT) minor += 1;
- else if (state == ProgressState.inCHECK) {
- major = major + 1;
- minor = 0;
+ if (state == ProgressState.inWORK || state == ProgressState.inDRAFT) {
+ _minor += 1;
+ } else if (state == ProgressState.inCHECK) {
+ _major = _major + 1;
+ _minor = 0;
}
return this;
}
- public boolean isGraterThan (Revision base) {
+ public boolean isGraterThan (final Revision base) {
// ------------------------------------------
- if (this.major > base.major) return true;
- if (this.major < base.major) return false;
- return (this.minor > base.minor);
+ if (this._major > base._major) {
+ return true;
+ }
+ if (this._major < base._major) {
+ return false;
+ }
+ return (this._minor > base._minor);
}
public boolean isMinor () {
// -------------------------
- return (minor != 0);
+ return (_minor != 0);
}
public boolean isNull () {
// ------------------------
- return (major+minor == 0);
+ return (_major+_minor == 0);
}
/**
* Sets the branch name of this revision.
* @param name the branch name or the internal representation of a version number (m.n.s)
* @return this revision object
*/
- public Revision setBranch (String name) {
+ public Revision setBranch (final String name) {
// ---------------------------------------
String[] vernum = name.split("\\x2E");
- branch = Integer.valueOf(vernum[vernum.length-1]);
+ _branch = Integer.valueOf(vernum[vernum.length-1]);
return this;
}
/**
* Returns the internal representation of a version number (m.n.s) represented by this Revision object.
*/
- public String toString () {
+ @Override
+ public String toString () {
// -------------------------
StringBuffer version = new StringBuffer();
- return version.append(major).append(".").append(minor).append(".").append(branch).toString();
+ return version.append(_major).append(".").append(_minor).append(".").append(_branch).toString();
}
}
\ No newline at end of file