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.google.api.server.spi.PeerAuth.java

@VisibleForTesting
Iterable<PeerAuthenticator> getPeerAuthenticatorInstances() {
    List<Class<? extends PeerAuthenticator>> classes = config.getPeerAuthenticators();
    return classes == null ? ImmutableList.of(DEFAULT_PEER_AUTHENTICATOR)
            : Iterables.filter(Iterables.transform(classes, INSTANTIATE_PEER_AUTHENTICATOR),
                    Predicates.notNull());
}

From source file:com.isotrol.impe3.web20.client.content.counter.GreatestHitsComponent.java

public ComponentResponse execute() {
    final Pagination pag = new Pagination(config.pageSize(), null);
    listing = ContentListingPage.empty(pag);
    // Fetch resources
    final CounterFilterDTO filter = new CounterFilterDTO();
    filter.setCounterType(config.counterType());
    List<ResourceCounterDTO> resources;
    try {/*  w w w  .jav a 2  s  .co m*/
        resources = service.getGreatestHits("", filter, Math.max(1, config.pageSize()));
    } catch (ServiceException e) {
        // TODO log
        return ComponentResponse.OK;
    }
    if (resources == null || resources.isEmpty()) {
        // Nothing to do
        return ComponentResponse.OK;
    }
    // Turn resources into keys
    final List<ContentKey> keys = Lists.newArrayListWithExpectedSize(resources.size());
    for (ResourceCounterDTO resource : Iterables.filter(resources, Predicates.notNull())) {
        final ContentKey ck = r2ck(resource.getResource());
        if (ck != null) {
            keys.add(ck);
        }
    }
    if (keys.isEmpty()) {
        // Nothing to do
        return ComponentResponse.OK;
    }
    // Perform the search
    ContentCriteria cc = loader.newCriteria();
    cc.setBytes(true);
    Map<ContentKey, Content> map = loader.newCriteria().setBytes(true).getContents(keys);
    if (map.isEmpty()) {
        // Nothing found
        return ComponentResponse.OK;
    }
    // Turn to listing
    final List<Content> contents = Lists.newArrayListWithExpectedSize(keys.size());
    for (ContentKey ck : keys) {
        final Content c = map.get(ck);
        if (c != null) {
            contents.add(c);
        }
    }
    listing = new ContentListingPage(null, pag, contents);
    return ComponentResponse.OK;
}

From source file:brooklyn.entity.messaging.activemq.ActiveMQBrokerImpl.java

@Override
protected void connectSensors() {
    setAttribute(BROKER_URL,//from ww  w .j  ava 2s  .co  m
            String.format("tcp://%s:%d", getAttribute(HOSTNAME), getAttribute(OPEN_WIRE_PORT)));

    String brokerMbeanName = "org.apache.activemq:type=Broker,brokerName=" + getBrokerName();

    jmxFeed = JmxFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS)
            .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP).objectName(brokerMbeanName)
                    .attributeName("BrokerName").onSuccess(Functions.forPredicate(Predicates.notNull()))
                    .onFailureOrException(Functions.constant(false)))
            .build();
}

From source file:org.eclipse.xtext.scoping.Scopes.java

/**
 * transforms an {@link Iterable} of {@link EObject}s into an {@link Iterable} of {@link IEObjectDescription}s computing
 * the name of the elements using the passed {@link Function} If the passed function returns null the object is
 * filtered out./*w  ww .j a va 2 s. c o m*/
 */
public static <T extends EObject> Iterable<IEObjectDescription> scopedElementsFor(
        Iterable<? extends T> elements, final Function<T, QualifiedName> nameComputation) {
    Iterable<IEObjectDescription> transformed = Iterables.transform(elements,
            new Function<T, IEObjectDescription>() {
                @Override
                public IEObjectDescription apply(T from) {
                    final QualifiedName qualifiedName = nameComputation.apply(from);
                    if (qualifiedName != null)
                        return new EObjectDescription(qualifiedName, from, null);
                    return null;
                }
            });
    return Iterables.filter(transformed, Predicates.notNull());
}

From source file:org.apache.brooklyn.entity.messaging.activemq.ActiveMQBrokerImpl.java

@Override
protected void connectSensors() {
    sensors().set(BROKER_URL,/*  w  w w . j a v a2s  .c om*/
            String.format("tcp://%s:%d", getAttribute(HOSTNAME), getAttribute(OPEN_WIRE_PORT)));

    String brokerMbeanName = "org.apache.activemq:type=Broker,brokerName=" + getBrokerName();

    jmxFeed = JmxFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS)
            .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP).objectName(brokerMbeanName)
                    .attributeName("BrokerName").onSuccess(Functions.forPredicate(Predicates.notNull()))
                    .onFailureOrException(Functions.constant(false)).suppressDuplicates(true))
            .build();
}

From source file:org.opensaml.storage.impl.client.SaveCookieBackedClientStorageServices.java

/**
 * Set the {@link ClientStorageService} instances to check for loading.
 * //from   w  w  w  .ja  v a2 s.  c  o m
 * @param services instances to check for loading
 */
