List of usage examples for com.google.common.base Predicates notNull
@GwtCompatible(serializable = true) public static <T> Predicate<T> notNull()
From source file:net.shibboleth.idp.saml.impl.profile.PopulateBindingAndEndpointContexts.java
/** * Set the bindings to evaluate for use, in preference order. * //from w w w .j a va 2s . c o m * @param bindings bindings to consider */ public void setBindings(@Nonnull @NonnullElements final List<BindingDescriptor> bindings) { ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); Constraint.isNotNull(bindings, "Binding descriptor list cannot be null"); bindingDescriptors = Lists.newArrayList(Collections2.filter(bindings, Predicates.notNull())); }
From source file:grkvlt.Ec2CleanUp.java
private Iterable<String> getVolumesWithNoName(ElasticBlockStoreClient ebsApi, TagApi tagApi) { Set<String> namedVolumes = tagApi.filter(new TagFilterBuilder().volume().key("Name").build()) .transform(new Function<Tag, String>() { @Override//from w w w .j av a 2s . c om public String apply(Tag input) { return input.getResourceId(); } }).toSet(); Set<String> allVolumes = FluentIterable.from(ebsApi.describeVolumesInRegion(region)) .transform(new Function<Volume, String>() { @Override public String apply(Volume input) { if (input.getId() == null && LOG.isTraceEnabled()) LOG.trace("No id on volume: " + input); return input.getId() != null ? input.getId() : null; } }).filter(Predicates.notNull()).toSet(); Set<String> unnamedVolumes = Sets.difference(allVolumes, namedVolumes); LOG.info("Found {} unnamed Volumes", Iterables.size(unnamedVolumes)); return unnamedVolumes; }
From source file:org.killbill.billing.util.security.shiro.realm.KillBillJndiLdapRealm.java
private String extractGroupNameFromSearchResult(final SearchResult searchResult) { // Get all attributes for that group final Iterator<? extends Attribute> attributesIterator = Iterators .forEnumeration(searchResult.getAttributes().getAll()); // Find the attribute representing the group name final Iterator<? extends Attribute> groupNameAttributesIterator = Iterators.filter(attributesIterator, new Predicate<Attribute>() { @Override/*from www.j ava 2 s . c om*/ public boolean apply(final Attribute attribute) { return groupNameId.equalsIgnoreCase(attribute.getID()); } }); // Extract the group name from the attribute // Note: at this point, groupNameAttributesIterator should really contain a single element final Iterator<String> groupNamesIterator = Iterators.transform(groupNameAttributesIterator, new Function<Attribute, String>() { @Override public String apply(final Attribute groupNameAttribute) { try { final NamingEnumeration<?> enumeration = groupNameAttribute.getAll(); if (enumeration.hasMore()) { return enumeration.next().toString(); } else { return null; } } catch (NamingException namingException) { log.warn("Unable to read group name", namingException); return null; } } }); final Iterator<String> finalGroupNamesIterator = Iterators.<String>filter(groupNamesIterator, Predicates.notNull()); if (finalGroupNamesIterator.hasNext()) { return finalGroupNamesIterator.next(); } else { log.warn("Unable to find an attribute matching {}", groupNameId); return null; } }
From source file:org.splevo.refactoring.VariabilityRefactoringService.java
private void preprocessResources(VariationPointModel variationPointModel) { Iterable<Resource> resourcesOfAllSoftwareElements = Iterables .transform(variationPointModel.getSoftwareElements(), new Function<SoftwareElement, Resource>() { @Override/* w w w .j av a 2 s.c o m*/ public Resource apply(SoftwareElement arg0) { return arg0.getWrappedElement().eResource(); } }); Iterable<Resource> nonNullResources = Iterables.filter(resourcesOfAllSoftwareElements, Predicates.notNull()); Set<Resource> resources = Sets.newHashSet(nonNullResources); new ResourceProcessorService().processResourcesBeforeRefactorings(resources); }
From source file:com.eucalyptus.simpleworkflow.ActivityTask.java
public Pair<String, Date> calculateNextTimeout() { final Iterable<Pair<String, Optional<Long>>> taggedTimeouts = Iterables.filter(Lists.newArrayList( Pair.ropair("SCHEDULE_TO_CLOSE", toTimeout(getCreationTimestamp(), getScheduleToCloseTimeout())), Pair.ropair("SCHEDULE_TO_START", toTimeout(getCreationTimestamp(), getScheduleToStartTimeout())), getState() == State.Active ? Pair.ropair("START_TO_CLOSE", toTimeout(getStartedTimestamp(), getStartToCloseTimeout())) : null,// w w w .j a v a2 s. c om getState() == State.Active ? Pair.ropair("HEARTBEAT", toTimeout(getLastUpdateTimestamp(), getHeartbeatTimeout())) : null), Predicates.notNull()); final Function<Pair<String, Optional<Long>>, Long> timeExtractor = Functions .compose(CollectionUtils.<Long>optionalOrNull(), Pair.<String, Optional<Long>>right()); final Long timeout = CollectionUtils.reduce( CollectionUtils.fluent(taggedTimeouts).transform(timeExtractor).filter(Predicates.notNull()), Long.MAX_VALUE, CollectionUtils.lmin()); final String tag = Iterables .tryFind(taggedTimeouts, CollectionUtils.propertyPredicate(timeout, timeExtractor)) .transform(Pair.<String, Optional<Long>>left()).or("SCHEDULE_TO_CLOSE"); return timeout == Long.MAX_VALUE ? null : Pair.pair(tag, new Date(timeout)); }
From source file:org.apache.brooklyn.location.jclouds.JCloudsPropertiesBuilder.java
public JCloudsPropertiesBuilder setCustomJcloudsProperties() { Map<String, Object> extra = Maps.filterKeys(conf.getAllConfig(), Predicates.containsPattern("^jclouds\\.")); if (extra.size() > 0) { String provider = getProviderFromConfig(conf); LOG.debug("Configuring custom jclouds property overrides for {}: {}", provider, Sanitizer.sanitize(extra)); }/*w ww .j ava2s. c om*/ properties.putAll(Maps.filterValues(extra, Predicates.notNull())); return this; }
From source file:co.cask.cdap.logging.framework.LogPipelineLoader.java
/** * Returns an {@link Iterable} of {@link URL} of pipeline configuration files. *///from ww w. j a va 2 s . c om private Iterable<URL> getPipelineConfigURLs() { URL systemPipeline = getClass().getClassLoader().getResource(SYSTEM_LOG_PIPELINE_CONFIG); // This shouldn't happen since the cdap pipeline is packaged in the jar. Preconditions.checkState(systemPipeline != null, "Missing cdap system pipeline configuration"); List<File> files = DirUtils.listFiles(new File(cConf.get(Constants.Logging.PIPELINE_CONFIG_DIR)), "xml"); return Iterables.concat(Collections.singleton(systemPipeline), Iterables.filter(Iterables.transform(files, new Function<File, URL>() { @Nullable @Override public URL apply(File file) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { // This shouldn't happen LOG.warn("Ignoring log pipeline config file {} due to {}", file, e.getMessage()); return null; } } }), Predicates.notNull())); }
From source file:com.google.devtools.build.lib.rules.cpp.CppCompileActionBuilder.java
private Iterable<IncludeScannable> getLipoScannables(NestedSet<Artifact> realMandatoryInputs) { return lipoScannableMap == null ? ImmutableList.<IncludeScannable>of() : Iterables.filter(Iterables.transform( Iterables.filter(/* w w w . j a v a 2s . co m*/ FileType.filter(realMandatoryInputs, CppFileTypes.C_SOURCE, CppFileTypes.CPP_SOURCE, CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR), Predicates.not(Predicates.equalTo(getSourceFile()))), Functions.forMap(lipoScannableMap, null)), Predicates.notNull()); }
From source file:cc.arduino.contributions.ui.InstallerJDialog.java
public void updateIndexFilter(String[] filters, Predicate<T>... additionalFilters) { Collection<Predicate<T>> notNullAdditionalFilters = Collections2.filter(Arrays.asList(additionalFilters), Predicates.notNull()); contribModel.updateIndexFilter(filters, notNullAdditionalFilters.toArray(new Predicate[notNullAdditionalFilters.size()])); }
From source file:com.facebook.buck.java.intellij.IjModuleGraph.java
/** * @param targetGraph input graph./*www.j a v a 2 s. c o m*/ * @param libraryFactory library factory. * @param moduleFactory module factory. * @param aggregationMode module aggregation mode. * @return module graph corresponding to the supplied {@link TargetGraph}. Multiple targets from * the same base path are mapped to a single module, therefore an IjModuleGraph edge * exists between two modules (Ma, Mb) if a TargetGraph edge existed between a pair of * nodes (Ta, Tb) and Ma contains Ta and Mb contains Tb. */ public static IjModuleGraph from(final TargetGraph targetGraph, final IjLibraryFactory libraryFactory, final IjModuleFactory moduleFactory, AggregationMode aggregationMode) { final ImmutableMap<BuildTarget, IjModule> rulesToModules = createModules(targetGraph, moduleFactory, aggregationMode.getBasePathTransform(targetGraph.getNodes().size())); final ExportedDepsClosureResolver exportedDepsClosureResolver = new ExportedDepsClosureResolver( targetGraph); ImmutableMap.Builder<IjProjectElement, ImmutableMap<IjProjectElement, DependencyType>> depsBuilder = ImmutableMap .builder(); final Set<IjLibrary> referencedLibraries = new HashSet<>(); for (final IjModule module : FluentIterable.from(rulesToModules.values()).toSet()) { Map<IjProjectElement, DependencyType> moduleDeps = new HashMap<>(); for (Map.Entry<BuildTarget, DependencyType> entry : module.getDependencies().entrySet()) { BuildTarget depBuildTarget = entry.getKey(); DependencyType depType = entry.getValue(); ImmutableSet<IjProjectElement> depElements; if (depType.equals(DependencyType.COMPILED_SHADOW)) { TargetNode<?> targetNode = Preconditions.checkNotNull(targetGraph.get(depBuildTarget)); Optional<IjLibrary> library = libraryFactory.getLibrary(targetNode); if (library.isPresent()) { depElements = ImmutableSet.<IjProjectElement>of(library.get()); } else { depElements = ImmutableSet.of(); } } else { depElements = FluentIterable .from(exportedDepsClosureResolver.getExportedDepsClosure(depBuildTarget)) .append(depBuildTarget).filter(new Predicate<BuildTarget>() { @Override public boolean apply(BuildTarget input) { // The exported deps closure can contain references back to targets contained // in the module, so filter those out. TargetNode<?> targetNode = targetGraph.get(input); return !module.getTargets().contains(targetNode); } }).transform(new Function<BuildTarget, IjProjectElement>() { @Nullable @Override public IjProjectElement apply(BuildTarget depTarget) { IjModule depModule = rulesToModules.get(depTarget); if (depModule != null) { return depModule; } TargetNode<?> targetNode = Preconditions .checkNotNull(targetGraph.get(depTarget)); IjLibrary library = libraryFactory.getLibrary(targetNode).orNull(); return library; } }).filter(Predicates.notNull()).toSet(); } for (IjProjectElement depElement : depElements) { Preconditions.checkState(!depElement.equals(module)); DependencyType.putWithMerge(moduleDeps, depElement, depType); } } if (!module.getExtraClassPathDependencies().isEmpty()) { IjLibrary extraClassPathLibrary = IjLibrary.builder() .setClassPaths(module.getExtraClassPathDependencies()) .setTargets(ImmutableSet.<TargetNode<?>>of()) .setName("library_" + module.getName() + "_extra_classpath").build(); moduleDeps.put(extraClassPathLibrary, DependencyType.PROD); } referencedLibraries.addAll(FluentIterable.from(moduleDeps.keySet()).filter(IjLibrary.class).toSet()); depsBuilder.put(module, ImmutableMap.copyOf(moduleDeps)); } for (IjLibrary library : referencedLibraries) { depsBuilder.put(library, ImmutableMap.<IjProjectElement, DependencyType>of()); } return new IjModuleGraph(depsBuilder.build()); }