VersionRange { public VersionRange intersect(VersionRange r) { final Version newMinimumVersion; final boolean newMinimumExclusive; int minCompare = minimumVersion.compareTo(r.getMinimumVersion()); if (minCompare > 0) { newMinimumVersion = minimumVersion; newMinimumExclusive = minimumExclusive; } else if (minCompare < 0) { newMinimumVersion = r.getMinimumVersion(); newMinimumExclusive = r.isMinimumExclusive(); } else { newMinimumVersion = minimumVersion; newMinimumExclusive = (minimumExclusive || r.isMinimumExclusive()); } final Version newMaximumVersion; final boolean newMaximumExclusive; if (maximumVersion == null) { newMaximumVersion = r.getMaximumVersion(); newMaximumExclusive = r.isMaximumExclusive(); } else if (r.getMaximumVersion() == null) { newMaximumVersion = maximumVersion; newMaximumExclusive = maximumExclusive; } else { int maxCompare = maximumVersion.compareTo(r.getMaximumVersion()); if (maxCompare < 0) { newMaximumVersion = maximumVersion; newMaximumExclusive = maximumExclusive; } else if (maxCompare > 0) { newMaximumVersion = r.getMaximumVersion(); newMaximumExclusive = r.isMaximumExclusive(); } else { newMaximumVersion = maximumVersion; newMaximumExclusive = (maximumExclusive || r.isMaximumExclusive()); } } VersionRange result; if (isRangeValid(newMinimumVersion, newMinimumExclusive, newMaximumVersion, newMaximumExclusive)) { result = new VersionRange(newMaximumVersion, newMaximumExclusive, newMinimumVersion, newMinimumExclusive); } else { result = null; } return result; } VersionRange(String version);  VersionRange(String version, boolean exactVersion); private  VersionRange(Version maximumVersion,
                         boolean maximumExclusive,
                         Version minimumVersion,
                         boolean minimumExclusive); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object other); Version getExactVersion(); Version getMaximumVersion(); Version getMinimumVersion(); boolean isMaximumExclusive(); boolean isMaximumUnbounded(); boolean isMinimumExclusive(); boolean matches(Version version); boolean isExactVersion(); VersionRange intersect(VersionRange r); static VersionRange parseVersionRange(String s); static VersionRange parseVersionRange(String s, boolean exactVersion);  }
@Test public void testIntersectVersionRange_Invalid1() { VersionRange v1 = new VersionRange("[1.0.0,2.0.0]"); VersionRange v2 = new VersionRange("(2.0.0,3.0.0]"); VersionRange result = v1.intersect(v2); assertNull(result); }
@Test public void testIntersectVersionRange_Invalid2() { VersionRange v1 = new VersionRange("[1.0.0,2.0.0)"); VersionRange v2 = new VersionRange("[2.0.0,3.0.0]"); VersionRange result = v1.intersect(v2); assertNull(result); }
@Test public void testIntersectVersionRange_Invalid3() { VersionRange v1 = new VersionRange("[1.0.0,1.0.0]"); VersionRange v2 = new VersionRange("[2.0.0,2.0.0]"); VersionRange result = v1.intersect(v2); assertNull(result); }