Example usage for com.google.common.base Predicates notNull

List of usage examples for com.google.common.base Predicates notNull

Introduction

In this page you can find the example usage for com.google.common.base Predicates notNull.

Prototype

@GwtCompatible(serializable = true)
public static <T> Predicate<T> notNull() 

Source Link

Document

Returns a predicate that evaluates to true if the object reference being tested is not null.

Usage

From source file:org.splevo.ui.commons.util.WorkspaceUtil.java

/**
 * Maps a list of given project names to a list of projects. If a project with a given name does
 * not exist, it will be omitted in the output.
 * //from  www.j a v a2 s.co m
 * @param projectNames
 *            The names of the projects.
 * @return The workspace projects matching the given names.
 */
public static Iterable<IProject> transformProjectNamesToProjects(Iterable<String> projectNames) {
    Iterable<IProject> projects = Iterables.transform(projectNames, new Function<String, IProject>() {
        @Override
        public IProject apply(String input) {
            return ResourcesPlugin.getWorkspace().getRoot().getProject(input);
        }
    });
    return Iterables.filter(projects, Predicates.notNull());
}

From source file:net.shibboleth.idp.oidc.config.login.LoginConfiguration.java

/**
 * Sets default authentication methods./*from  w w w .j av  a 2 s .  co  m*/
 *
 * @param contexts the contexts
 */
public void setDefaultAuthenticationMethods(
        @Nonnull @NonnullElements final List<AuthnContextClassRefPrincipal> contexts) {
    Constraint.isNotNull(contexts, "List of contexts cannot be null");
    this.defaultAuthenticationContexts = new ArrayList(Collections2.filter(contexts, Predicates.notNull()));
}

From source file:brooklyn.networking.subnet.PortForwarderAsyncImpl.java

@Override
public void openPortForwardingAndAdvertise(final EntityAndAttribute<Integer> privatePort,
        final Optional<Integer> optionalPublicPort, final Protocol protocol, final Cidr accessingCidr,
        final EntityAndAttribute<String> whereToAdvertiseEndpoint) {
    DeferredExecutor<Integer> updater = new DeferredExecutor<Integer>("open-port-forwarding", privatePort,
            Predicates.notNull(), new Runnable() {
                public void run() {
                    Entity entity = privatePort.getEntity();
                    MachineLocation machine = (MachineLocation) Iterables.getOnlyElement(entity.getLocations(),
                            null);/*from www.ja  va 2 s  . c  o m*/
                    HostAndPort publicEndpoint = portForwarder.openPortForwarding(machine,
                            privatePort.getValue(), optionalPublicPort, protocol, accessingCidr);
                    whereToAdvertiseEndpoint
                            .setValue(publicEndpoint.getHostText() + ":" + publicEndpoint.getPort());
                }
            });
    subscribe(privatePort.getEntity(), privatePort.getAttribute(), updater);
    updater.apply(privatePort.getEntity(), privatePort.getValue());
}

From source file:net.shibboleth.idp.authn.impl.PopulateAuthenticationContext.java

/**
 * Set the flows available for possible use.
 * // w w w .jav  a 2 s  .co m
 * @param flows the flows available for possible use
 */
public void setAvailableFlows(@Nonnull @NonnullElements final Collection<AuthenticationFlowDescriptor> flows) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
    Constraint.isNotNull(flows, "Flow collection cannot be null");

    availableFlows = new ArrayList<>(Collections2.filter(flows, Predicates.notNull()));
}

From source file:org.opensaml.xmlsec.impl.BasicSignatureSigningConfiguration.java

/**
 * Set the signing credentials to use when signing.
 * /*from  w ww  . j av  a 2 s.co m*/
 * @param credentials the list of signing credentials
 */
public void setSigningCredentials(@Nullable final List<Credential> credentials) {
    if (credentials == null) {
        signingCredentials = Collections.emptyList();
        return;
    }
    signingCredentials = new ArrayList<>(Collections2.filter(credentials, Predicates.notNull()));
}

From source file:controllers.modules.opinionMiners.base.OpinionMiner.java

@Override
public Iterable<Module> getSubModules() {
    final Iterable<ViewModel> viewModels = this.viewModels;
    Iterable<Module> modules = Iterables.filter(
            Iterables.transform(this.getSubMiners(), new Function<Class<? extends OpinionMiner>, Module>() {
                @Override/*from ww  w  .j  av a 2  s .  c om*/
                @Nullable
                public Module apply(@Nullable Class<? extends OpinionMiner> input) {
                    try {
                        return input.newInstance().setViewModels(viewModels);
                    } catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {
                        return null;
                    }
                }
            }), Predicates.notNull());

    return Iterables.size(modules) > 0 ? modules : null;
}

