Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSHARED-1104] Four element pattern may be GATV or GATC #29

Merged
merged 6 commits into from
Jul 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
Expand Down Expand Up @@ -364,11 +365,11 @@ private static Pattern compile( String pattern )
}
else if ( tokens.length == 4 )
{
// trivial, full pattern w/o classifier: G:A:T:V
// trivial, full pattern w/ version or classifier: G:A:T:V or G:A:T:C
patterns.add( toPattern( tokens[0], Coordinate.GROUP_ID ) );
patterns.add( toPattern( tokens[1], Coordinate.ARTIFACT_ID ) );
patterns.add( toPattern( tokens[2], Coordinate.TYPE ) );
patterns.add( toPattern( tokens[3], Coordinate.BASE_VERSION ) );
patterns.add( toPattern( tokens[3], Coordinate.BASE_VERSION, Coordinate.CLASSIFIER ) );
}
else if ( tokens.length == 3 )
{
Expand All @@ -388,31 +389,25 @@ else if ( tokens.length == 3 )
}
else if ( ANY.equals( tokens[0] ) && ANY.equals( tokens[1] ) )
{
patterns.add( new CoordinateMatchingPattern( pattern, tokens[2],
EnumSet.of( Coordinate.TYPE, Coordinate.CLASSIFIER ) ) );
patterns.add( toPattern( pattern, tokens[2], Coordinate.TYPE, Coordinate.CLASSIFIER ) );
}
else if ( ANY.equals( tokens[0] ) && ANY.equals( tokens[2] ) )
{
patterns.add( new CoordinateMatchingPattern( pattern, tokens[1],
EnumSet.of( Coordinate.ARTIFACT_ID, Coordinate.TYPE ) ) );
patterns.add( toPattern( pattern, tokens[1], Coordinate.ARTIFACT_ID, Coordinate.TYPE ) );
}
else if ( ANY.equals( tokens[0] ) )
{
patterns.add( new CoordinateMatchingPattern( pattern, tokens[1],
EnumSet.of( Coordinate.GROUP_ID, Coordinate.ARTIFACT_ID ) ) );
patterns.add( new CoordinateMatchingPattern( pattern, tokens[2],
EnumSet.of( Coordinate.TYPE, Coordinate.CLASSIFIER ) ) );
patterns.add( toPattern( pattern, tokens[1], Coordinate.GROUP_ID, Coordinate.ARTIFACT_ID ) );
patterns.add( toPattern( pattern, tokens[2], Coordinate.TYPE, Coordinate.CLASSIFIER ) );
}
else if ( ANY.equals( tokens[1] ) && ANY.equals( tokens[2] ) )
{
patterns.add( new CoordinateMatchingPattern( pattern, tokens[0],
EnumSet.of( Coordinate.GROUP_ID, Coordinate.ARTIFACT_ID ) ) );
patterns.add( toPattern( pattern, tokens[0], Coordinate.GROUP_ID, Coordinate.ARTIFACT_ID ) );
}
else if ( ANY.equals( tokens[1] ) )
{
patterns.add( toPattern( tokens[0], Coordinate.GROUP_ID ) );
patterns.add( new CoordinateMatchingPattern( pattern, tokens[2],
EnumSet.of( Coordinate.TYPE, Coordinate.CLASSIFIER ) ) );
patterns.add( toPattern( tokens[0], tokens[0], Coordinate.GROUP_ID ) );
patterns.add( toPattern( pattern, tokens[2], Coordinate.TYPE, Coordinate.CLASSIFIER ) );
}
else if ( ANY.equals( tokens[2] ) )
{
Expand Down Expand Up @@ -441,9 +436,8 @@ else if ( tokens.length == 2 )
}
else if ( ANY.equals( tokens[0] ) )
{
patterns.add( new CoordinateMatchingPattern( pattern, tokens[1],
EnumSet.of( Coordinate.GROUP_ID, Coordinate.ARTIFACT_ID, Coordinate.TYPE,
Coordinate.BASE_VERSION ) ) );
patterns.add( toPattern( pattern, tokens[1],
Coordinate.GROUP_ID, Coordinate.ARTIFACT_ID, Coordinate.TYPE, Coordinate.BASE_VERSION ) );
}
else if ( ANY.equals( tokens[1] ) )
{
Expand Down Expand Up @@ -481,15 +475,22 @@ else if ( ANY.equals( tokens[1] ) )
}
}

private static Pattern toPattern( final String token, final Coordinate coordinate )
private static Pattern toPattern( final String token, final Coordinate... coordinates )
{
return toPattern( token, token, coordinates );
}

private static Pattern toPattern( final String pattern, final String token, final Coordinate... coordinates )
{
if ( ANY.equals( token ) )
{
return MATCH_ALL_PATTERN;
}
else
{
return new CoordinateMatchingPattern( token, token, EnumSet.of( coordinate ) );
EnumSet<Coordinate> coordinateSet = EnumSet.noneOf( Coordinate.class );
coordinateSet.addAll( Arrays.asList( coordinates ) );
return new CoordinateMatchingPattern( pattern, token, coordinateSet );
}
}

Expand Down