@Test public void testSubstitutables() { Assert.assertTrue (new Version("0" ).isSubstitutableFor(new Version("beta" ))); Assert.assertTrue (new Version("1" ).isSubstitutableFor(new Version("beta" ))); Assert.assertTrue (new Version("0" ).isSubstitutableFor(new Version("0" ))); Assert.assertTrue (new Version("1" ).isSubstitutableFor(new Version("0" ))); Assert.assertTrue (new Version("1" ).isSubstitutableFor(new Version("1" ))); Assert.assertTrue (new Version("1.2.3.4.5").isSubstitutableFor(new Version("1" ))); Assert.assertTrue (new Version("2.1.rc" ).isSubstitutableFor(new Version("2.1.beta3"))); Assert.assertTrue (new Version("2.1.rc2" ).isSubstitutableFor(new Version("2.1.beta3"))); Assert.assertTrue (new Version("2.1" ).isSubstitutableFor(new Version("2.1.beta" ))); Assert.assertTrue (new Version("2.1" ).isSubstitutableFor(new Version("2.1.beta3"))); Assert.assertTrue (new Version("2.2" ).isSubstitutableFor(new Version("2.1.beta3"))); Assert.assertTrue (new Version("2.1.beta3").isSubstitutableFor(new Version("2.1.beta" ))); Assert.assertTrue (new Version("2.1.beta3").isSubstitutableFor(new Version("2.1.beta3"))); Assert.assertTrue (new Version("1.2" ).isSubstitutableFor(new Version("1.beta" ))); Assert.assertTrue (new Version("1.2.alpha").isSubstitutableFor(new Version("1.beta" ))); Assert.assertTrue (new Version("1.2.beta" ).isSubstitutableFor(new Version("1.beta" ))); Assert.assertTrue (new Version("1.2.beta1").isSubstitutableFor(new Version("1.beta" ))); Assert.assertTrue (new Version("1.2" ).isSubstitutableFor(new Version("1.beta1" ))); Assert.assertTrue (new Version("1.2.alpha").isSubstitutableFor(new Version("1.beta1" ))); Assert.assertTrue (new Version("1.2.beta1").isSubstitutableFor(new Version("1.beta1" ))); Assert.assertTrue (new Version("1.2.beta2").isSubstitutableFor(new Version("1.2.beta1"))); Assert.assertTrue (new Version("1.2.beta" ).isSubstitutableFor(new Version("1.2.alpha"))); Assert.assertTrue (new Version("beta" ).isSubstitutableFor(new Version("alpha" ))); Assert.assertFalse(new Version("beta").isSubstitutableFor(new Version("0"))); Assert.assertFalse(new Version("beta").isSubstitutableFor(new Version("1"))); Assert.assertFalse(new Version("0").isSubstitutableFor(new Version("1"))); Assert.assertFalse(new Version("1").isSubstitutableFor(new Version("1.2.3.4.5"))); Assert.assertFalse(new Version("2.1.beta3").isSubstitutableFor(new Version("2.1.rc"))); Assert.assertFalse(new Version("2.1.beta3").isSubstitutableFor(new Version("2.1.rc2"))); Assert.assertFalse(new Version("2.1.beta").isSubstitutableFor(new Version("2.1"))); Assert.assertFalse(new Version("2.1.beta3").isSubstitutableFor(new Version("2.1"))); Assert.assertFalse(new Version("2.1.beta3").isSubstitutableFor(new Version("2.2"))); Assert.assertFalse(new Version("2.1.beta").isSubstitutableFor(new Version("2.1.beta3"))); Assert.assertFalse(new Version("1.beta").isSubstitutableFor(new Version("1.2"))); Assert.assertFalse(new Version("1.beta").isSubstitutableFor(new Version("1.2.alpha"))); Assert.assertFalse(new Version("1.beta").isSubstitutableFor(new Version("1.2.beta"))); Assert.assertFalse(new Version("1.beta").isSubstitutableFor(new Version("1.2.beta1"))); Assert.assertFalse(new Version("1.beta1").isSubstitutableFor(new Version("1.2"))); Assert.assertFalse(new Version("1.beta1").isSubstitutableFor(new Version("1.2.alpha"))); Assert.assertFalse(new Version("1.beta1").isSubstitutableFor(new Version("1.2.beta1"))); Assert.assertFalse(new Version("1.2.beta1").isSubstitutableFor(new Version("1.2.beta2"))); Assert.assertFalse(new Version("1.2.alpha").isSubstitutableFor(new Version("1.2.beta"))); Assert.assertFalse(new Version("alpha").isSubstitutableFor(new Version("beta"))); }
public boolean isSubstitutableFor(Version that) { if (this.equals(that)) { return true; } int[] thisInts = this.getIntArray(); int[] thatInts = that.getIntArray(); int cThis = thisInts.length; int cThisGA = thisInts[cThis - 1] < 0 ? cThis - 1 : cThis >= 2 && thisInts[cThis - 2] < 0 ? cThis - 2 : cThis; int cThat = thatInts.length; int cThatGA = thatInts[cThat - 1] < 0 ? cThat - 1 : cThat >= 2 && thatInts[cThat - 2] < 0 ? cThat - 2 : cThat; int iLast = Math.min(cThis, cThat) - 1; int iLastGA = Math.min(cThisGA, cThatGA) - 1; for (int i = 0; i < iLastGA; ++i) { if (thisInts[i] != thatInts[i]) { return false; } } int nVerDif = iLastGA >= 0 ? thisInts[iLastGA] - thatInts[iLastGA] : 0; if (nVerDif < 0) { return false; } if (nVerDif > 0) { return cThisGA >= cThatGA; } if (cThisGA > cThatGA) { for (int i = cThatGA; i < cThisGA; ++i) { if (thisInts[i] > 0) { return true; } } } else if (cThisGA < cThatGA) { for (int i = cThisGA; i < cThatGA; ++i) { if (thatInts[i] > 0) { return false; } } } boolean fThisGA = cThis == cThisGA; boolean fThatGA = cThat == cThatGA; if (!fThisGA || !fThatGA) { if (fThisGA ^ fThatGA) { return fThisGA; } int cThisNonGA = cThis - cThisGA; int cThatNonGA = cThat - cThatGA; int cSharedNonGA = Math.min(cThisNonGA, cThatNonGA); assert cSharedNonGA == 1 || cSharedNonGA == 2; for (int of = 0; of < cSharedNonGA; ++of) { nVerDif = thisInts[cThisGA + of] - thatInts[cThatGA + of]; if (nVerDif < 0) { return false; } else if (nVerDif > 0) { return true; } } if (cThisNonGA != cThatNonGA) { return cThisNonGA > cThatNonGA; } } return true; }
Version implements Comparable<Version> { public boolean isSubstitutableFor(Version that) { if (this.equals(that)) { return true; } int[] thisInts = this.getIntArray(); int[] thatInts = that.getIntArray(); int cThis = thisInts.length; int cThisGA = thisInts[cThis - 1] < 0 ? cThis - 1 : cThis >= 2 && thisInts[cThis - 2] < 0 ? cThis - 2 : cThis; int cThat = thatInts.length; int cThatGA = thatInts[cThat - 1] < 0 ? cThat - 1 : cThat >= 2 && thatInts[cThat - 2] < 0 ? cThat - 2 : cThat; int iLast = Math.min(cThis, cThat) - 1; int iLastGA = Math.min(cThisGA, cThatGA) - 1; for (int i = 0; i < iLastGA; ++i) { if (thisInts[i] != thatInts[i]) { return false; } } int nVerDif = iLastGA >= 0 ? thisInts[iLastGA] - thatInts[iLastGA] : 0; if (nVerDif < 0) { return false; } if (nVerDif > 0) { return cThisGA >= cThatGA; } if (cThisGA > cThatGA) { for (int i = cThatGA; i < cThisGA; ++i) { if (thisInts[i] > 0) { return true; } } } else if (cThisGA < cThatGA) { for (int i = cThisGA; i < cThatGA; ++i) { if (thatInts[i] > 0) { return false; } } } boolean fThisGA = cThis == cThisGA; boolean fThatGA = cThat == cThatGA; if (!fThisGA || !fThatGA) { if (fThisGA ^ fThatGA) { return fThisGA; } int cThisNonGA = cThis - cThisGA; int cThatNonGA = cThat - cThatGA; int cSharedNonGA = Math.min(cThisNonGA, cThatNonGA); assert cSharedNonGA == 1 || cSharedNonGA == 2; for (int of = 0; of < cSharedNonGA; ++of) { nVerDif = thisInts[cThisGA + of] - thatInts[cThatGA + of]; if (nVerDif < 0) { return false; } else if (nVerDif > 0) { return true; } } if (cThisNonGA != cThatNonGA) { return cThisNonGA > cThatNonGA; } } return true; } }
Version implements Comparable<Version> { public boolean isSubstitutableFor(Version that) { if (this.equals(that)) { return true; } int[] thisInts = this.getIntArray(); int[] thatInts = that.getIntArray(); int cThis = thisInts.length; int cThisGA = thisInts[cThis - 1] < 0 ? cThis - 1 : cThis >= 2 && thisInts[cThis - 2] < 0 ? cThis - 2 : cThis; int cThat = thatInts.length; int cThatGA = thatInts[cThat - 1] < 0 ? cThat - 1 : cThat >= 2 && thatInts[cThat - 2] < 0 ? cThat - 2 : cThat; int iLast = Math.min(cThis, cThat) - 1; int iLastGA = Math.min(cThisGA, cThatGA) - 1; for (int i = 0; i < iLastGA; ++i) { if (thisInts[i] != thatInts[i]) { return false; } } int nVerDif = iLastGA >= 0 ? thisInts[iLastGA] - thatInts[iLastGA] : 0; if (nVerDif < 0) { return false; } if (nVerDif > 0) { return cThisGA >= cThatGA; } if (cThisGA > cThatGA) { for (int i = cThatGA; i < cThisGA; ++i) { if (thisInts[i] > 0) { return true; } } } else if (cThisGA < cThatGA) { for (int i = cThisGA; i < cThatGA; ++i) { if (thatInts[i] > 0) { return false; } } } boolean fThisGA = cThis == cThisGA; boolean fThatGA = cThat == cThatGA; if (!fThisGA || !fThatGA) { if (fThisGA ^ fThatGA) { return fThisGA; } int cThisNonGA = cThis - cThisGA; int cThatNonGA = cThat - cThatGA; int cSharedNonGA = Math.min(cThisNonGA, cThatNonGA); assert cSharedNonGA == 1 || cSharedNonGA == 2; for (int of = 0; of < cSharedNonGA; ++of) { nVerDif = thisInts[cThisGA + of] - thatInts[cThatGA + of]; if (nVerDif < 0) { return false; } else if (nVerDif > 0) { return true; } } if (cThisNonGA != cThatNonGA) { return cThisNonGA > cThatNonGA; } } return true; } Version(String sLiteral);  Version(int[] aiParts, String sBuild); }
Version implements Comparable<Version> { public boolean isSubstitutableFor(Version that) { if (this.equals(that)) { return true; } int[] thisInts = this.getIntArray(); int[] thatInts = that.getIntArray(); int cThis = thisInts.length; int cThisGA = thisInts[cThis - 1] < 0 ? cThis - 1 : cThis >= 2 && thisInts[cThis - 2] < 0 ? cThis - 2 : cThis; int cThat = thatInts.length; int cThatGA = thatInts[cThat - 1] < 0 ? cThat - 1 : cThat >= 2 && thatInts[cThat - 2] < 0 ? cThat - 2 : cThat; int iLast = Math.min(cThis, cThat) - 1; int iLastGA = Math.min(cThisGA, cThatGA) - 1; for (int i = 0; i < iLastGA; ++i) { if (thisInts[i] != thatInts[i]) { return false; } } int nVerDif = iLastGA >= 0 ? thisInts[iLastGA] - thatInts[iLastGA] : 0; if (nVerDif < 0) { return false; } if (nVerDif > 0) { return cThisGA >= cThatGA; } if (cThisGA > cThatGA) { for (int i = cThatGA; i < cThisGA; ++i) { if (thisInts[i] > 0) { return true; } } } else if (cThisGA < cThatGA) { for (int i = cThisGA; i < cThatGA; ++i) { if (thatInts[i] > 0) { return false; } } } boolean fThisGA = cThis == cThisGA; boolean fThatGA = cThat == cThatGA; if (!fThisGA || !fThatGA) { if (fThisGA ^ fThatGA) { return fThisGA; } int cThisNonGA = cThis - cThisGA; int cThatNonGA = cThat - cThatGA; int cSharedNonGA = Math.min(cThisNonGA, cThatNonGA); assert cSharedNonGA == 1 || cSharedNonGA == 2; for (int of = 0; of < cSharedNonGA; ++of) { nVerDif = thisInts[cThisGA + of] - thatInts[cThatGA + of]; if (nVerDif < 0) { return false; } else if (nVerDif > 0) { return true; } } if (cThisNonGA != cThatNonGA) { return cThisNonGA > cThatNonGA; } } return true; } Version(String sLiteral);  Version(int[] aiParts, String sBuild); boolean isGARelease(); int getReleaseCategory(); String getReleaseCategoryString(); boolean isSubstitutableFor(Version that); boolean isSameAs(Version that); Version normalize(); @Override int compareTo(Version that); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }
Version implements Comparable<Version> { public boolean isSubstitutableFor(Version that) { if (this.equals(that)) { return true; } int[] thisInts = this.getIntArray(); int[] thatInts = that.getIntArray(); int cThis = thisInts.length; int cThisGA = thisInts[cThis - 1] < 0 ? cThis - 1 : cThis >= 2 && thisInts[cThis - 2] < 0 ? cThis - 2 : cThis; int cThat = thatInts.length; int cThatGA = thatInts[cThat - 1] < 0 ? cThat - 1 : cThat >= 2 && thatInts[cThat - 2] < 0 ? cThat - 2 : cThat; int iLast = Math.min(cThis, cThat) - 1; int iLastGA = Math.min(cThisGA, cThatGA) - 1; for (int i = 0; i < iLastGA; ++i) { if (thisInts[i] != thatInts[i]) { return false; } } int nVerDif = iLastGA >= 0 ? thisInts[iLastGA] - thatInts[iLastGA] : 0; if (nVerDif < 0) { return false; } if (nVerDif > 0) { return cThisGA >= cThatGA; } if (cThisGA > cThatGA) { for (int i = cThatGA; i < cThisGA; ++i) { if (thisInts[i] > 0) { return true; } } } else if (cThisGA < cThatGA) { for (int i = cThisGA; i < cThatGA; ++i) { if (thatInts[i] > 0) { return false; } } } boolean fThisGA = cThis == cThisGA; boolean fThatGA = cThat == cThatGA; if (!fThisGA || !fThatGA) { if (fThisGA ^ fThatGA) { return fThisGA; } int cThisNonGA = cThis - cThisGA; int cThatNonGA = cThat - cThatGA; int cSharedNonGA = Math.min(cThisNonGA, cThatNonGA); assert cSharedNonGA == 1 || cSharedNonGA == 2; for (int of = 0; of < cSharedNonGA; ++of) { nVerDif = thisInts[cThisGA + of] - thatInts[cThatGA + of]; if (nVerDif < 0) { return false; } else if (nVerDif > 0) { return true; } } if (cThisNonGA != cThatNonGA) { return cThisNonGA > cThatNonGA; } } return true; } Version(String sLiteral);  Version(int[] aiParts, String sBuild); boolean isGARelease(); int getReleaseCategory(); String getReleaseCategoryString(); boolean isSubstitutableFor(Version that); boolean isSameAs(Version that); Version normalize(); @Override int compareTo(Version that); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }