Filepatterns { public static Iterable<String> expandAtNFilepattern(String filepattern) { ImmutableList.Builder<String> builder = ImmutableList.builder(); Matcher match = AT_N_SPEC.matcher(filepattern); if (!match.find()) { builder.add(filepattern); } else { int numShards = Integer.parseInt(match.group("N")); String formatString = "-%0" + getShardWidth(numShards, filepattern) + "d-of-%05d"; for (int i = 0; i < numShards; ++i) { builder.add( AT_N_SPEC.matcher(filepattern).replaceAll(String.format(formatString, i, numShards))); } if (match.find()) { throw new IllegalArgumentException( "More than one @N wildcard found in filepattern: " + filepattern); } } return builder.build(); }  static Iterable<String> expandAtNFilepattern(String filepattern);  }
@Test public void testExpandAtNFilepatternNoPattern() throws Exception { assertThat( Filepatterns.expandAtNFilepattern("gs: contains("gs: }
@Test public void testExpandAtNFilepatternTwoPatterns() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage( "More than one @N wildcard found in filepattern: gs: Filepatterns.expandAtNFilepattern("gs: }
@Test public void testExpandAtNFilepatternHugeN() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage( "Unsupported number of shards: 2000000000 " + "in filepattern: gs: Filepatterns.expandAtNFilepattern("gs: }
@Test public void testExpandAtNFilepatternSmall() throws Exception { assertThat( Filepatterns.expandAtNFilepattern("gs: contains("gs: }
@Test public void testExpandAtNFilepatternLarge() throws Exception { Iterable<String> iterable = Filepatterns.expandAtNFilepattern("gs: assertThat(iterable, Matchers.<String>iterableWithSize(200000)); assertThat( iterable, hasItems("gs: }