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:com.isotrol.impe3.palette.oc7.loader.ManyPathsComponent.java

@Override
void load(ContentCriteria criteria) {
    final List<Content> list = Lists.newArrayListWithCapacity(10);
    if (config != null) {
        for (String path : Iterables.filter(
                Arrays.asList(config.path1(), config.path2(), config.path3(), config.path4(), config.path5(),
                        config.path6(), config.path7(), config.path8(), config.path9(), config.path10()),
                Predicates.notNull())) {
            final Content c = loadContent(criteria, path);
            if (c != null) {
                list.add(c);/*from  w w  w .  j  a  va  2  s  . co  m*/
            }
        }
    }
    contents = new ContentListingPage(list.size(), null, list);
}

From source file:org.eclipse.smarthome.core.common.registry.AbstractManagedProvider.java

@Override
public Collection<E> getAll() {
    final Function<String, E> toElementList = new Function<String, E>() {
        @Override//  ww  w. ja  v  a2 s  .c om
        public E apply(String elementKey) {
            PE persistableElement = storage.get(elementKey);
            if (persistableElement != null) {
                return toElement(elementKey, persistableElement);
            } else {
                return null;
            }
        }
    };

    Collection<String> keys = storage.getKeys();
    Collection<E> elements = Collections2.filter(Collections2.transform(keys, toElementList),
            Predicates.notNull());

    return ImmutableList.copyOf(elements);
}

From source file:org.eclipse.buildship.ui.view.task.WorkbenchSelectionListener.java

private ImmutableList<IProject> convertToProjects(List<Object> selections) {
    return FluentIterable.from(selections).transform(new Function<Object, IProject>() {

        @Override//w w w .  j av  a2 s  . com
        public IProject apply(Object input) {
            if (input instanceof IProject) {
                return (IProject) input;
            } else if (input instanceof IJavaElement) {
                return ((IJavaElement) input).getJavaProject().getProject();
            } else if (input instanceof IResource) {
                return ((IResource) input).getProject();
            } else {
                return null;
            }
        }
    }).filter(Predicates.notNull()).toList();
}

From source file:org.apache.jackrabbit.oak.plugins.document.PropertyHistory.java

@Override
public Iterator<NodeDocument> iterator() {
    return ensureOrder(filter(transform(doc.getPreviousRanges().entrySet(),
            new Function<Map.Entry<Revision, Range>, Map.Entry<Revision, NodeDocument>>() {
                @Nullable/* www . j  av  a2s  . c om*/
                @Override
                public Map.Entry<Revision, NodeDocument> apply(Map.Entry<Revision, Range> input) {
                    Revision r = input.getKey();
                    int h = input.getValue().height;
                    String prevId = Utils.getPreviousIdFor(mainPath, r, h);
                    NodeDocument prev = doc.getPreviousDocument(prevId);
                    if (prev == null) {
                        LOG.debug("Document with previous revisions not found: " + prevId);
                        return null;
                    }
                    return new SimpleImmutableEntry<Revision, NodeDocument>(r, prev);
                }
            }), Predicates.notNull()));
}

From source file:de.javauni.jarcade.model.scene.SceneImpl.java

@Override
public Iterable<Entity> getAllEntities() {
    return Iterables.filter(entities, Predicates.notNull());
}

From source file:google.registry.ui.server.registrar.SendEmailUtils.java

/**
 * Sends an email from Nomulus to the specified recipient(s). Returns true iff sending was
 * successful.//from   w ww  .j a v  a2 s  .c o m
 */
