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.sonar.server.computation.task.projectanalysis.step.LoadMeasureComputersStep.java

private static Iterable<MeasureComputerWrapper> getDependencies(MeasureComputerWrapper measureComputer,
        ToComputerByKey toComputerByOutputMetricKey) {
    // Remove null computer because a computer can depend on a metric that is only generated by a sensor or on a core metrics
    return from(measureComputer.getDefinition().getInputMetrics()).transform(toComputerByOutputMetricKey)
            .filter(Predicates.notNull());
}

From source file:net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext.java

/**
 * Set the (internal) names of the attributes requested to be resolved.
 * /*from   w  w  w. j  a v  a  2  s  .c  o  m*/
 * @param names the (internal) names of the attributes requested to be resolved
 */
public void setRequestedIdPAttributeNames(@Nonnull @NonnullElements final Collection<String> names) {
    Constraint.isNotNull(names, "Requested IdPAttribute collection cannot be null");

    requestedAttributeNames = new HashSet<>(Collections2.filter(names, Predicates.notNull()));
}

From source file:org.locationtech.geogig.storage.sqlite.SQLiteObjectDatabase.java

@Override
public Iterator<RevObject> getAll(Iterable<ObjectId> ids, final BulkOpListener listener) {
    return filter(transform(ids, new Function<ObjectId, RevObject>() {
        @Override//w  w w  .j  a  v  a 2s. co  m
        public RevObject apply(ObjectId id) {
            RevObject obj = getIfPresent(id);
            if (obj == null) {
                listener.notFound(id);
            } else {
                listener.found(id, null);
            }
            return obj;
        }
    }), Predicates.notNull()).iterator();
}

From source file:net.shibboleth.idp.cas.config.impl.LoginConfiguration.java

/**
 * Set the name identifier formats to use.
 *
 * @param formats name identifier formats to use
 */// ww w . java2s  . co m
public void setNameIDFormatPrecedence(@Nonnull @NonnullElements final List<String> formats) {
    Constraint.isNotNull(formats, "List of formats cannot be null");

    nameIDFormatPrecedence = new ArrayList<>(Collections2.filter(formats, Predicates.notNull()));
}

From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.design.system.model.NormalizedNamingAuthority.java

private void readObject(final ObjectInputStream objectInputStream) throws ClassNotFoundException, IOException {
    objectInputStream.defaultReadObject();

    Preconditions.checkNotNull(this.normalizer);
    Preconditions.checkArgument(this.counter >= 0);
    Preconditions.checkNotNull(this.used);

    final Collection<String> nonNullUsed = Collections2.filter(this.used, Predicates.notNull());
    Preconditions.checkArgument(nonNullUsed.size() == this.used.size());
}

From source file:org.geogit.geotools.plumbing.ExportOp.java

/**
 * Executes the export operation using the parameters that have been specified.
 * /*from w w w  .j a v a2  s.  c om*/
 * @return a FeatureCollection with the specified features
 */
@SuppressWarnings("deprecation")
@Override
public SimpleFeatureStore call() {

    if (filterFeatureTypeId != null) {
        RevObject filterType = database.getIfPresent(filterFeatureTypeId);
        checkArgument(filterType instanceof RevFeatureType, "Provided filter feature type is does not exist");
    }

    final SimpleFeatureStore targetStore = getTargetStore();

    final String refspec = resolveRefSpec();
    final String treePath = refspec.substring(refspec.indexOf(':') + 1);
    final RevTree rootTree = resolveRootTree(refspec);
    final NodeRef typeTreeRef = resolTypeTreeRef(refspec, treePath, rootTree);

    final ObjectId defaultMetadataId = typeTreeRef.getMetadataId();

    final RevTree typeTree = database.getTree(typeTreeRef.objectId());

    final ProgressListener progressListener = getProgressListener();

    progressListener.started();
    progressListener.setDescription("Exporting " + path + "... ");

    FeatureCollection<SimpleFeatureType, SimpleFeature> asFeatureCollection = new BaseFeatureCollection<SimpleFeatureType, SimpleFeature>() {

        @Override
        public FeatureIterator<SimpleFeature> features() {

            final Iterator<SimpleFeature> plainFeatures = getFeatures(typeTree, database, defaultMetadataId,
                    progressListener);

            Iterator<SimpleFeature> adaptedFeatures = adaptToArguments(plainFeatures, defaultMetadataId);

            Iterator<Optional<Feature>> transformed = Iterators.transform(adaptedFeatures,
                    ExportOp.this.function);

            Iterator<SimpleFeature> filtered = Iterators
                    .filter(Iterators.transform(transformed, new Function<Optional<Feature>, SimpleFeature>() {
                        @Override
                        public SimpleFeature apply(Optional<Feature> input) {
                            return (SimpleFeature) (input.isPresent() ? input.get() : null);
                        }
                    }), Predicates.notNull());

            return new DelegateFeatureIterator<SimpleFeature>(filtered);
        }
    };

    // add the feature collection to the feature store
    final Transaction transaction;
    if (transactional) {
        transaction = new DefaultTransaction("create");
    } else {
        transaction = Transaction.AUTO_COMMIT;
    }
    try {
        targetStore.setTransaction(transaction);
        try {
            targetStore.addFeatures(asFeatureCollection);
            transaction.commit();
        } catch (final Exception e) {
            if (transactional) {
                transaction.rollback();
            }
            Throwables.propagateIfInstanceOf(e, GeoToolsOpException.class);
            throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD);
        } finally {
            transaction.close();
        }
    } catch (IOException e) {
        throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD);
    }

    progressListener.complete();

    return targetStore;

}

