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.xmlsec.impl.WhitelistBlacklistConfigurationCriterion.java

/**
 * Constructor.//from  www  .j av  a  2 s. c om
 *
 * @param configurations list of configuration instances
 */
public WhitelistBlacklistConfigurationCriterion(
        @Nonnull @NonnullElements @NotEmpty List<WhitelistBlacklistConfiguration> configurations) {
    Constraint.isNotNull(configurations, "List of configurations may not be null");
    configs = new ArrayList<>(Collections2.filter(configurations, Predicates.notNull()));
    Constraint.isGreaterThanOrEqual(1, configs.size(), "At least one configuration is required");

}

From source file:org.jetbrains.jet.plugin.caches.JetGotoSymbolContributor.java

@NotNull
@Override//from   ww w. j ava2 s  .co  m
public NavigationItem[] getItemsByName(String name, String pattern, Project project,
        boolean includeNonProjectItems) {
    GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project)
            : GlobalSearchScope.projectScope(project);

    Collection<? extends NavigationItem> functions = StubIndex.getInstance()
            .get(JetIndexKeys.FUNCTIONS_SHORT_NAME_KEY, name, project, scope);

    Collection<? extends NavigationItem> properties = StubIndex.getInstance()
            .get(JetIndexKeys.PROPERTIES_SHORT_NAME_KEY, name, project, scope);

    final List<NavigationItem> items = new ArrayList<NavigationItem>(
            Collections2.filter(functions, Predicates.notNull()));
    items.addAll(properties);

    return ArrayUtil.toObjectArray(items, NavigationItem.class);
}

From source file:eu.lp0.cursus.scoring.scores.impl.GenericRaceDiscardsData.java

@Override
protected List<Race> calculateDiscardedRaces(Pilot pilot) {
    if (discards > 0) {
        final Map<Race, Integer> racePoints = scores.getRacePoints(pilot);

        // Discard the highest scoring races
        return Lists.newArrayList(Iterables.limit(Ordering.from(new Comparator<Race>() {
            @Override//  w  w w.  j a v a  2s.c o m
            public int compare(Race o1, Race o2) {
                return ComparisonChain.start().compare(racePoints.get(o2), racePoints.get(o1)).compare(o1, o2)
                        .result();
            }
            // Use all races where the score is not null
        }).immutableSortedCopy(Maps.filterValues(racePoints, Predicates.notNull()).keySet()), discards));
    }

    return Collections.emptyList();
}

From source file:org.mayocat.attachment.AttachmentDataLoader.java

public <E extends Entity> void loadList(List<EntityData<E>> entities, LoadingOption... options) {
    List<LoadingOption> optionsAsList = Arrays.asList(options);

    List<Attachment> attachments;

    if (optionsAsList.contains(AttachmentLoadingOptions.FEATURED_IMAGE_ONLY)) {

        // Featured image only : we ignore all other attachments

        List<UUID> imageIds = FluentIterable.from(entities).transform(new Function<EntityData<E>, UUID>() {
            public UUID apply(EntityData<E> input) {
                if (!HasFeaturedImage.class.isAssignableFrom(input.getEntity().getClass())) {
                    throw new RuntimeException(
                            "Failed to load attachment list with featured image only option : entity does not implement HasFeaturedImage");
                }// ww w  .jav a  2  s  .c  o m
                return ((HasFeaturedImage) input.getEntity()).getFeaturedImageId();
            }
        }).filter(Predicates.notNull()).toList();

        attachments = imageIds.size() > 0 ? this.attachmentStore.findByIds(imageIds)
                : Collections.<Attachment>emptyList();
    } else {

        // All attachments for the list

        List<UUID> ids = FluentIterable.from(entities).transform(new Function<EntityData<E>, UUID>() {
            public UUID apply(EntityData<E> input) {
                return input.getEntity().getId();
            }
        }).toList();

        attachments = ids.size() > 0 ? this.attachmentStore.findAllChildrenOfParentIds(ids)
                : Collections.<Attachment>emptyList();
    }

    for (final EntityData entity : entities) {
        List<Attachment> thisEntityAttachments = FluentIterable.from(attachments)
                .filter(new Predicate<Attachment>() {
                    public boolean apply(Attachment attachment) {
                        return entity.getEntity().getId().equals(attachment.getParentId());
                    }
                }).toList();
        entity.setChildren(Attachment.class, thisEntityAttachments);
    }
}

From source file:net.shibboleth.idp.attribute.filter.matcher.logic.impl.AbstractComposedMatcher.java

/**
 * Constructor.//  ww w  .jav a2  s  .c om
 * 
 * @param composedMatchers matchers being composed
 */