public void setStorageServices(@Nonnull @NonnullElements final Collection<ClientStorageService> services) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);

    Constraint.isNotNull(services, "StorageService collection cannot be null");
    storageServices = new HashMap<>(services.size());
    for (final ClientStorageService ss : Collections2.filter(services, Predicates.notNull())) {
        storageServices.put(ss.getId(), ss);
    }
}

From source file:net.shibboleth.idp.authn.principal.impl.InexactPrincipalEvalPredicateFactory.java

/**
 * Set the matching rules to apply.// ww w.j  a  v a  2  s .c o m
 * 
 * <p>The input is a map of sets for bean compatibility.</p>
 * 
 * @param rules matching rules
 */
public void setMatchingRules(@Nonnull @NonnullElements final Map<String, Collection<String>> rules) {
    Constraint.isNotNull(rules, "Map cannot be null");
    matchingRules.clear();

    for (Map.Entry<String, Collection<String>> e : rules.entrySet()) {
        if (!Strings.isNullOrEmpty(e.getKey()) && e.getValue() != null) {
            matchingRules.putAll(e.getKey(),
                    new HashSet(Collections2.filter(e.getValue(), Predicates.notNull())));
        }
    }
}

From source file:org.obiba.opal.core.identifiers.IdentifiersMaps.java

/**
 * Get all private entities: entities with non-null private identifiers.
 *
 * @return/* www .  ja  va 2  s. c  om*/
 */
public Iterable<VariableEntity> getPrivateEntities() {
    return Iterables.filter(Iterables.transform(this, new Function<IdentifiersMap, VariableEntity>() {

        @Override
        public VariableEntity apply(IdentifiersMap from) {
            return from.hasPrivateIdentifier() ? from.getPrivateEntity() : null;
        }

    }), Predicates.notNull());
}

From source file:de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRowsSaver.java

public List<PurchaseCandidate> save(@NonNull final List<PurchaseRow> groupingRows) {
    final Set<DemandGroupReference> demandIds = extractDemandIds(groupingRows);
    final Map<PurchaseCandidateId, PurchaseCandidate> existingPurchaseCandidatesById = getExistingPurchaseCandidatesIndexedById(
            demandIds);//from w  ww .j a v  a  2 s.co m

    //
    // Create/Update purchase candidates (this used to be stream-based, but it was too hard to debug)
    final List<PurchaseCandidate> purchaseCandidatesToSave = new ArrayList<>();
    final List<PurchaseCandidatesGroup> purchaseCandidatesGroups = extractPurchaseCandidatesGroups(
            groupingRows);
    for (final PurchaseCandidatesGroup purchaseCandidatesGroup : purchaseCandidatesGroups) {
        final List<PurchaseCandidate> purchaseCandidates = createOrUpdatePurchaseCandidate(
                purchaseCandidatesGroup, existingPurchaseCandidatesById);
        purchaseCandidatesToSave.addAll(purchaseCandidates);
    }

    purchaseCandidatesRepo.saveAll(purchaseCandidatesToSave);

    //
    // Zerofy remaining candidates:
    final Set<PurchaseCandidateId> purchaseCandidateIdsSaved = purchaseCandidatesToSave.stream()
            .map(PurchaseCandidate::getId).filter(Predicates.notNull()).collect(ImmutableSet.toImmutableSet());
    final List<PurchaseCandidate> purchaseCandidatesToZero = existingPurchaseCandidatesById.values().stream()
            .filter(candidate -> !candidate.isProcessedOrLocked()) // don't delete processed/locked candidates
            .filter(candidate -> !purchaseCandidateIdsSaved.contains(candidate.getId())).peek(candidate -> {
                candidate.setQtyToPurchase(candidate.getQtyToPurchase().toZero());
                candidate.setPrepared(false);
            }).collect(ImmutableList.toImmutableList());
    purchaseCandidatesRepo.saveAll(purchaseCandidatesToZero);

    return purchaseCandidatesToSave;
}

From source file:es.uah.aut.srg.micobs.xtext.MICOBSElementAbstractScopeProvider.java

public IScope scope_MCommonPackageFile_package(final MCommonPackageFile file, EReference pack) {
    Collection<MCommonPackage> packageList = null;
    try {/*from  w  ww.  jav a 2  s.  co m*/
        packageList = getFileLibraryManager().getAllPackages();
    } catch (LibraryManagerException e) {
        MICOBSPlugin.INSTANCE.log(e);
        return IScope.NULLSCOPE;
    }

    Iterable<IEObjectDescription> descriptions = Iterables.transform(packageList,
            new Function<MCommonPackage, IEObjectDescription>() {

                @Override
                public IEObjectDescription apply(MCommonPackage from) {
                    return EObjectDescription.create(qualifiedNameProvider.getFullyQualifiedName(from), from);
                }
            });

    return new SimpleScope(IScope.NULLSCOPE, Iterables.filter(descriptions, Predicates.notNull()));
}