From source file:org.apache.brooklyn.util.core.javalang.ReflectionScanner.java

/** scanner which will look in the given urls 
 * (or if those are null attempt to infer from the first entry in the classloaders,
 * although currently that seems to only pick up directories, not JAR's),
 * optionally filtering for the given prefix;
 * any or all arguments can be null to accept all (and use default classpath for classloading).
 **//*ww w .  j  ava  2 s .  c o  m*/
public ReflectionScanner(final Iterable<URL> urlsToScan, final String optionalPrefix,
        final ClassLoader... classLoaders) {
    reflections = new Reflections(new ConfigurationBuilder() {
        {
            final Predicate<String> filter = Strings.isNonEmpty(optionalPrefix)
                    ? new FilterBuilder.Include(FilterBuilder.prefix(optionalPrefix))
                    : null;

            if (urlsToScan != null)
                setUrls(ImmutableSet.copyOf(urlsToScan));
            else if (classLoaders.length > 0 && classLoaders[0] != null)
                setUrls(ClasspathHelper.forPackage(Strings.isNonEmpty(optionalPrefix) ? optionalPrefix : "",
                        asClassLoaderVarArgs(classLoaders[0])));

            if (filter != null)
                filterInputsBy(filter);

            Scanner typeScanner = new TypeAnnotationsScanner();
            if (filter != null)
                typeScanner = typeScanner.filterResultsBy(filter);
            Scanner subTypeScanner = new SubTypesScanner();
            if (filter != null)
                subTypeScanner = subTypeScanner.filterResultsBy(filter);
            setScanners(typeScanner, subTypeScanner);

            for (ClassLoader cl : classLoaders)
                if (cl != null)
                    addClassLoader(cl);
        }
    });
    this.classLoaders = Iterables.toArray(Iterables.filter(Arrays.asList(classLoaders), Predicates.notNull()),
            ClassLoader.class);
}

From source file:org.grouplens.lenskit.scored.VectorEntryScoredId.java

@Nonnull
@Override//w  ww  .  j  ava 2 s .co  m
public Collection<DoubleSymbolValue> getUnboxedChannels() {
    // FIXME Make this fast
    return FluentIterable.from(vector.getChannelVectorSymbols())
            .transform(new Function<Symbol, DoubleSymbolValue>() {
                @Nullable
                @Override
                public DoubleSymbolValue apply(@Nullable Symbol input) {
                    assert input != null;
                    if (vector.getChannelVector(input).isSet(ent)) {
                        return SymbolValue.of(input, vector.getChannelVector(input).get(ent));
                    } else {
                        return null;
                    }
                }
            }).filter(Predicates.notNull()).toList();
}

From source file:org.opensaml.saml.common.profile.logic.EntityAttributesPredicate.java

/**
 * Constructor.// w  ww.j  a v a2 s .  c  o  m
 * 
 * @param candidates the {@link Candidate} criteria to check for
 */
public EntityAttributesPredicate(@Nonnull @NonnullElements final Collection<Candidate> candidates) {

    Constraint.isNotNull(candidates, "Attribute collection cannot be null");

    candidateSet = new ArrayList<>(Collections2.filter(candidates, Predicates.notNull()));

    trimTags = true;
    matchAll = false;
}

From source file:com.codereligion.diff.internal.linewriter.MapLineWriter.java

/**
 * Transforms the given map {@code value} into a {@link SortedMap}.
 *
 * @param path the path which describes the position of the given value in the object graph
 * @param value the map to be sorted/*  ww  w .ja  v  a 2 s .  c o  m*/
 * @return a new sorted map with the contents of the given map
 */
private SortedMap<Object, Object> transformToSortedMap(final String path, final Map<Object, Object> value) {

    final Optional<Object> anyKey = Iterables.tryFind(value.keySet(), Predicates.notNull());

    final boolean thereIsJustOneKeyAndItIsNull = !anyKey.isPresent();
    if (thereIsJustOneKeyAndItIsNull) {
        return new TreeMap<Object, Object>();
    }

    final Comparator<Object> comparator = findComparatorOrThrowException(path, anyKey.get());
    final SortedMap<Object, Object> sortedMap = new TreeMap<Object, Object>(comparator);
    sortedMap.putAll(value);

    return sortedMap;
}