Add methods for checking major and minor compatibility
This commit is contained in:
parent
9c72603fb9
commit
f6abcf5dd7
@ -560,6 +560,39 @@ public class Version implements Comparable<Version> {
|
|||||||
return compareTo(other) <= 0;
|
return compareTo(other) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this version is compatible with the
|
||||||
|
* other version in terms of their major versions.
|
||||||
|
*
|
||||||
|
* When checking compatibility no assumptions
|
||||||
|
* are made about the versions' precedence.
|
||||||
|
*
|
||||||
|
* @param other the other version to check with
|
||||||
|
* @return {@code true} if this version is compatible with
|
||||||
|
* the other version or {@code false} otherwise
|
||||||
|
* @since 0.10.0
|
||||||
|
*/
|
||||||
|
public boolean isMajorVersionCompatible(Version other) {
|
||||||
|
return this.getMajorVersion() == other.getMajorVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this version is compatible with the
|
||||||
|
* other version in terms of their minor versions.
|
||||||
|
*
|
||||||
|
* When checking compatibility no assumptions
|
||||||
|
* are made about the versions' precedence.
|
||||||
|
*
|
||||||
|
* @param other the other version to check with
|
||||||
|
* @return {@code true} if this version is compatible with
|
||||||
|
* the other version or {@code false} otherwise
|
||||||
|
* @since 0.10.0
|
||||||
|
*/
|
||||||
|
public boolean isMinorVersionCompatible(Version other) {
|
||||||
|
return this.getMajorVersion() == other.getMajorVersion()
|
||||||
|
&& this.getMinorVersion() == other.getMinorVersion();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this version equals the other version.
|
* Checks if this version equals the other version.
|
||||||
*
|
*
|
||||||
|
@ -314,6 +314,24 @@ public class VersionTest {
|
|||||||
assertTrue(v.satisfies(gte("1.0.0").and(lt("2.0.0"))));
|
assertTrue(v.satisfies(gte("1.0.0").and(lt("2.0.0"))));
|
||||||
assertFalse(v.satisfies(gte("2.0.0").and(lt("3.0.0"))));
|
assertFalse(v.satisfies(gte("2.0.0").and(lt("3.0.0"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCheckIfMajorVersionCompatible() {
|
||||||
|
Version v1 = Version.valueOf("1.0.0");
|
||||||
|
Version v2 = Version.valueOf("1.2.3");
|
||||||
|
Version v3 = Version.valueOf("2.0.0");
|
||||||
|
assertTrue(v1.isMajorVersionCompatible(v2));
|
||||||
|
assertFalse(v1.isMajorVersionCompatible(v3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCheckIfMinorVersionCompatible() {
|
||||||
|
Version v1 = Version.valueOf("1.1.1");
|
||||||
|
Version v2 = Version.valueOf("1.1.2");
|
||||||
|
Version v3 = Version.valueOf("1.2.3");
|
||||||
|
assertTrue(v1.isMinorVersionCompatible(v2));
|
||||||
|
assertFalse(v1.isMinorVersionCompatible(v3));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EqualsMethodTest {
|
public static class EqualsMethodTest {
|
||||||
|
Loading…
Reference in New Issue
Block a user