public AbstractComposedMatcher(@Nullable @NullableElements final Collection<Matcher> composedMatchers) {
    ArrayList<Matcher> checkedMatchers = new ArrayList<>();

    if (composedMatchers != null) {
        CollectionSupport.addIf(checkedMatchers, composedMatchers, Predicates.notNull());
    }

    matchers = ImmutableList.copyOf(Iterables.filter(checkedMatchers, Predicates.notNull()));
}

From source file:net.shibboleth.idp.attribute.filter.impl.matcher.logic.AbstractComposedMatcher.java

/**
 * Constructor./*from   w w w . j a va2  s . c  o m*/
 * 
 * @param composedMatchers matchers being composed
 */
public AbstractComposedMatcher(@Nullable @NullableElements final Collection<Matcher> composedMatchers) {
    ArrayList<Matcher> checkedMatchers = new ArrayList<Matcher>();

    if (composedMatchers != null) {
        CollectionSupport.addIf(checkedMatchers, composedMatchers, Predicates.notNull());
    }

    matchers = ImmutableList.copyOf(Iterables.filter(checkedMatchers, Predicates.notNull()));
}

From source file:com.mmounirou.spotirss.rss.ChartRss.java

@SuppressWarnings("unchecked")
public static ChartRss getInstance(String strUrl, final EntryToTrackConverter converter)
        throws MalformedURLException, ChartRssException {
    File rssCache = new File(FileUtils.getTempDirectory(), "billboard-charts");
    rssCache.mkdirs();/* w  w w .  ja va  2  s  .  co  m*/

    FeedFetcherCache feedFetcherCache = new DiskFeedInfoCache(rssCache.getAbsolutePath());
    FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedFetcherCache);

    URL feedUrl = new URL(strUrl);
    try {
        SyndFeed retrievedFeed = feedFetcher.retrieveFeed(feedUrl);
        String title = retrievedFeed.getTitle();
        ImmutableSortedSet<Track> songs = FluentIterable.from((List<SyndEntry>) retrievedFeed.getEntries())
                .transform(new Function<SyndEntry, Track>() {

                    @Override
                    @Nonnull
                    public Track apply(@Nonnull SyndEntry entry) {
                        try {
                            return converter.apply(entry.getTitle());
                        } catch (Exception e) {
                            SpotiRss.LOGGER.error(String.format("fail to parse %s ", entry.getTitle()));
                            return null;
                        }

                    }

                }).filter(Predicates.notNull()).toImmutableSortedSet(new Comparator<Track>() {

                    @Override
                    public int compare(Track o1, Track o2) {
                        return Integer.valueOf(o1.getRank()).compareTo(Integer.valueOf(o2.getRank()));
                    }
                });

        return new ChartRss(title, songs);
    } catch (IllegalArgumentException e) {
        throw new ChartRssException(e);
    } catch (IOException e) {
        throw new ChartRssException(e);

    } catch (FeedException e) {
        throw new ChartRssException(e);

    } catch (FetcherException e) {
        throw new ChartRssException(e);
    }

}

From source file:com.example.ModelWithAnonymousClass.java

private List<String> createFromPaths(List<String> paths) {
    return FluentIterable.from(paths).transform(new Function<String, String>() {
        @Override//from w ww  . jav  a  2  s .  c  om
        public String apply(String path) {
            return resourceResolver.getResource(path).getValueMap().get("property", String.class);
        }
    }).filter(Predicates.notNull()).toList();
}

From source file:org.eclipse.sirius.ui.tools.internal.actions.session.OpenRepresentationsAction.java

/**
 * Constructor.// ww w.  ja v a 2 s . c om
 *
 * @param representations
 *            representations to open.
 */
public OpenRepresentationsAction(Collection<DRepresentation> representations) {
    super(Messages.OpenRepresentationsAction_name);

    if (representations != null) {
        this.representationsToOpen = Sets
                .newLinkedHashSet(Iterables.filter(representations, Predicates.notNull()));
    }
}

From source file:org.eclipselabs.spray.xtext.scoping.AliasingScope.java

/**
 * Creates the aliasing scope.//w  w  w . j  a  va  2 s.  c  o  m
 * 
 * @param parent
 *            Parent scope
 * @param aliasingFunction
 *            A function that maps qualified names to their aliases
 */
public AliasingScope(IScope parent, final Function<QualifiedName, QualifiedName> aliasingFunction) {
    super(IScope.NULLSCOPE, false);
    final Function<IEObjectDescription, IEObjectDescription> toAliasedDescription = new Function<IEObjectDescription, IEObjectDescription>() {
        @Override
        public IEObjectDescription apply(IEObjectDescription input) {
            // the alias function might result into null, return null in this case. The nulls will be filtered afterwards
            final QualifiedName alias = aliasingFunction.apply(input.getQualifiedName());
            return alias != null ? new AliasedEObjectDescription(alias, input) : null;
        }
    };
    elements = Iterables.filter(Iterables.transform(parent.getAllElements(), toAliasedDescription),
            Predicates.notNull());
}