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.eclipse.sirius.diagram.business.internal.experimental.sync.AbstractSynchronizerHelper.java

/**
 * ./*w  w  w.j  a v  a  2s  .  c  o m*/
 * 
 * @param container
 *            .
 * @param mapping
 *            .
 * @return .
 */
protected Collection<EObject> getPreviousSemanticsElements(DragAndDropTarget container,
        DiagramElementMapping mapping) {
    Collection<EObject> transformed = Collections2.transform(
            sync.getPreviousDiagramElements(container, mapping), new Function<DDiagramElement, EObject>() {
                public EObject apply(final DDiagramElement from) {
                    return from.getTarget();
                }
            });
    return ImmutableSet.copyOf(
            Collections2.filter(transformed, Predicates.and(Predicates.notNull(), new Predicate<EObject>() {
                // We don't keep semantic element that is invalid
                public boolean apply(final EObject input) {
                    return (input.eContainer() != null && input.eContainer().eResource() != null)
                            || input.eResource() != null;
                }
            })));
}

From source file:com.preferanser.client.application.widgets.TablePanel.java

public void layoutLocation(final TableLocation location) {
    if (CENTER == location) {
        centerCardLayout.apply(centerHandCards);
    } else {/*from  w  ww . j a v  a2  s. c  o  m*/
        Panel panel = locationPanelMap.get(location);
        assert panel != null : "Panel for " + location + " is null";

        Layout<CardWidget> layout = locationLayoutMap.get(location);
        assert layout != null : "Layout for " + location + " is null";

        Collection<CardWidget> cardWidgets = newArrayList(
                filter(transform(panel, new Function<Widget, CardWidget>() {
                    @Nullable
                    @Override
                    public CardWidget apply(@Nullable Widget widget) {
                        return widget instanceof CardWidget ? (CardWidget) widget : null;
                    }
                }), Predicates.notNull()));

        layout.apply(cardWidgets);
    }
}

From source file:net.derquinse.common.meta.MetaProperty.java

/**
 * Returns a predicate that evaluates to {@code true} if the property value being tested is not
 * null.// ww w . j  a  v a 2  s.co  m
 */
public final Predicate<C> notNull() {
    return compose(Predicates.notNull());
}

From source file:net.shibboleth.idp.saml.saml1.profile.impl.AddAttributeStatementToAssertion.java

/**
 * Builds an attribute statement from a collection of attributes.
 * //w  w  w .  ja  v  a  2 s. c  o  m
 * @param profileRequestContext current profile request context
 * @param attributes the collection of attributes
 * 
 * @return the attribute statement or null if no attributes can be encoded
 * @throws AttributeEncodingException thrown if there is a problem encoding an attribute
 */
@Nullable
private AttributeStatement buildAttributeStatement(@Nonnull final ProfileRequestContext profileRequestContext,
        @Nullable @NullableElements final Collection<IdPAttribute> attributes)
        throws AttributeEncodingException {
    if (attributes == null || attributes.isEmpty()) {
        log.debug("{} No attributes available to be encoded, nothing to do", getLogPrefix());
        return null;
    }

    final ArrayList<Attribute> encodedAttributes = new ArrayList<>(attributes.size());
    for (final IdPAttribute attribute : Collections2.filter(attributes, Predicates.notNull())) {
        encodeAttribute(profileRequestContext, attribute, encodedAttributes);
    }

    if (encodedAttributes.isEmpty()) {
        log.debug("{} No attributes were encoded as SAML 1 Attributes, nothing to do", getLogPrefix());
        return null;
    }

    final SAMLObjectBuilder<AttributeStatement> statementBuilder = (SAMLObjectBuilder<AttributeStatement>) XMLObjectProviderRegistrySupport
            .getBuilderFactory().<AttributeStatement>getBuilderOrThrow(AttributeStatement.DEFAULT_ELEMENT_NAME);

    final AttributeStatement statement = statementBuilder.buildObject();
    statement.getAttributes().addAll(encodedAttributes);
    return statement;
}

From source file:net.shibboleth.idp.saml.saml2.profile.impl.AddAttributeStatementToAssertion.java

/**
 * Builds an attribute statement from a collection of attributes.
 * //from   w  w w.j  a  v a 2s  . c om
 * @param profileRequestContext current profile request context
 * @param attributes the collection of attributes
 * 
 * @return the attribute statement or null if no attributes can be encoded
 * @throws AttributeEncodingException thrown if there is a problem encoding an attribute
 */
