@Test public void testExpect() { FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" ); assertEquals( "maven-test-plugin-1.8.3", parser.getName() ); assertEquals( "jar", parser.getExtension() ); assertEquals( "maven-test-plugin", parser.expect( "maven-test-plugin" ) ); assertEquals( "1.8.3", parser.expect( "1.8.3" ) ); assertNull( parser.expect( "jar" ) ); }
protected String expect( String expected ) { String value = null; if ( name.startsWith( expected, offset ) ) { value = expected; } else if ( VersionUtil.isGenericSnapshot( expected ) ) { String version = name.substring( offset ); int leadingLength = expected.length() - 9; if ( leadingLength > 0 && version.startsWith( expected.substring( 0, leadingLength ) ) && version.length() > leadingLength ) { Matcher m = SNAPSHOT_PATTERN.matcher( version.substring( leadingLength + 1 ) ); if ( m.matches() ) { value = version.substring( 0, leadingLength + 1 ) + m.group( 1 ); } } } if ( value != null ) { int seperatorOffset = offset + value.length(); if ( seperatorOffset >= name.length() ) { offset = name.length(); return value; } char seperatorChar = name.charAt( seperatorOffset ); if ( ( seperatorChar == '-' ) || ( seperatorChar == '.' ) ) { offset = seperatorOffset + 1; return value; } } return null; }
FilenameParser { protected String expect( String expected ) { String value = null; if ( name.startsWith( expected, offset ) ) { value = expected; } else if ( VersionUtil.isGenericSnapshot( expected ) ) { String version = name.substring( offset ); int leadingLength = expected.length() - 9; if ( leadingLength > 0 && version.startsWith( expected.substring( 0, leadingLength ) ) && version.length() > leadingLength ) { Matcher m = SNAPSHOT_PATTERN.matcher( version.substring( leadingLength + 1 ) ); if ( m.matches() ) { value = version.substring( 0, leadingLength + 1 ) + m.group( 1 ); } } } if ( value != null ) { int seperatorOffset = offset + value.length(); if ( seperatorOffset >= name.length() ) { offset = name.length(); return value; } char seperatorChar = name.charAt( seperatorOffset ); if ( ( seperatorChar == '-' ) || ( seperatorChar == '.' ) ) { offset = seperatorOffset + 1; return value; } } return null; } }
FilenameParser { protected String expect( String expected ) { String value = null; if ( name.startsWith( expected, offset ) ) { value = expected; } else if ( VersionUtil.isGenericSnapshot( expected ) ) { String version = name.substring( offset ); int leadingLength = expected.length() - 9; if ( leadingLength > 0 && version.startsWith( expected.substring( 0, leadingLength ) ) && version.length() > leadingLength ) { Matcher m = SNAPSHOT_PATTERN.matcher( version.substring( leadingLength + 1 ) ); if ( m.matches() ) { value = version.substring( 0, leadingLength + 1 ) + m.group( 1 ); } } } if ( value != null ) { int seperatorOffset = offset + value.length(); if ( seperatorOffset >= name.length() ) { offset = name.length(); return value; } char seperatorChar = name.charAt( seperatorOffset ); if ( ( seperatorChar == '-' ) || ( seperatorChar == '.' ) ) { offset = seperatorOffset + 1; return value; } } return null; } FilenameParser( String filename ); }
FilenameParser { protected String expect( String expected ) { String value = null; if ( name.startsWith( expected, offset ) ) { value = expected; } else if ( VersionUtil.isGenericSnapshot( expected ) ) { String version = name.substring( offset ); int leadingLength = expected.length() - 9; if ( leadingLength > 0 && version.startsWith( expected.substring( 0, leadingLength ) ) && version.length() > leadingLength ) { Matcher m = SNAPSHOT_PATTERN.matcher( version.substring( leadingLength + 1 ) ); if ( m.matches() ) { value = version.substring( 0, leadingLength + 1 ) + m.group( 1 ); } } } if ( value != null ) { int seperatorOffset = offset + value.length(); if ( seperatorOffset >= name.length() ) { offset = name.length(); return value; } char seperatorChar = name.charAt( seperatorOffset ); if ( ( seperatorChar == '-' ) || ( seperatorChar == '.' ) ) { offset = seperatorOffset + 1; return value; } } return null; } FilenameParser( String filename ); void reset(); String next(); String getExtension(); String remaining(); String nextNonVersion(); }
FilenameParser { protected String expect( String expected ) { String value = null; if ( name.startsWith( expected, offset ) ) { value = expected; } else if ( VersionUtil.isGenericSnapshot( expected ) ) { String version = name.substring( offset ); int leadingLength = expected.length() - 9; if ( leadingLength > 0 && version.startsWith( expected.substring( 0, leadingLength ) ) && version.length() > leadingLength ) { Matcher m = SNAPSHOT_PATTERN.matcher( version.substring( leadingLength + 1 ) ); if ( m.matches() ) { value = version.substring( 0, leadingLength + 1 ) + m.group( 1 ); } } } if ( value != null ) { int seperatorOffset = offset + value.length(); if ( seperatorOffset >= name.length() ) { offset = name.length(); return value; } char seperatorChar = name.charAt( seperatorOffset ); if ( ( seperatorChar == '-' ) || ( seperatorChar == '.' ) ) { offset = seperatorOffset + 1; return value; } } return null; } FilenameParser( String filename ); void reset(); String next(); String getExtension(); String remaining(); String nextNonVersion();  }