List of usage examples for com.google.common.collect ImmutableSet contains
boolean contains(Object o);
From source file:org.apache.hadoop.hbase.master.cleaner.CleanerChore.java
/** * Run the given files through each of the cleaners to see if it should be deleted, deleting it if * necessary.// w ww .jav a 2 s . c o m * @param files List of FileStatus for the files to check (and possibly delete) * @return true iff successfully deleted all files */ private boolean checkAndDeleteFiles(List<FileStatus> files) { // first check to see if the path is valid List<FileStatus> validFiles = Lists.newArrayListWithCapacity(files.size()); List<FileStatus> invalidFiles = Lists.newArrayList(); for (FileStatus file : files) { if (validate(file.getPath())) { validFiles.add(file); } else { LOG.warn("Found a wrongly formatted file: " + file.getPath() + " - will delete it."); invalidFiles.add(file); } } Iterable<FileStatus> deletableValidFiles = validFiles; // check each of the cleaners for the valid files for (T cleaner : cleanersChain) { if (cleaner.isStopped() || this.stopper.isStopped()) { LOG.warn("A file cleaner" + this.getName() + " is stopped, won't delete any more files in:" + this.oldFileDir); return false; } Iterable<FileStatus> filteredFiles = cleaner.getDeletableFiles(deletableValidFiles); // trace which cleaner is holding on to each file if (LOG.isTraceEnabled()) { ImmutableSet<FileStatus> filteredFileSet = ImmutableSet.copyOf(filteredFiles); for (FileStatus file : deletableValidFiles) { if (!filteredFileSet.contains(file)) { LOG.trace(file.getPath() + " is not deletable according to:" + cleaner); } } } deletableValidFiles = filteredFiles; } Iterable<FileStatus> filesToDelete = Iterables.concat(invalidFiles, deletableValidFiles); int deletedFileCount = 0; for (FileStatus file : filesToDelete) { Path filePath = file.getPath(); if (LOG.isTraceEnabled()) { LOG.trace("Removing: " + filePath + " from archive"); } try { boolean success = this.fs.delete(filePath, false); if (success) { deletedFileCount++; } else { LOG.warn("Attempted to delete:" + filePath + ", but couldn't. Run cleaner chain and attempt to delete on next pass."); } } catch (IOException e) { e = RemoteExceptionHandler.checkIOException(e); LOG.warn("Error while deleting: " + filePath, e); } } return deletedFileCount == files.size(); }
From source file:com.google.devtools.build.lib.skyframe.TraversalInfoRootPackageExtractor.java
private void collectPackagesUnder(WalkableGraph graph, ExtendedEventHandler eventHandler, final RepositoryName repository, Set<TraversalInfo> traversals, ImmutableList.Builder<PathFragment> builder) throws InterruptedException { Map<TraversalInfo, SkyKey> traversalToKeyMap = Maps.asMap(traversals, new Function<TraversalInfo, SkyKey>() { @Override//w w w. j a v a 2 s . co m public SkyKey apply(TraversalInfo traversalInfo) { return CollectPackagesUnderDirectoryValue.key(repository, traversalInfo.rootedDir, traversalInfo.blacklistedSubdirectories); } }); Map<SkyKey, SkyValue> values = graph.getSuccessfulValues(traversalToKeyMap.values()); ImmutableSet.Builder<TraversalInfo> subdirTraversalBuilder = ImmutableSet.builder(); for (Map.Entry<TraversalInfo, SkyKey> entry : traversalToKeyMap.entrySet()) { TraversalInfo info = entry.getKey(); SkyKey key = entry.getValue(); SkyValue val = values.get(key); CollectPackagesUnderDirectoryValue collectPackagesValue = (CollectPackagesUnderDirectoryValue) val; if (collectPackagesValue != null) { if (collectPackagesValue.isDirectoryPackage()) { builder.add(info.rootedDir.getRootRelativePath()); } if (collectPackagesValue.getErrorMessage() != null) { eventHandler.handle(Event.error(collectPackagesValue.getErrorMessage())); } ImmutableMap<RootedPath, Boolean> subdirectoryTransitivelyContainsPackages = collectPackagesValue .getSubdirectoryTransitivelyContainsPackagesOrErrors(); for (RootedPath subdirectory : subdirectoryTransitivelyContainsPackages.keySet()) { if (subdirectoryTransitivelyContainsPackages.get(subdirectory)) { PathFragment subdirectoryRelativePath = subdirectory.getRootRelativePath(); ImmutableSet<PathFragment> blacklistedSubdirectoriesBeneathThisSubdirectory = info.blacklistedSubdirectories .stream().filter(pathFragment -> pathFragment.startsWith(subdirectoryRelativePath)) .collect(toImmutableSet()); ImmutableSet<PathFragment> excludedSubdirectoriesBeneathThisSubdirectory = info.excludedSubdirectories .stream().filter(pathFragment -> pathFragment.startsWith(subdirectoryRelativePath)) .collect(toImmutableSet()); if (!excludedSubdirectoriesBeneathThisSubdirectory.contains(subdirectoryRelativePath)) { subdirTraversalBuilder.add(new TraversalInfo(subdirectory, blacklistedSubdirectoriesBeneathThisSubdirectory, excludedSubdirectoriesBeneathThisSubdirectory)); } } } } } ImmutableSet<TraversalInfo> subdirTraversals = subdirTraversalBuilder.build(); if (!subdirTraversals.isEmpty()) { collectPackagesUnder(graph, eventHandler, repository, subdirTraversals, builder); } }
From source file:com.facebook.buck.thrift.ThriftCxxEnhancer.java
private ImmutableSet<BuildTarget> getImplicitDepsFromOptions(UnflavoredBuildTarget target, ImmutableSet<String> options) { ImmutableSet.Builder<BuildTarget> implicitDeps = ImmutableSet.builder(); if (!options.contains("bootstrap")) { if (cpp2) { implicitDeps.add(thriftBuckConfig.getCpp2Dep()); } else {//from w w w .j av a2 s . co m implicitDeps.add(thriftBuckConfig.getCppDep()); } implicitDeps.add(thriftBuckConfig.getCppReflectionDep()); } if (options.contains("frozen2")) { implicitDeps.add(thriftBuckConfig.getCppFrozenDep()); } if (options.contains("json")) { implicitDeps.add(thriftBuckConfig.getCppJsonDep()); } if (cpp2 && options.contains("compatibility")) { implicitDeps.add(thriftBuckConfig.getCppDep()); BuildTarget cppTarget = BuildTargets.createFlavoredBuildTarget(target, CPP_FLAVOR); implicitDeps.add(cppTarget); } if (!cpp2 && options.contains("cob_style")) { implicitDeps.add(thriftBuckConfig.getCppAyncDep()); } if (cpp2) { boolean flagLeanMeanMetaMachine = options.contains("lean_mean_meta_machine"); if (options.contains("lean_mean_meta_machine")) { implicitDeps.add(thriftBuckConfig.getCpp2LeanMeanMetaMachineDep()); } boolean flagReflection = flagLeanMeanMetaMachine || options.contains("fatal") || options.contains("reflection"); if (flagReflection) { implicitDeps.add(thriftBuckConfig.getCpp2ReflectionDep()); } } return implicitDeps.build(); }
From source file:com.facebook.buck.cli.AuditRulesCommand.java
/** Prints the expanded build rules from the specified build files to the console. */ @Override/* w w w . j av a 2 s . com*/ int runCommandWithOptionsInternal(AuditRulesOptions options) throws IOException { ProjectFilesystem projectFilesystem = getProjectFilesystem(); ProjectBuildFileParserFactory factory = new DefaultProjectBuildFileParserFactory(projectFilesystem, options.getBuckConfig().getPythonInterpreter(), // TODO(simons): When we land dynamic loading, this MUST change. getBuildRuleTypes().getAllDescriptions()); try (ProjectBuildFileParser parser = factory.createParser(options.getBuckConfig().getDefaultIncludes(), EnumSet.noneOf(ProjectBuildFileParser.Option.class), console)) { PrintStream out = console.getStdOut(); for (String pathToBuildFile : options.getArguments()) { // Print a comment with the path to the build file. out.printf("# %s\n\n", pathToBuildFile); // Resolve the path specified by the user. Path path = Paths.get(pathToBuildFile); if (!path.isAbsolute()) { Path root = projectFilesystem.getProjectRoot().toPath(); path = root.resolve(path); } // Parse the rules from the build file. List<Map<String, Object>> rawRules; try { rawRules = parser.getAllRules(path); } catch (BuildFileParseException e) { throw new HumanReadableException(e); } // Format and print the rules from the raw data, filtered by type. final ImmutableSet<String> types = options.getTypes(); Predicate<String> includeType = new Predicate<String>() { @Override public boolean apply(String type) { return types.isEmpty() || types.contains(type); } }; printRulesToStdout(rawRules, includeType); } } catch (BuildFileParseException e) { throw new HumanReadableException("Unable to create parser"); } return 0; }
From source file:com.facebook.buck.android.exopackage.ExopackageInstaller.java
private void deleteUnwantedFiles(ImmutableSortedSet<Path> presentFiles, ImmutableSet<Path> wantedFiles) { ImmutableSortedSet<Path> filesToDelete = presentFiles.stream() .filter(p -> !p.getFileName().toString().equals("lock") && !wantedFiles.contains(p)) .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural())); deleteFiles(filesToDelete);/*from ww w. j a va2 s . c o m*/ }
From source file:org.tendiwa.inflectible.inflection.LxWithSuppletivism.java
/** * Generates all word forms of this lexeme. * @return All word forms of this lexeme * @throws Exception If fails//from w ww . j a va 2s . c o m */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private ImmutableMap<GrammaticalMeaning, Spelling> forms() throws Exception { final ImmutableMap.Builder<GrammaticalMeaning, Spelling> builder = ImmutableMap.builder(); final ImmutableSet<ImmutableSet<Grammeme>> headwordMeanings = this.headwords.keySet().stream() .map(Rethrowing.rethrowFunction(GrammaticalMeaning::grammemes)) .collect(Collectors.toImmutableSet()); builder.putAll(this.headwords); for (final GrammaticalMeaning meaning : this.part.meaningVariations()) { if (headwordMeanings.contains(meaning.grammemes())) { continue; } final GrammaticalMeaning closest = this.closestHeadwordMeaning(meaning); builder.put(meaning, this.part .lexeme(this.headwords.get(closest), new GmCombined(ImmutableList.of(this.persistent, closest))) .wordForm(meaning)); } return builder.build(); }
From source file:com.facebook.buck.rust.RustLibraryDescription.java
@Override public boolean hasFlavors(ImmutableSet<Flavor> flavors) { if (cxxPlatforms.containsAnyOf(flavors)) { return true; }/* ww w.java 2s. c o m*/ for (RustDescriptionEnhancer.Type type : RustDescriptionEnhancer.Type.values()) { if (flavors.contains(type.getFlavor())) { return true; } } return false; }
From source file:org.csstudio.utility.treemodel.builder.XmlFileContentModelBuilder.java
@SuppressWarnings("unchecked") private Attributes extractAttributes(final Element element, final ImmutableSet<String> attributes) { final Attributes treeNodeAttributes = new BasicAttributes(); final List<Attribute> xmlAttributes = element.getAttributes(); for (final Attribute xmlAttribute : xmlAttributes) { final String attrName = xmlAttribute.getName(); if (attributes.contains(attrName)) { treeNodeAttributes.put(attrName, xmlAttribute.getValue()); }//from w ww . j a v a2 s . c o m } return treeNodeAttributes; }
From source file:com.facebook.buck.core.build.engine.cache.manager.BuildCacheArtifactFetcher.java
public ListenableFuture<CacheResult> tryToFetchArtifactFromBuildCacheAndOverlayOnTopOfProjectFilesystem( RuleKey ruleKey, ArtifactCache artifactCache, ProjectFilesystem filesystem) { if (!rule.isCacheable()) { return Futures.immediateFuture(CacheResult.ignored()); }// w w w .ja v a 2s .com // Create a temp file whose extension must be ".zip" for Filesystems.newFileSystem() to infer // that we are creating a zip-based FileSystem. LazyPath lazyZipPath = new LazyPath() { @Override protected Path create() throws IOException { return Files.createTempFile( "buck_artifact_" + MostFiles.sanitize(rule.getBuildTarget().getShortName()), ".zip"); } }; // TODO(mbolin): Change ArtifactCache.fetch() so that it returns a File instead of takes one. // Then we could download directly from the remote cache into the on-disk cache and unzip it // from there. return Futures.transformAsync(fetch(artifactCache, ruleKey, lazyZipPath), cacheResult -> { try (Scope ignored = buildRuleScope()) { // Verify that the rule key we used to fetch the artifact is one of the rule keys // reported in it's metadata. if (cacheResult.getType().isSuccess()) { ImmutableSet<RuleKey> ruleKeys = RichStream.from(cacheResult.getMetadata().entrySet()) .filter(e -> BuildInfo.RULE_KEY_NAMES.contains(e.getKey())).map(Map.Entry::getValue) .map(RuleKey::new).toImmutableSet(); if (!ruleKeys.contains(ruleKey)) { LOG.warn("%s: rule keys in artifact don't match rule key used to fetch it: %s not in %s", rule.getBuildTarget(), ruleKey, ruleKeys); } } return Futures.immediateFuture( extractArtifactFromCacheResult(ruleKey, lazyZipPath, filesystem, cacheResult)); } }); }
From source file:omero.cmd.graphs.ChildOptionI.java
/** * Initialize this child option instance. * An option takes effect according to the {@link ChildOption} field values set when this method was last called. *//*from w ww. j av a 2 s .c om*/ public void init() { /* convert the class names to actual classes */ final Function<String, Class<? extends IObject>> getClassFromName = new Function<String, Class<? extends IObject>>() { @Override public Class<? extends IObject> apply(String className) { final int lastDot = className.lastIndexOf('.'); if (lastDot > 0) { className = className.substring(lastDot + 1); } return graphPathBean.getClassForSimpleName(className); } }; /* construct the function corresponding to the type-based inclusion requirements */ final ImmutableSet<Class<? extends IObject>> typeInclusions; final ImmutableSet<Class<? extends IObject>> typeExclusions; if (CollectionUtils.isEmpty(includeType)) { typeInclusions = ImmutableSet.of(); } else { typeInclusions = ImmutableSet.copyOf(Collections2.transform(includeType, getClassFromName)); } if (CollectionUtils.isEmpty(excludeType)) { typeExclusions = ImmutableSet.of(); } else { typeExclusions = ImmutableSet.copyOf(Collections2.transform(excludeType, getClassFromName)); } if (typeInclusions.isEmpty() && typeExclusions.isEmpty()) { throw new IllegalArgumentException("child option must include or exclude some type"); } isIncludeType = new Function<Class<? extends IObject>, Boolean>() { @Override public Boolean apply(Class<? extends IObject> objectClass) { for (final Class<? extends IObject> typeInclusion : typeInclusions) { if (typeInclusion.isAssignableFrom(objectClass)) { return Boolean.TRUE; } } for (final Class<? extends IObject> typeExclusion : typeExclusions) { if (typeExclusion.isAssignableFrom(objectClass)) { return Boolean.FALSE; } } return null; } }; /* if no annotation namespaces are set, then apply the defaults */ if (CollectionUtils.isEmpty(includeNs) && CollectionUtils.isEmpty(excludeNs)) { excludeNs = new ArrayList<String>(defaultExcludeNs); } /* construct the predicate corresponding to the namespace restriction */ if (CollectionUtils.isEmpty(includeNs)) { if (CollectionUtils.isEmpty(excludeNs)) { /* there is no adjustment to make, not even for any default namespaces */ isTargetNamespace = Predicates.alwaysTrue(); } else { final ImmutableSet<String> nsExclusions = ImmutableSet.copyOf(excludeNs); isTargetNamespace = new Predicate<String>() { @Override public boolean apply(String namespace) { return !nsExclusions.contains(namespace); } }; } } else { if (CollectionUtils.isEmpty(excludeNs)) { final ImmutableSet<String> nsInclusions = ImmutableSet.copyOf(includeNs); isTargetNamespace = new Predicate<String>() { @Override public boolean apply(String namespace) { return nsInclusions.contains(namespace); } }; } else { throw new IllegalArgumentException("child option may not both include and exclude namespace"); } } }