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.opensaml.saml.saml2.profile.impl.AddStatusToResponse.java

/**
 * Set the list of status code values to insert, ordered such that the top level code is first
 * and every other code will be nested inside the previous one.
 * //from w  w w.j av a2 s .c  om
 * @param codes list of status code values to insert
 */
public void setStatusCodes(@Nonnull @NonnullElements List<String> codes) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);

    Constraint.isNotNull(codes, "Status code list cannot be null");
    defaultStatusCodes = new ArrayList<>(Collections2.filter(codes, Predicates.notNull()));
}

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

/**
 * Set the list of status code values to insert, ordered such that the top level code is first
 * and every other code will be nested inside the previous one.
 * //  w w  w.j a v  a 2s.  co m
 * @param codes list of status code values to insert
 */
public synchronized void setStatusCodes(@Nonnull @NonnullElements List<String> codes) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);

    Constraint.isNotNull(codes, "Status code list cannot be null");
    statusCodes = Lists.newArrayList(Collections2.filter(codes, Predicates.notNull()));
}

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

/**
 * Set the list of status code values to insert, ordered such that the top level code is first
 * and every other code will be nested inside the previous one.
 * /*from   w w  w .j  a  v  a 2s.c  om*/
 * @param codes list of status code values to insert
 */
public synchronized void setStatusCodes(@Nonnull @NonnullElements List<QName> codes) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);

    Constraint.isNotNull(codes, "Status code list cannot be null");
    statusCodes = Lists.newArrayList(Collections2.filter(codes, Predicates.notNull()));
}

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

protected void doOpenPortForwardingAndAdvertise(final EntityAndAttribute<Integer> source,
        final Optional<Integer> optionalPublicPort, final Protocol protocol, final Cidr accessingCidr,
        final Advertiser advertiser) {
    DeferredExecutor<Integer> updater = new DeferredExecutor<>("open-port-forwarding", source,
            Predicates.notNull(), Boolean.FALSE, new Runnable() {

                private AtomicReference<MachineAndPort> updated = new AtomicReference<>();

                @Override//from   w  w w  .  jav  a2s. c  o  m
                public void run() {
                    Entity entity = source.getEntity();
                    Integer privatePortVal = source.getValue();
                    if (privatePortVal == null) {
                        if (log.isDebugEnabled())
                            log.debug("Private port null for entity {}; not opening or advertising mapped port",
                                    entity, source.getAttribute().getName());
                        return;
                    }
                    Maybe<MachineLocation> machineLocationMaybe = Machines
                            .findUniqueMachineLocation(entity.getLocations());
                    if (machineLocationMaybe.isAbsent()) {
                        if (log.isDebugEnabled())
                            log.debug("No machine found for entity {}; not opening or advertising mapped port",
                                    entity);
                        return;
                    }
                    MachineLocation machine = machineLocationMaybe.get();
                    MachineAndPort machineAndPort = new MachineAndPort(machine, privatePortVal);

                    // Check if another thread is already opening the port-forwarding.
                    // This can happen because the DeferredExecutor submits the task, and does 
                    // not block for completion (hence allowing us to open ports in parallel).
                    // Given we have multiple subscriptions (for location + port), we can get
                    // called multiple times concurrently.
                    if (updated.compareAndSet(null, machineAndPort)) {
                        // We got here first; we open the port-forwarding.
                    } else if (machineAndPort.equals(updated.get())) {
                        if (log.isDebugEnabled())
                            log.debug(
                                    "Already created port-mapping for entity {}, at {} -> {}; not opening again",
                                    new Object[] { entity, machine, privatePortVal });
                        return;
                    } else {
                        // Check again before logging, in case updated was cleared - 
                        // can happen if openPortForwarding returns null.
                        MachineAndPort oldMachineAndPort = updated.get();
                        if (oldMachineAndPort != null) {
                            log.info(
                                    "Previous port-forwarding for {} used different machine:port ({}:{}, compared to now {}:{}); "
                                            + "opening with new machine:port",
                                    new Object[] { entity, oldMachineAndPort.machine, oldMachineAndPort.port,
                                            machineAndPort.machine, machineAndPort.port });
                        }
                    }

                    HostAndPort publicEndpoint;
                    try {
                        publicEndpoint = portForwarder.openPortForwarding(machine, privatePortVal,
                                optionalPublicPort, protocol, accessingCidr);
                    } catch (Throwable t) {
                        updated.set(null);
                        throw Exceptions.propagate(t);
                    }
                    if (publicEndpoint == null) {
                        // Failed to open port-forwarding; clear "updated" so another thread can have a go
                        // if we are ever called again.
                        log.warn("No host:port obtained for " + machine + " -> " + privatePortVal
                                + "; not advertising mapped port");
                        updated.set(null);
                        return;
                    }

                    // TODO What publicIpId to use in portForwardManager.associate? Elsewhere, uses jcloudsMachine.getJcloudsId().
                    portForwarder.getPortForwardManager().associate(machine.getId(), publicEndpoint, machine,
                            privatePortVal);

                    advertiser.advertise(source, publicEndpoint);
                    log.debug("Set target sensor, advertising mapping of {}->{} ({})",
                            new Object[] { entity, source.getAttribute().getName(), publicEndpoint });
                }
            });

    subscribe(ImmutableMap.of("notifyOfInitialValue", Boolean.TRUE), source.getEntity(), source.getAttribute(),
            updater);
    subscribe(source.getEntity(), AbstractEntity.LOCATION_ADDED, updater);
}

