GenericVersionScheme implements VersionScheme { public VersionConstraint parseVersionConstraint( final String constraint ) throws InvalidVersionSpecificationException { GenericVersionConstraint result = new GenericVersionConstraint(); String process = constraint; while ( process.startsWith( "[" ) || process.startsWith( "(" ) ) { int index1 = process.indexOf( ')' ); int index2 = process.indexOf( ']' ); int index = index2; if ( index2 < 0 || ( index1 >= 0 && index1 < index2 ) ) { index = index1; } if ( index < 0 ) { throw new InvalidVersionSpecificationException( constraint, "Unbounded version range " + constraint ); } VersionRange range = parseVersionRange( process.substring( 0, index + 1 ) ); result.addRange( range ); process = process.substring( index + 1 ).trim(); if ( process.length() > 0 && process.startsWith( "," ) ) { process = process.substring( 1 ).trim(); } } if ( process.length() > 0 && !result.getRanges().isEmpty() ) { throw new InvalidVersionSpecificationException( constraint, "Invalid version range " + constraint + ", expected [ or ( but got " + process ); } if ( result.getRanges().isEmpty() ) { result.setVersion( parseVersion( constraint ) ); } return result; } GenericVersionScheme(); Version parseVersion( final String version ); VersionRange parseVersionRange( final String range ); VersionConstraint parseVersionConstraint( final String constraint ); @Override boolean equals( final Object obj ); @Override int hashCode();  }
@Test public void testEnumeratedVersions() throws InvalidVersionSpecificationException { VersionConstraint c = scheme.parseVersionConstraint( "1.0" ); assertEquals( "1.0", c.getVersion().toString() ); assertTrue( c.containsVersion( new GenericVersion( "1.0" ) ) ); c = scheme.parseVersionConstraint( "[1.0]" ); assertEquals( null, c.getVersion() ); assertTrue( c.containsVersion( new GenericVersion( "1.0" ) ) ); c = scheme.parseVersionConstraint( "[1.0],[2.0]" ); assertTrue( c.containsVersion( new GenericVersion( "1.0" ) ) ); assertTrue( c.containsVersion( new GenericVersion( "2.0" ) ) ); c = scheme.parseVersionConstraint( "[1.0],[2.0],[3.0]" ); assertContains( c, "1.0", "2.0", "3.0" ); assertNotContains( c, "1.5" ); c = scheme.parseVersionConstraint( "[1,3),(3,5)" ); assertContains( c, "1", "2", "4" ); assertNotContains( c, "3", "5" ); c = scheme.parseVersionConstraint( "[1,3),(3,)" ); assertContains( c, "1", "2", "4" ); assertNotContains( c, "3" ); }