public boolean sendEmail(Iterable<String> addresses, final String subject, String body) {
    try {
        Message msg = emailService.createMessage();
        msg.setFrom(new InternetAddress(googleAppsSendFromEmailAddress, googleAppsAdminEmailDisplayName));
        List<InternetAddress> emails = FluentIterable.from(addresses)
                .transform(new Function<String, InternetAddress>() {
                    @Override
                    public InternetAddress apply(String emailAddress) {
                        try {
                            return new InternetAddress(emailAddress, true);
                        } catch (AddressException e) {
                            logger.severefmt(e, "Could not send email to %s with subject '%s'.", emailAddress,
                                    subject);
                            // Returning null excludes this address from the list of recipients on the email.
                            return null;
                        }
                    }
                }).filter(Predicates.notNull()).toList();
        if (emails.isEmpty()) {
            return false;
        }
        msg.addRecipients(Message.RecipientType.TO, toArray(emails, InternetAddress.class));
        msg.setSubject(subject);
        msg.setText(body);
        emailService.sendMessage(msg);
    } catch (Throwable t) {
        logger.severefmt(t, "Could not email to addresses %s with subject '%s'.",
                Joiner.on(", ").join(addresses), subject);
        return false;
    }
    return true;
}

From source file:org.sonar.db.user.UserDao.java

/**
 * Gets a list users by their logins. The result does NOT contain {@code null} values for users not found, so
 * the size of result may be less than the number of keys.
 * A single user is returned if input keys contain multiple occurrences of a key.
 * <p>Contrary to {@link #selectByLogins(DbSession, Collection)}, results are in the same order as input keys.</p>
 *///from   www  .  ja v a2 s  .c o m
public List<UserDto> selectByOrderedLogins(DbSession session, Collection<String> logins) {
    List<UserDto> unordered = selectByLogins(session, logins);
    return from(logins).transform(new LoginToUser(unordered)).filter(Predicates.notNull()).toList();
}

From source file:net.shibboleth.idp.attribute.filter.AttributeFilterImpl.java

/**
 * Constructor.//from   w w  w .  j  a v a 2  s. c  o m
 * 
 * @param engineId ID of this engine
 * @param policies filter policies used by this engine
 */
public AttributeFilterImpl(@Nonnull @NotEmpty String engineId,
        @Nullable @NullableElements final Collection<AttributeFilterPolicy> policies) {
    setId(engineId);

    ArrayList<AttributeFilterPolicy> checkedPolicies = new ArrayList<AttributeFilterPolicy>();
    CollectionSupport.addIf(checkedPolicies, policies, Predicates.notNull());
    filterPolicies = ImmutableList.copyOf(Iterables.filter(checkedPolicies, Predicates.notNull()));
}

From source file:org.mayocat.shop.shipping.DefaultShippingService.java

@Override
public String getDestinationNames(List<String> destinationCodes) {
    if (destinationCodes == null) {
        // Garbage in, garbage out
        return null;
    }/*w w  w. j ava2  s. c  o  m*/

    Collection<String> result = Collections2.transform(destinationCodes, new Function<String, String>() {
        @Override
        public String apply(final String code) {
            return getDestinationName(code);
        }
    });
    result = (Collections2.filter(result, Predicates.notNull()));
    Joiner joiner = Joiner.on(", ");
    return joiner.join(result);
}

From source file:org.eclipse.sirius.ui.tools.internal.actions.export.AbstractExportRepresentationsAction.java

/**
 * Collect the diagrams to export, get the corresponding sessionn compute
 * the export path and then show the path and file format dialog to the user
 * before exporting export the diagrams.
 *//*w  ww .j a  v  a  2 s . co  m*/
@Override
public void run() {
    Collection<DRepresentation> collectedRepresentations = getDRepresentationToExport();
    Iterable<DRepresentation> dRepresentationsToExport = Iterables.filter(collectedRepresentations,
            Predicates.notNull());
    if (!Iterables.isEmpty(dRepresentationsToExport)) {
        DRepresentation firstDRepresentationToExport = dRepresentationsToExport.iterator().next();
        Session session = getSession(firstDRepresentationToExport);
        if (session != null) {
            IPath exportPath = getExportPath(firstDRepresentationToExport, session);

            if (exportPath != null) {
                exportRepresentation(exportPath, dRepresentationsToExport, session);
            }
        }
    }
}