@Nullable
private AttributeStatement buildAttributeStatement(@Nonnull final ProfileRequestContext profileRequestContext,
        @Nullable @NullableElements final Collection<IdPAttribute> attributes)
        throws AttributeEncodingException {
    if (attributes == null || attributes.isEmpty()) {
        log.debug("{} No attributes available to be encoded, nothing to do", getLogPrefix());
        return null;
    }

    final ArrayList<Attribute> encodedAttributes = new ArrayList<>(attributes.size());
    for (final IdPAttribute attribute : Collections2.filter(attributes, Predicates.notNull())) {
        encodeAttribute(profileRequestContext, attribute, encodedAttributes);
    }

    if (encodedAttributes.isEmpty()) {
        log.debug("{} No attributes were encoded as SAML 2 Attributes, nothing to do", getLogPrefix());
        return null;
    }

    final SAMLObjectBuilder<AttributeStatement> statementBuilder = (SAMLObjectBuilder<AttributeStatement>) XMLObjectProviderRegistrySupport
            .getBuilderFactory().<AttributeStatement>getBuilderOrThrow(AttributeStatement.DEFAULT_ELEMENT_NAME);

    final AttributeStatement statement = statementBuilder.buildObject();
    statement.getAttributes().addAll(encodedAttributes);
    return statement;
}

From source file:io.hops.transaction.context.BaseEntityContext.java

private Collection<Entity> filterValues(final State state, final boolean not) {
    Collection<Entity> entities = Maps.transformValues(contextEntities, new Function<ContextEntity, Entity>() {
        @Override/*from   www  . j a  v a2  s.  co  m*/
        public Entity apply(ContextEntity input) {
            if (not ? (input.getState() != state) : (input.getState() == state)) {
                return input.getEntity();
            }
            return null;
        }
    }).values();
    return Collections2.filter(entities, Predicates.notNull());
}

From source file:org.eclipse.viatra.integration.graphiti.GraphitiModelConnector.java

@Override
protected Collection<EObject> getSelectedEObjects(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        //XXX after Graphiti 0.9 GraphitiShapeEditPart would be the related type, but that is not available in 0.8
        Iterator<ContainerShapeEditPart> selectionIterator = Iterators
                .filter((((IStructuredSelection) selection).iterator()), ContainerShapeEditPart.class);
        return Lists.newArrayList(Iterators
                .filter(Iterators.transform(selectionIterator, new Function<ContainerShapeEditPart, EObject>() {

                    @Override//from w w w. j av  a2 s  .  com
                    public EObject apply(ContainerShapeEditPart input) {
                        return Graphiti.getLinkService()
                                .getBusinessObjectForLinkedPictogramElement(input.getPictogramElement());
                    }
                }), Predicates.notNull()));
    } else {
        return super.getSelectedEObjects();
    }
}

From source file:org.obm.imap.archive.services.MailerImpl.java

@VisibleForTesting
Address[] internetAddresses(Mailing mailing) {
    return FluentIterable.from(mailing.getEmailAddresses()).transform(new Function<EmailAddress, Address>() {

        @Override//  www .j  ava2  s  .  c o m
        public Address apply(EmailAddress emailAddress) {
            try {
                return new InternetAddress(emailAddress.get());
            } catch (AddressException e) {
                logger.error("Can't get an internet address for " + emailAddress.get(), e);
                return null;
            }
        }
    }).filter(Predicates.notNull()).toArray(Address.class);
}

From source file:net.shibboleth.idp.attribute.resolver.AbstractResolverPlugin.java

/**
 * Sets the list of dependencies for this plugin.
 * /*w ww  .  j  a v  a 2s. c om*/
 * @param pluginDependencies unmodifiable list of dependencies for this plugin
 */
public void setDependencies(
        @Nullable @NullableElements final Set<ResolverPluginDependency> pluginDependencies) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
    ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);

    HashSet<ResolverPluginDependency> checkedDeps = new HashSet<>();
    CollectionSupport.addIf(checkedDeps, pluginDependencies, Predicates.notNull());
    dependencies = Collections.unmodifiableSet(checkedDeps);
}

From source file:com.google.gerrit.server.index.Schema.java

/**
 * Build all fields in the schema from an input object.
 *
 * <p>Null values are omitted, as are fields which cause errors, which are logged.
 *
 * @param obj input object./*from   ww w .j  a  v a2s. c o m*/
 * @param fillArgs arguments for filling fields.
 * @return all non-null field values from the object.
 */
public final Iterable<Values<T>> buildFields(final T obj, final FillArgs fillArgs) {
    return FluentIterable.from(fields.values()).transform(new Function<FieldDef<T, ?>, Values<T>>() {
        @Override
        public Values<T> apply(FieldDef<T, ?> f) {
            Object v;
            try {
                v = f.get(obj, fillArgs);
            } catch (OrmException e) {
                log.error(String.format("error getting field %s of %s", f.getName(), obj), e);
                return null;
            }
            if (v == null) {
                return null;
            } else if (f.isRepeatable()) {
                return new Values<>(f, (Iterable<?>) v);
            } else {
                return new Values<>(f, Collections.singleton(v));
            }
        }
    }).filter(Predicates.notNull());
}