GcsFileSystem extends FileSystem<GcsResourceId> { @Override protected List<MatchResult> match(List<String> specs) throws IOException { List<GcsPath> gcsPaths = toGcsPaths(specs); List<GcsPath> globs = Lists.newArrayList(); List<GcsPath> nonGlobs = Lists.newArrayList(); List<Boolean> isGlobBooleans = Lists.newArrayList(); for (GcsPath path : gcsPaths) { if (GcsUtil.isWildcard(path)) { globs.add(path); isGlobBooleans.add(true); } else { nonGlobs.add(path); isGlobBooleans.add(false); } } Iterator<MatchResult> globsMatchResults = matchGlobs(globs).iterator(); Iterator<MatchResult> nonGlobsMatchResults = matchNonGlobs(nonGlobs).iterator(); ImmutableList.Builder<MatchResult> ret = ImmutableList.builder(); for (Boolean isGlob : isGlobBooleans) { if (isGlob) { checkState(globsMatchResults.hasNext(), "Expect globsMatchResults has next: %s", globs); ret.add(globsMatchResults.next()); } else { checkState( nonGlobsMatchResults.hasNext(), "Expect nonGlobsMatchResults has next: %s", nonGlobs); ret.add(nonGlobsMatchResults.next()); } } checkState( !globsMatchResults.hasNext(), "Internal error encountered in GcsFilesystem: expected no more elements in globsMatchResults."); checkState( !nonGlobsMatchResults.hasNext(), "Internal error encountered in GcsFilesystem: expected no more elements in globsMatchResults."); return ret.build(); } GcsFileSystem(GcsOptions options);   }
@Test public void testMatch() throws Exception { Objects modelObjects = new Objects(); List<StorageObject> items = new ArrayList<>(); items.add(new StorageObject().setBucket("testbucket").setName("testdirectory/")); items.add(createStorageObject("gs: items.add(createStorageObject("gs: items.add(createStorageObject("gs: items.add(createStorageObject("gs: items.add(createStorageObject("gs: items.add(createStorageObject("gs: modelObjects.setItems(items); when(mockGcsUtil.listObjects(eq("testbucket"), anyString(), isNull(String.class))) .thenReturn(modelObjects); List<GcsPath> gcsPaths = ImmutableList.of( GcsPath.fromUri("gs: GcsPath.fromUri("gs: when(mockGcsUtil.getObjects(eq(gcsPaths))) .thenReturn( ImmutableList.of( StorageObjectOrIOException.create(new FileNotFoundException()), StorageObjectOrIOException.create( createStorageObject("gs: List<String> specs = ImmutableList.of( "gs: "gs: "gs: List<MatchResult> matchResults = gcsFileSystem.match(specs); assertEquals(3, matchResults.size()); assertEquals(Status.OK, matchResults.get(0).status()); assertThat( ImmutableList.of( "gs: "gs: "gs: contains(toFilenames(matchResults.get(0)).toArray())); assertEquals(Status.NOT_FOUND, matchResults.get(1).status()); assertEquals(Status.OK, matchResults.get(2).status()); assertThat( ImmutableList.of("gs: contains(toFilenames(matchResults.get(2)).toArray())); }