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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:org.batoo.jpa.parser.MappingException.java

private static String getLocation(AbstractLocator[] locators) {
    if (locators == null) {
        return "";
    }/*from w  ww  .  j a v a2s  .  c o  m*/

    final Collection<AbstractLocator> filteredLocators = Collections2.filter(Arrays.asList(locators),
            Predicates.not(Predicates.isNull()));
    if (filteredLocators.size() == 0) {
        return "";
    }

    return " Defined at:" + (filteredLocators.size() > 1 ? "\n\t" : " ")
            + Joiner.on("\n\t").skipNulls().join(filteredLocators);
}

From source file:com.samskivert.depot.impl.operator.BaseOperator.java

public static <S, T> boolean all(Function<S, T> fun, S... obj) {
    return Iterables.all(Arrays.asList(obj), Predicates.compose(Predicates.isNull(), fun));
}

From source file:org.apache.gobblin.runtime.listeners.JobListeners.java

/**
 * Chains a given {@link List} of {@link JobListener}s into a single {@link JobListener}. The specified {@link JobListener}s
 * will all be executed in parallel.//  w  ww. ja  va  2  s  .com
 *
 * @param jobListeners is a {@link List} of {@link JobListener}s that need to be executed
 *
 * @return a {@link CloseableJobListener}, which is similar to {@link JobListener}, except
 * {@link CloseableJobListener#close()} will block until all {@link JobListener}s have finished their executions.
 */
public static CloseableJobListener parallelJobListener(List<JobListener> jobListeners) {
    Iterables.removeIf(jobListeners, Predicates.isNull());
    return new ParallelJobListener(jobListeners);
}

From source file:org.apache.abdera2.common.misc.MorePredicates.java

/**
 * Returns a Predicate that checks if the named property of instances of
 * the specified class are null. The named property MUST NOT be private 
 * and MUST NOT require any input parameters. The method name is case
 * sensitive. /*from  www . j  a  v a 2 s. c o  m*/
 */
public static <T> Selector<T> isNull(Class<T> _class, String method) {
    return PropertySelector.<T>create(_class, method, Predicates.isNull());
}

From source file:org.apache.abdera2.common.misc.MorePredicates.java

/**
 * Returns a Predicate that checks if the named property of instances of
 * the specified class are not null. The named property MUST NOT be private 
 * and MUST NOT require any input parameters. The method name is case
 * sensitive. //from   w w  w  .  j  av a 2s .c  o  m
 */
public static <T> Selector<T> isNotNull(Class<T> _class, String method) {
    return PropertySelector.<T>create(_class, method, Predicates.not(Predicates.isNull()));
}

From source file:com.eucalyptus.reporting.domain.ReportingAccountDao.java

public ReportingAccount getReportingAccount(String accountId) {

    ReportingAccount searchAccount = new ReportingAccount();
    searchAccount.setId(accountId);/* w ww .  j  a  v  a 2 s .  c  om*/
    List<ReportingAccount> foundAccountList = Lists.newArrayList();

    EntityTransaction db = Entities.get(ReportingAccount.class);
    try {

        foundAccountList = (List<ReportingAccount>) Entities.query(searchAccount, true);

        db.commit();
    } catch (Exception ex) {
        LOG.error(ex, ex);
        foundAccountList.clear();
    } finally {
        if (db.isActive())
            db.rollback();
    }

    if (foundAccountList.isEmpty()) {
        return null;
    }

    Iterables.removeIf(foundAccountList, Predicates.isNull());
    return foundAccountList.get(0);

}

From source file:com.atlassian.jira.license.MultiLicenseStoreImpl.java

@Override
public void store(@Nonnull final Iterable<String> newLicenseKeys) {
    checkNotNull(newLicenseKeys, "newLicenseKeys");
    if (licenseRolesAreEnabled()) {
        if (Iterables.isEmpty(newLicenseKeys)) {
            throw new IllegalArgumentException("You must store at least one license.");
        }/*  w  ww  .  j a  v  a 2s  . c o  m*/

        if (any(newLicenseKeys, Predicates.isNull())) {
            throw new IllegalArgumentException(
                    "You cannot store null licenses - no changes have been made to licenses.");
        }

        entityEngine.delete(from(PRODUCT_LICENSE).all());

        for (String licenseKey : newLicenseKeys) {
            entityEngine.createValue(PRODUCT_LICENSE, new ProductLicense(licenseKey));
        }

        String singleLicense = trimToNull(jiraLicenseStore.retrieve());
        if (singleLicense != null) {
            jiraLicenseStore.remove();
        }
    } else {
        Iterator<String> iterator = newLicenseKeys.iterator();
        if (iterator.hasNext()) {
            jiraLicenseStore.store(iterator.next());
        } else {
            jiraLicenseStore.store(null);
        }
    }
}

From source file:com.eucalyptus.reporting.domain.ReportingUserDao.java

private List<ReportingUser> searchReportingUser(final ReportingUser searchUser) {

    List<ReportingUser> reportingUserList = Lists.newArrayList();
    EntityTransaction db = Entities.get(ReportingUser.class);

    try {/*from   www. j  a v a 2s.  c om*/
        reportingUserList = (List<ReportingUser>) Entities.query(searchUser, true);
        db.commit();
    } catch (Exception ex) {
        LOG.error(ex, ex);
        reportingUserList.clear();
    } finally {
        if (db.isActive())
            db.rollback();
    }

    Iterables.removeIf(reportingUserList, Predicates.isNull());
    if (!reportingUserList.isEmpty()) {
        return reportingUserList;
    } else {
        return null;
    }
}

From source file:org.apache.brooklyn.core.sensor.password.CreatePasswordSensor.java

@Override
public void apply(EntityLocal entity) {
    super.apply(entity);

    boolean isCharacterGroupsPresent = characterGroups != null && characterGroups.size() > 0;
    boolean isCharacterGroupsValid = isCharacterGroupsPresent
            && !Iterables.contains(characterGroups, Predicates.isNull())
            && !Iterables.contains(characterGroups, Predicates.equalTo(""));
    boolean isAcceptableCharsPresentAndValid = acceptableChars != null && !acceptableChars.isEmpty();

    Preconditions.checkArgument(!isCharacterGroupsPresent || isCharacterGroupsValid,
            "password.character.groups config key was given but does not contain any valid groups");
    Preconditions.checkArgument(!(isCharacterGroupsPresent && isAcceptableCharsPresentAndValid),
            "password.chars and password.character.groups both provided - please provide only ONE of them");
    Preconditions.checkArgument(!isCharacterGroupsValid || characterGroups.size() <= passwordLength,
            "password.length must be longer than the number of entries in password.character.groups");

    String password;//w w  w. jav a  2 s . c om
    if (isCharacterGroupsValid) {
        password = Identifiers.makeRandomPassword(passwordLength, characterGroups.toArray(new String[0]));
    } else if (isAcceptableCharsPresentAndValid) {
        password = Identifiers.makeRandomPassword(passwordLength, acceptableChars);
    } else {
        password = Identifiers.makeRandomPassword(passwordLength);
    }

    entity.sensors().set(sensor, password);
}

From source file:io.crate.executor.transport.StreamBucket.java

private static boolean validStreamers(Streamer<?>[] streamers) {
    if (streamers == null || streamers.length == 0) {
        return true;
    }/*w  w  w .jav  a  2  s.  co m*/
    return !Iterables.all(FluentIterable.of(streamers), Predicates.isNull());
}