From source file:brooklyn.entity.group.DynamicMultiGroupImpl.java

@Override
public void distributeEntities() {
    synchronized (memberChangeMutex) {
        Function<Entity, String> bucketFunction = getConfig(BUCKET_FUNCTION);
        EntitySpec<? extends BasicGroup> bucketSpec = getConfig(BUCKET_SPEC);
        if (bucketFunction == null || bucketSpec == null)
            return;
        Map<String, BasicGroup> buckets = MutableMap.copyOf(getAttribute(BUCKETS));

        // Bucketize the members where the function gives a non-null bucket
        Multimap<String, Entity> entityMapping = Multimaps.index(
                Iterables.filter(getMembers(), Predicates.compose(Predicates.notNull(), bucketFunction)),
                bucketFunction);/*from w  w  w  .jav  a  2 s  .c o m*/

        // Now fill the buckets
        for (String name : entityMapping.keySet()) {
            BasicGroup bucket = buckets.get(name);
            if (bucket == null) {
                bucket = addChild(EntitySpec.create(bucketSpec).displayName(name));
                Entities.manage(bucket);
                buckets.put(name, bucket);
            }
            bucket.setMembers(entityMapping.get(name));
        }

        // Remove any now-empty buckets
        Set<String> empty = ImmutableSet.copyOf(Sets.difference(buckets.keySet(), entityMapping.keySet()));
        for (String name : empty) {
            Group removed = buckets.remove(name);
            removeChild(removed);
            Entities.unmanage(removed);
        }

        // Save the bucket mappings
        setAttribute(BUCKETS, ImmutableMap.copyOf(buckets));
    }
}

From source file:net.shibboleth.idp.authn.impl.RemoteUserAuthServlet.java

/**
 * Set the list of request headers to check for an identity.
 * /* w  w w.ja va2  s  . c  o  m*/
 * @param headers list of request headers to check
 */
public void setCheckHeaders(@Nonnull @NonnullElements final Collection<String> headers) {
    checkHeaders = new ArrayList<>(Collections2.filter(headers, Predicates.notNull()));
}

From source file:org.apache.brooklyn.entity.group.DynamicMultiGroupImpl.java

@Override
public void distributeEntities() {
    synchronized (memberChangeMutex) {
        Function<Entity, String> bucketFunction = getConfig(BUCKET_FUNCTION);
        EntitySpec<? extends BasicGroup> bucketSpec = getConfig(BUCKET_SPEC);
        if (bucketFunction == null || bucketSpec == null)
            return;
        Map<String, BasicGroup> buckets = MutableMap.copyOf(getAttribute(BUCKETS));

        // Bucketize the members where the function gives a non-null bucket
        Multimap<String, Entity> entityMapping = Multimaps.index(
                Iterables.filter(getMembers(), Predicates.compose(Predicates.notNull(), bucketFunction)),
                bucketFunction);// www  .  jav a2  s .  c om

        // Now fill the buckets
        for (String name : entityMapping.keySet()) {
            BasicGroup bucket = buckets.get(name);
            if (bucket == null) {
                bucket = addChild(EntitySpec.create(bucketSpec).displayName(name));
                buckets.put(name, bucket);
            }
            bucket.setMembers(entityMapping.get(name));
        }

        // Remove any now-empty buckets
        Set<String> empty = ImmutableSet.copyOf(Sets.difference(buckets.keySet(), entityMapping.keySet()));
        for (String name : empty) {
            Group removed = buckets.remove(name);
            removeChild(removed);
            Entities.unmanage(removed);
        }

        // Save the bucket mappings
        sensors().set(BUCKETS, ImmutableMap.copyOf(buckets));
    }
}

From source file:org.apache.brooklyn.policy.loadbalancing.MockContainerEntityImpl.java

public static void runWithLock(List<MockContainerEntity> entitiesToLock, Runnable r) {
    List<MockContainerEntity> entitiesToLockCopy = MutableList
            .copyOf(Iterables.filter(entitiesToLock, Predicates.notNull()));
    List<MockContainerEntity> entitiesLocked = Lists.newArrayList();
    Collections.sort(entitiesToLockCopy, new Comparator<MockContainerEntity>() {
        public int compare(MockContainerEntity o1, MockContainerEntity o2) {
            return o1.getId().compareTo(o2.getId());
        }/*  w  w w.  jav  a2 s  .c o  m*/
    });

    try {
        for (MockContainerEntity it : entitiesToLockCopy) {
            it.lock();
            entitiesLocked.add(it);
        }

        r.run();

    } finally {
        for (MockContainerEntity it : entitiesLocked) {
            it.unlock();
        }
    }
}