List of usage examples for com.google.common.base Predicates notNull
@GwtCompatible(serializable = true) public static <T> Predicate<T> notNull()
From source file:hudson.util.Iterators.java
/** * Wraps another iterator and throws away nulls. *//*from w w w . j a va 2 s. c o m*/ public static <T> Iterator<T> removeNull(final Iterator<T> itr) { return com.google.common.collect.Iterators.filter(itr, Predicates.notNull()); }
From source file:com.eucalyptus.util.Exceptions.java
/** * Get the message closest to the cause. * * @param throwable The exception//from ww w .j a v a 2 s. co m * @return The message or null if none */ public static String getCauseMessage(final Throwable throwable) { return FluentIterable.from(Lists.reverse(causes(throwable))).transform(message()) .firstMatch(Predicates.notNull()).orNull(); }
From source file:com.tinspx.util.net.FormEncodedBody.java
/** * Returns a modifiable view of the headers. Any header (except * {@code Content-Length}) may be added, including overwriting the * {@code Content-Type} (which defaults to * {@code application/x-www-form-urlencoded}). *//* w ww . j a v a 2s . c o m*/ @Override public ListMultimap<String, String> headers() { if (headers == null) { headers = LinkedListMultimap.create(); headers.put(HttpHeaders.CONTENT_TYPE, X_WWW_FORM_URLENCODED); } if (headersView == null) { headersView = Predicated.listMultimap(headers, Requests.HKEY_NO_LEN, Predicates.notNull()); } return headersView; }
From source file:io.hops.transaction.context.BaseEntityContext.java
final Collection<Entity> get(Predicate<ContextEntity> pred) { Map<Key, ContextEntity> filtered = Maps.filterValues(contextEntities, pred); Collection<Entity> transformed = Maps.transformValues(filtered, new Function<ContextEntity, Entity>() { @Override//from ww w . j a va2 s . co m public Entity apply(ContextEntity input) { return input.getEntity(); } }).values(); return Collections2.filter(transformed, Predicates.notNull()); }
From source file:org.geogit.geotools.plumbing.ExportOp.java
private static Iterator<SimpleFeature> getFeatures(final RevTree typeTree, final ObjectDatabase database, final ObjectId defaultMetadataId, final ProgressListener progressListener) { Iterator<NodeRef> nodes = new DepthTreeIterator("", defaultMetadataId, typeTree, database, Strategy.FEATURES_ONLY);//from w w w . j a v a 2 s . co m // progress reporting nodes = Iterators.transform(nodes, new Function<NodeRef, NodeRef>() { private AtomicInteger count = new AtomicInteger(); @Override public NodeRef apply(NodeRef input) { progressListener.progress((count.incrementAndGet() * 100.f) / typeTree.size()); return input; } }); Function<NodeRef, SimpleFeature> asFeature = new Function<NodeRef, SimpleFeature>() { private Map<ObjectId, FeatureBuilder> ftCache = Maps.newHashMap(); @Override @Nullable public SimpleFeature apply(final NodeRef input) { final ObjectId metadataId = input.getMetadataId(); final RevFeature revFeature = database.getFeature(input.objectId()); FeatureBuilder featureBuilder = getBuilderFor(metadataId); Feature feature = featureBuilder.build(input.name(), revFeature); feature.getUserData().put(Hints.USE_PROVIDED_FID, true); feature.getUserData().put(RevFeature.class, revFeature); feature.getUserData().put(RevFeatureType.class, featureBuilder.getType()); if (feature instanceof SimpleFeature) { return (SimpleFeature) feature; } return null; } private FeatureBuilder getBuilderFor(final ObjectId metadataId) { FeatureBuilder featureBuilder = ftCache.get(metadataId); if (featureBuilder == null) { RevFeatureType revFtype = database.getFeatureType(metadataId); featureBuilder = new FeatureBuilder(revFtype); ftCache.put(metadataId, featureBuilder); } return featureBuilder; } }; Iterator<SimpleFeature> asFeatures = Iterators.transform(nodes, asFeature); UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull()); return filterNulls; }
From source file:org.eclipse.sirius.common.acceleo.mtl.ide.AcceleoCompletionService.java
private List<URI> getDeclaredImports() { List<URI> accessibleOutputFiles = Lists.newArrayList(); if (dependencies != null) { Iterables.addAll(accessibleOutputFiles, Iterables.filter(dependencies, Predicates.notNull())); }/*w w w. ja v a2 s. c om*/ return accessibleOutputFiles; }
From source file:de.metas.ui.web.pickingV2.productsToPick.ProductsToPickRowsDataFactory.java
private List<ProductsToPickRow> createRowsFromHUs(final AllocablePackageable packageable) { if (packageable.isAllocated()) { return ImmutableList.of(); }/* w ww . ja v a 2 s . com*/ final Set<HuId> huIds = getHuIdsAvailableToAllocate(packageable); final List<ProductsToPickRow> rows = huIds.stream().map(huId -> createZeroQtyRowFromHU(packageable, huId)) .collect(ImmutableList.toImmutableList()); return rows.stream() .sorted(Comparator.comparing(row -> Util.coalesce(row.getExpiringDate(), LocalDate.MAX))) .map(row -> allocateRowFromHU(row, packageable)).filter(Predicates.notNull()) .collect(ImmutableList.toImmutableList()); }
From source file:com.eucalyptus.tags.TagManager.java
public DeleteTagsResponseType deleteTags(final DeleteTagsType request) throws EucalyptusCloudException { final DeleteTagsResponseType reply = request.getReply(); reply.set_return(false); final Context context = Contexts.lookup(); final OwnerFullName ownerFullName = context.getUserFullName().asAccountFullName(); final List<String> resourceIds = Objects.firstNonNull(request.getResourcesSet(), Collections.<String>emptyList()); final List<DeleteResourceTag> resourceTags = Objects.firstNonNull(request.getTagSet(), Collections.<DeleteResourceTag>emptyList()); for (final DeleteResourceTag resourceTag : resourceTags) { final String key = resourceTag.getKey(); if (Strings.isNullOrEmpty(key) || key.trim().length() > 128 || isReserved(key)) { throw new InvalidParameterValueException( "Invalid key (max length 128, must not be empty, reserved prefixes " + reservedPrefixes + "): " + key); }//from w ww . ja va 2s . c om } if (resourceIds.size() > 0 && resourceIds.size() > 0) { final Predicate<Void> delete = new Predicate<Void>() { @Override public boolean apply(final Void v) { final Iterable<CloudMetadata> resources = Iterables .filter(Iterables.transform(resourceIds, resourceLookup(false)), Predicates.notNull()); for (final CloudMetadata resource : resources) { for (final DeleteResourceTag resourceTag : resourceTags) { try { final Tag example = TagSupport.fromResource(resource).example(resource, ownerFullName, resourceTag.getKey(), resourceTag.getValue()); if (RestrictedTypes.filterPrivileged().apply(example)) { Tags.delete(example); } } catch (NoSuchMetadataException e) { log.trace(e); } } } return true; } }; try { reply.set_return(Entities.asTransaction(Tag.class, delete).apply(null)); } catch (RuntimeException e) { handleException(e); } } return reply; }
From source file:org.jpmml.evaluator.ModelEvaluationExample.java
static private Sets.SetView<FieldName> difference(List<FieldName> requiredFields, List<FieldName> fields) { Predicate<FieldName> notNull = Predicates.notNull(); return Sets.difference(Sets.newHashSet(Iterables.filter(requiredFields, notNull)), Sets.newHashSet(Iterables.filter(fields, notNull))); }
From source file:io.hops.transaction.context.BaseEntityContext.java
final Collection<Entity> getAll() { Collection<Entity> tr = Collections2.transform(contextEntities.values(), new Function<ContextEntity, Entity>() { @Override// w w w. ja va2 s . c o m public Entity apply(ContextEntity input) { return input.getEntity(); } }); return Collections2.filter(tr, Predicates.notNull()); }