From source file:de.metas.ui.web.pickingV2.productsToPick.ProductsToPickRowsDataFactory.java

private List<ProductsToPickRow> createRowsFromPickingCandidates(final AllocablePackageable packageable) {
    final List<PickingCandidate> pickingCandidates = pickingCandidateRepo.getByShipmentScheduleIdAndStatus(
            packageable.getShipmentScheduleId(), PickingCandidateStatus.Draft);

    return pickingCandidates.stream()
            .map(pickingCandidate -> createRowFromPickingCandidate(packageable, pickingCandidate))
            .filter(Predicates.notNull()).collect(ImmutableList.toImmutableList());
}

From source file:io.urmia.naming.service.ZkNamingServiceImpl.java

@Override
public List<NodeType> queryTypes() throws Exception {
    return FluentIterable.from(naming.queryForNames()).transform(nameToType()).filter(Predicates.notNull())
            .toList();// w  w w . ja  va  2s.c om
}

From source file:org.killbill.billing.util.security.shiro.realm.KillBillJndiLdapRealm.java

private Set<String> findLDAPGroupsForUser(final String userName, final LdapContext ldapCtx)
        throws NamingException {
    final NamingEnumeration<SearchResult> foundGroups = ldapCtx.search(searchBase,
            groupSearchFilter.replace(USERDN_SUBSTITUTION_TOKEN, userName), SUBTREE_SCOPE);

    // Extract the name of all the groups
    final Iterator<SearchResult> groupsIterator = Iterators.<SearchResult>forEnumeration(foundGroups);
    final Iterator<String> groupsNameIterator = Iterators.<SearchResult, String>transform(groupsIterator,
            new Function<SearchResult, String>() {
                @Override//from   w w  w .  ja  v a  2  s.  co  m
                public String apply(final SearchResult groupEntry) {
                    return extractGroupNameFromSearchResult(groupEntry);
                }
            });
    final Iterator<String> finalGroupsNameIterator = Iterators.<String>filter(groupsNameIterator,
            Predicates.notNull());

    return Sets.newHashSet(finalGroupsNameIterator);
}

From source file:org.apache.hadoop.hive.metastore.utils.MetaStoreServerUtils.java

/**
 * We have a need to sanity-check the map before conversion from persisted objects to
 * metadata thrift objects because null values in maps will cause a NPE if we send
 * across thrift. Pruning is appropriate for most cases except for databases such as
 * Oracle where Empty strings are stored as nulls, in which case we need to handle that.
 * See HIVE-8485 for motivations for this.
 *///from   w w  w  .  ja v a 2s .co  m
public static Map<String, String> trimMapNulls(Map<String, String> dnMap,
        boolean retrieveMapNullsAsEmptyStrings) {
    if (dnMap == null) {
        return null;
    }
    // Must be deterministic order map - see HIVE-8707
    //   => we use Maps.newLinkedHashMap instead of Maps.newHashMap
    if (retrieveMapNullsAsEmptyStrings) {
        // convert any nulls present in map values to empty strings - this is done in the case
        // of backing dbs like oracle which persist empty strings as nulls.
        return Maps.newLinkedHashMap(Maps.transformValues(dnMap, transFormNullsToEmptyString));
    } else {
        // prune any nulls present in map values - this is the typical case.
        return Maps.newLinkedHashMap(Maps.filterValues(dnMap, Predicates.notNull()));
    }
}

From source file:net.shibboleth.idp.authn.AbstractValidationAction.java

/**
 * Set the error messages indicating an unknown username.
 * //  w w w.j  a va  2 s. c  om
 * @param messages the "unknown username" error messages to set
 */
public void setClassifiedMessages(@Nonnull @NonnullElements final Map<String, Collection<String>> messages) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
    Constraint.isNotNull(messages, "Map of classified messages cannot be null");

    classifiedMessages = new HashMap<>();
    for (final Map.Entry<String, Collection<String>> entry : messages.entrySet()) {
        if (entry.getKey() != null && !entry.getKey().isEmpty() && entry.getValue() != null
                && !entry.getValue().isEmpty()) {
            classifiedMessages.put(entry.getKey(),
                    ImmutableList.copyOf(Collections2.filter(entry.getValue(), Predicates.notNull())));
        }
    }
}

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

private static final OrderId getSingleSalesOrderId(@NonNull final List<PurchaseCandidate> purchaseCandidates) {
    Check.assumeNotEmpty(purchaseCandidates, "purchaseCandidates not empty");

    return purchaseCandidates.stream().map(PurchaseCandidate::getSalesOrderAndLineIdOrNull)
            .filter(Predicates.notNull()).map(OrderAndLineId::getOrderId).distinct()
            .collect(GuavaCollectors.singleElementOrThrow(() -> new AdempiereException(
                    "More or less than one salesOrderId found in the given purchaseCandidates")
                            .appendParametersToMessage()
                            .setParameter("purchaseCandidates", purchaseCandidates)));
}