Reddysekhar Gaduputi
Reddysekhar Gaduputi

Reputation: 490

groovy - how to work with multiple point numbers?

Working on a groovy script which will calculate the current product release version by increment the previous version.
But the version has multiple points to it like 1.2.0 and need to increment it with another multi point number like 0.1.0, how to achieve in groovy, as it seems there is no such data type.

Upvotes: 0

Views: 381

Answers (1)

adn.911
adn.911

Reputation: 1314

I would probably do something like this. Does this help?

class Version {  

static final int INCREMENT_UNIT = 1;

int major, minor, point;  

Version(String version) {
    String parts[] = version.split(".");

    this.major = Integer.parseInt(parts[0]);
    this.minor = Integer.parseInt(parts[1]);
    this.point = Integer.parseInt(parts[2]);
 }

 Version incrementMajor(int unit) {
    this.major += unit; 

    return this;
 }

 Version incrementMinor(int unit) {
    this.minor += unit; 

    return this;
 }

 Version incrementPoint(int unit) {
    this.point += unit;

    return this; 
 }

String toString() {
    return major + "." + minor + "." + point;
}

}

Upvotes: 3

Related Questions