List of usage examples for com.google.common.collect ImmutableSortedSet tailSet
public ImmutableSortedSet<E> tailSet(E fromElement)
From source file:com.facebook.buck.go.GoDescriptors.java
@VisibleForTesting static ImmutableMap<Path, Path> getPackageImportMap(ImmutableList<Path> globalVendorPaths, Path basePackagePath, Iterable<Path> packageNameIter) { Map<Path, Path> importMapBuilder = Maps.newHashMap(); ImmutableSortedSet<Path> packageNames = ImmutableSortedSet.copyOf(packageNameIter); ImmutableList.Builder<Path> vendorPathsBuilder = ImmutableList.builder(); vendorPathsBuilder.addAll(globalVendorPaths); Path prefix = Paths.get(""); for (Path component : FluentIterable.of(new Path[] { Paths.get("") }).append(basePackagePath)) { prefix = prefix.resolve(component); vendorPathsBuilder.add(prefix.resolve("vendor")); }/*from ww w. jav a 2s.c o m*/ for (Path vendorPrefix : vendorPathsBuilder.build()) { for (Path vendoredPackage : packageNames.tailSet(vendorPrefix)) { if (!vendoredPackage.startsWith(vendorPrefix)) { break; } importMapBuilder.put(MorePaths.relativize(vendorPrefix, vendoredPackage), vendoredPackage); } } return ImmutableMap.copyOf(importMapBuilder); }
From source file:com.facebook.buck.features.go.GoDescriptors.java
@VisibleForTesting static ImmutableMap<Path, Path> getPackageImportMap(ImmutableList<Path> globalVendorPaths, Path basePackagePath, Iterable<Path> packageNameIter) { Map<Path, Path> importMapBuilder = new HashMap<>(); ImmutableSortedSet<Path> packageNames = ImmutableSortedSet.copyOf(packageNameIter); ImmutableList.Builder<Path> vendorPathsBuilder = ImmutableList.builder(); vendorPathsBuilder.addAll(globalVendorPaths); Path prefix = Paths.get(""); for (Path component : FluentIterable.from(new Path[] { Paths.get("") }).append(basePackagePath)) { prefix = prefix.resolve(component); vendorPathsBuilder.add(prefix.resolve("vendor")); }// www .j a v a 2 s . c o m for (Path vendorPrefix : vendorPathsBuilder.build()) { for (Path vendoredPackage : packageNames.tailSet(vendorPrefix)) { if (!vendoredPackage.startsWith(vendorPrefix)) { break; } importMapBuilder.put(MorePaths.relativize(vendorPrefix, vendoredPackage), vendoredPackage); } } return ImmutableMap.copyOf(importMapBuilder); }
From source file:com.facebook.buck.io.file.PathListing.java
private static ImmutableSortedSet<Path> subSet(ImmutableSortedSet<Path> paths, FilterMode filterMode, int limitIndex) { // This doesn't copy the contents of the ImmutableSortedSet. We use it // as a simple way to get O(1) access to the set's contents, as otherwise // we would have to iterate to find the Nth element. ImmutableList<Path> pathsList = paths.asList(); boolean fullSet = limitIndex == paths.size(); switch (filterMode) { case INCLUDE: // Make sure we don't call pathsList.get(pathsList.size()). if (!fullSet) { paths = paths.headSet(pathsList.get(limitIndex)); }//from w w w.j av a 2 s . c o m break; case EXCLUDE: if (fullSet) { // Make sure we don't call pathsList.get(pathsList.size()). paths = ImmutableSortedSet.of(); } else { paths = paths.tailSet(pathsList.get(limitIndex)); } break; } return paths; }