@Test public void testValidSyntax() throws Exception { try { VersionRange.parse("(1.1.0.0)"); fail("Invalid syntax not failed"); } catch (IllegalArgumentException e) { } try { VersionRange.parse("1.1.0.0,1.1)]"); fail("Invalid syntax not failed"); } catch (IllegalArgumentException e) { } try { VersionRange.parse("(1.1.0.0-1.1)"); fail("Invalid syntax not failed"); } catch (IllegalArgumentException e) { } try { VersionRange.parse("1.1.0.0,1.1"); fail("Invalid syntax not failed"); } catch (IllegalArgumentException e) { } try { VersionRange.parse("( , 1.1)"); fail("Invalid syntax not failed"); } catch (IllegalArgumentException e) { } }
public static VersionRange parse(String range) { Assertions.blankCheck(range, "range"); int idx = range.indexOf(ENDPOINT_DELIMITER); if (idx > 1 && idx == range.lastIndexOf(ENDPOINT_DELIMITER)) { String vlo = range.substring(0, idx).trim(); String vhi = range.substring(idx + 1).trim(); boolean isLowInclusive = true; boolean isHighInclusive = true; if (vlo.charAt(0) == LEFT_OPEN) { isLowInclusive = false; } else if (vlo.charAt(0) != LEFT_CLOSED) { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } vlo = vlo.substring(1).trim(); if (vhi.charAt(vhi.length() - 1) == RIGHT_OPEN) { isHighInclusive = false; } else if (vhi.charAt(vhi.length() - 1) != RIGHT_CLOSED) { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } vhi = vhi.substring(0, vhi.length() - 1).trim(); return new VersionRange(parseVersion(vlo, range), isLowInclusive, parseVersion(vhi, range), isHighInclusive); } else if (idx == -1) { return new VersionRange(VersionRange.parseVersion(range.trim(), range), true, null, false); } else { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } }
VersionRange { public static VersionRange parse(String range) { Assertions.blankCheck(range, "range"); int idx = range.indexOf(ENDPOINT_DELIMITER); if (idx > 1 && idx == range.lastIndexOf(ENDPOINT_DELIMITER)) { String vlo = range.substring(0, idx).trim(); String vhi = range.substring(idx + 1).trim(); boolean isLowInclusive = true; boolean isHighInclusive = true; if (vlo.charAt(0) == LEFT_OPEN) { isLowInclusive = false; } else if (vlo.charAt(0) != LEFT_CLOSED) { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } vlo = vlo.substring(1).trim(); if (vhi.charAt(vhi.length() - 1) == RIGHT_OPEN) { isHighInclusive = false; } else if (vhi.charAt(vhi.length() - 1) != RIGHT_CLOSED) { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } vhi = vhi.substring(0, vhi.length() - 1).trim(); return new VersionRange(parseVersion(vlo, range), isLowInclusive, parseVersion(vhi, range), isHighInclusive); } else if (idx == -1) { return new VersionRange(VersionRange.parseVersion(range.trim(), range), true, null, false); } else { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } } }
VersionRange { public static VersionRange parse(String range) { Assertions.blankCheck(range, "range"); int idx = range.indexOf(ENDPOINT_DELIMITER); if (idx > 1 && idx == range.lastIndexOf(ENDPOINT_DELIMITER)) { String vlo = range.substring(0, idx).trim(); String vhi = range.substring(idx + 1).trim(); boolean isLowInclusive = true; boolean isHighInclusive = true; if (vlo.charAt(0) == LEFT_OPEN) { isLowInclusive = false; } else if (vlo.charAt(0) != LEFT_CLOSED) { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } vlo = vlo.substring(1).trim(); if (vhi.charAt(vhi.length() - 1) == RIGHT_OPEN) { isHighInclusive = false; } else if (vhi.charAt(vhi.length() - 1) != RIGHT_CLOSED) { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } vhi = vhi.substring(0, vhi.length() - 1).trim(); return new VersionRange(parseVersion(vlo, range), isLowInclusive, parseVersion(vhi, range), isHighInclusive); } else if (idx == -1) { return new VersionRange(VersionRange.parseVersion(range.trim(), range), true, null, false); } else { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } } VersionRange(Version low, boolean isLowInclusive, Version high, boolean isHighInclusive); }
VersionRange { public static VersionRange parse(String range) { Assertions.blankCheck(range, "range"); int idx = range.indexOf(ENDPOINT_DELIMITER); if (idx > 1 && idx == range.lastIndexOf(ENDPOINT_DELIMITER)) { String vlo = range.substring(0, idx).trim(); String vhi = range.substring(idx + 1).trim(); boolean isLowInclusive = true; boolean isHighInclusive = true; if (vlo.charAt(0) == LEFT_OPEN) { isLowInclusive = false; } else if (vlo.charAt(0) != LEFT_CLOSED) { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } vlo = vlo.substring(1).trim(); if (vhi.charAt(vhi.length() - 1) == RIGHT_OPEN) { isHighInclusive = false; } else if (vhi.charAt(vhi.length() - 1) != RIGHT_CLOSED) { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } vhi = vhi.substring(0, vhi.length() - 1).trim(); return new VersionRange(parseVersion(vlo, range), isLowInclusive, parseVersion(vhi, range), isHighInclusive); } else if (idx == -1) { return new VersionRange(VersionRange.parseVersion(range.trim(), range), true, null, false); } else { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } } VersionRange(Version low, boolean isLowInclusive, Version high, boolean isHighInclusive); static VersionRange parse(String range); Version getFloor(); boolean isFloorInclusive(); Version getCeiling(); boolean isCeilingInclusive(); boolean isInRange(Version version); boolean isExact(); boolean isEmpty(); boolean equals(Object obj); @Override int hashCode(); String toString(); }
VersionRange { public static VersionRange parse(String range) { Assertions.blankCheck(range, "range"); int idx = range.indexOf(ENDPOINT_DELIMITER); if (idx > 1 && idx == range.lastIndexOf(ENDPOINT_DELIMITER)) { String vlo = range.substring(0, idx).trim(); String vhi = range.substring(idx + 1).trim(); boolean isLowInclusive = true; boolean isHighInclusive = true; if (vlo.charAt(0) == LEFT_OPEN) { isLowInclusive = false; } else if (vlo.charAt(0) != LEFT_CLOSED) { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } vlo = vlo.substring(1).trim(); if (vhi.charAt(vhi.length() - 1) == RIGHT_OPEN) { isHighInclusive = false; } else if (vhi.charAt(vhi.length() - 1) != RIGHT_CLOSED) { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } vhi = vhi.substring(0, vhi.length() - 1).trim(); return new VersionRange(parseVersion(vlo, range), isLowInclusive, parseVersion(vhi, range), isHighInclusive); } else if (idx == -1) { return new VersionRange(VersionRange.parseVersion(range.trim(), range), true, null, false); } else { throw new IllegalArgumentException("invalid range \"" + range + "\": invalid format"); } } VersionRange(Version low, boolean isLowInclusive, Version high, boolean isHighInclusive); static VersionRange parse(String range); Version getFloor(); boolean isFloorInclusive(); Version getCeiling(); boolean isCeilingInclusive(); boolean isInRange(Version version); boolean isExact(); boolean isEmpty(); boolean equals(Object obj); @Override int hashCode(); String toString(); static final char LEFT_OPEN; static final char LEFT_CLOSED; static final char RIGHT_OPEN; static final char RIGHT_CLOSED; }