Skip to content

Commit

Permalink
[MSHARED-1104] Four element pattern may be GATV or GATC (#29)
Browse files Browse the repository at this point in the history
This simple patch makes 4 element pattern
be interpeted as GATV (as before) or as GATC.

Also, cleanup how patterns are created, make
everywhere toPattern static helper is used, no need
for direct ctor invocation, and it simplifies things.
  • Loading branch information
cstamas authored Jul 17, 2022
1 parent 0985a22 commit 611baf6
Showing 1 changed file with 21 additions and 20 deletions.
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

0 comments on commit 611baf6

Please sign in to comment.