
com.adobe.aemds.guide.common.FDVersion Maven / Gradle / Ivy
package com.adobe.aemds.guide.common;
import org.apache.commons.lang.StringUtils;
/**
* Class representing AF version
*
* @pad.exclude Exclude from Published API.
*/
public final class FDVersion {
// major version
private final int majorVersion;
// minor version
private final int minorVersion;
public FDVersion(int majorVersion, int minorVersion) {
this.majorVersion = majorVersion;
this.minorVersion = minorVersion;
}
public FDVersion(String version) {
String[] split = StringUtils.split(version, ".");
if (split != null && split.length > 1) {
majorVersion = Integer.parseInt(split[0]);
minorVersion = Integer.parseInt(split[1]);
} else {
majorVersion = 0;
minorVersion = 0;
}
}
/**
* Compares two version objects
*
* @param version version to compare with
* @return the value {@code 0} if {@code version} is
* numerically equal to this {@code FDVersion}; a value
* less than {@code 0} if this {@code FDVersion}
* is numerically less than {@code version};
* and a value greater than {@code 0} if this
* {@code FDVersion} is numerically greater than
* {@code version}.
*/
public int compareTo(FDVersion version) {
return FDVersion.compare(this, version);
}
/**
* Compares two {@link FDVersion} objects
*
* @param v1 instance of {@link FDVersion} object
* @param v2 instance of {@link FDVersion} object
* @return
*/
public static int compare(FDVersion v1, FDVersion v2) {
return (v1.majorVersion == v2.majorVersion)
? v1.minorVersion - v2.minorVersion
: v1.majorVersion - v2.majorVersion;
}
/**
* Compares two string objects representing guide version
*
* @param v1 string representing guide version
* @param v2 string representing guide version
* @return
*/
public static int compare(String v1, String v2) {
FDVersion gv1 = new FDVersion(v1);
FDVersion gv2 = new FDVersion(v2);
return compare(gv1, gv2);
}
/**
* Returns {@link FDVersion} object as string
*
* @return string representation of guide version object
*/
public String toString() {
return String.valueOf(majorVersion) + "." + String.valueOf(minorVersion);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy