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.codice.ddf.parser.xml.XmlParserConfigurator.java

@Override
public ParserConfigurator addProperties(Map<String, Object> properties) {
    this.properties.putAll(Maps.filterKeys(properties, Predicates.notNull()));
    return this;
}

From source file:org.pentaho.di.trans.dataservice.optimization.cache.ResetCacheServlet.java

@Override
public void handleRequest(CarteRequest request) throws IOException {
    Collection<String> names = request.getParameters().get(NAME_PARAMETER);
    if (names == null || names.isEmpty()) {
        request.respond(400).withMessage(NAME_PARAMETER + " not specified");
        return;//from  ww  w .  java 2 s . co  m
    }

    final Set<Cache> cacheSet = FluentIterable.from(names).transform(new Function<String, Cache>() {
        @Override
        public Cache apply(String name) {
            return factory.getCache(name).orNull();
        }
    }).filter(Predicates.notNull()).toSet();

    for (Cache cache : cacheSet) {
        cache.clear();
    }

    request.respond(200).with(MediaType.PLAIN_TEXT_UTF_8.toString(), new WriterResponse() {
        @Override
        public void write(PrintWriter writer) throws IOException {
            if (cacheSet.isEmpty()) {
                writer.println("No matching caches to flush.");
            }
            for (Cache cache : cacheSet) {
                writer.println("Cleared cache: " + cache.getName());
            }
            writer.println("Done");
        }
    });
}

From source file:org.mayocat.shop.catalog.front.context.PagesWebDataSupplier.java

@Override
public void supply(Map<String, Object> data) {
    if (context.getTenant() == null) {
        return;//w w  w . j  a v a2s . c om
    }

    ThemeDefinition theme = context.getTheme().getDefinition();

    // Pages
    List<Page> rootPages = this.pageStore.get().findAllRootPages();

    java.util.Collection<UUID> featuredImageIds = Collections2.transform(rootPages,
            WebDataHelper.ENTITY_FEATURED_IMAGE);
    List<UUID> ids = new ArrayList<>(Collections2.filter(featuredImageIds, Predicates.notNull()));
    List<Attachment> allImages;
    List<Thumbnail> allThumbnails;
    if (ids.isEmpty()) {
        allImages = Collections.emptyList();
        allThumbnails = Collections.emptyList();
    } else {
        allImages = this.attachmentStore.get().findByIds(ids);
        allThumbnails = this.thumbnailStore.get().findAllForIds(ids);
    }

    List<PageWebObject> pageWebObjectList = new ArrayList<>();

    for (final Page page : rootPages) {
        PageWebObject pageWebObject = new PageWebObject();
        pageWebObject.withPage(entityLocalizationService.localize(page), urlFactory, themeFileResolver);
        java.util.Collection<Attachment> attachments = Collections2.filter(allImages,
                WebDataHelper.isEntityFeaturedImage(page));
        List<Image> images = new ArrayList<>();
        for (final Attachment attachment : attachments) {
            java.util.Collection<Thumbnail> thumbnails = Collections2.filter(allThumbnails,
                    WebDataHelper.isThumbnailOfAttachment(attachment));
            Image image = new Image(attachment, new ArrayList<>(thumbnails));
            images.add(image);
        }
        pageWebObject.withImages(images, page.getFeaturedImageId(),
                Optional.fromNullable(context.getTheme() != null ? context.getTheme().getDefinition() : null));

        pageWebObjectList.add(pageWebObject);
    }
    data.put("pages", pageWebObjectList);
}

From source file:org.opensaml.security.trust.impl.ChainingTrustEngine.java

/** 
 * Constructor.//from  w ww.  jav a2  s  .  co  m
 * 
 * @param chain the list of trust engines in the chain
 */
public ChainingTrustEngine(@Nonnull final List<TrustEngine<? super TokenType>> chain) {
    Constraint.isNotNull(chain, "TrustEngine list cannot be null");
    engines = new ArrayList<>(Collections2.filter(chain, Predicates.notNull()));
}

From source file:org.jetbrains.kotlin.idea.caches.JetGotoSymbolContributor.java

@NotNull
@Override//from   w ww  . ja v a  2  s . c o m
public NavigationItem[] getItemsByName(String name, String pattern, Project project,
        boolean includeNonProjectItems) {
    GlobalSearchScope baseScope = includeNonProjectItems ? GlobalSearchScope.allScope(project)
            : GlobalSearchScope.projectScope(project);
    GlobalSearchScope noLibrarySourceScope = JetSourceFilterScope.kotlinSourceAndClassFiles(baseScope, project);

    Collection<? extends NavigationItem> functions = JetFunctionShortNameIndex.getInstance().get(name, project,
            noLibrarySourceScope);
    Collection<? extends NavigationItem> properties = JetPropertyShortNameIndex.getInstance().get(name, project,
            noLibrarySourceScope);

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

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

From source file:net.shibboleth.idp.saml.nameid.NameIDCanonicalizationFlowDescriptor.java

/**
 * Sets the acceptable formats.//  w  w w. ja v  a 2  s. c  o m
 * 
 * @param theFormats The formats to set.
 */
public void setFormats(@Nonnull Collection<String> theFormats) {
    Constraint.isNotNull(theFormats, "Format list must be non null");
    Constraint.isNotEmpty(theFormats, "Format list must be non empty");
    final Set<String> newFormats = new HashSet(theFormats.size());
    CollectionSupport.addIf(newFormats, theFormats, Predicates.notNull());

    formats = ImmutableSet.copyOf(newFormats);
}

From source file:org.robotframework.ide.eclipse.main.plugin.project.editor.libraries.PathEntryDialog.java

@Override
protected void okPressed() {
    searchPath = newArrayList(filter(/*from  w  w  w.  j  a  va 2s  . c  om*/
            transform(Splitter.on('\n').splitToList(pathText.getText()), new Function<String, SearchPath>() {

                @Override
                public SearchPath apply(final String singlePath) {
                    final String trimmedPath = singlePath.trim().replaceAll("\t", " ");
                    return trimmedPath.isEmpty() ? null : SearchPath.create(trimmedPath);
                }
            }), Predicates.notNull()));
    super.okPressed();
}

From source file:org.incode.eurocommercial.contactapp.fixture.scenarios.demo.DemoFixture.java

@Override
protected void execute(final ExecutionContext ec) {

    // zap everything
    ec.executeChild(this, new ContactRoleTearDown());
    ec.executeChild(this, new ContactNumberTearDown());
    ec.executeChild(this, new ContactTearDown());
    ec.executeChild(this, new ContactGroupTearDown());
    ec.executeChild(this, new CountryTearDown());

    // load data from spreadsheet
    final URL spreadsheet = Resources.getResource(DemoFixture.class, getSpreadsheetBasename() + ".xlsx");
    final ExcelFixture fs = new ExcelFixture(spreadsheet, getHandlers());
    ec.executeChild(this, fs);

    // make objects created by ExcelFixture available to our caller.
    final Map<Class, List<Object>> objectsByClass = fs.getObjectsByClass();

    getContacts().addAll(FluentIterable.from((List) objectsByClass.get(ContactImport.class))
            .filter(Predicates.notNull()).toList());

}

From source file:io.druid.java.util.common.guava.FunctionalIterator.java

public <RetType> FunctionalIterator<RetType> keep(Function<T, RetType> fn) {
    return new FunctionalIterator<>(Iterators.filter(Iterators.transform(delegate, fn), Predicates.notNull()));
}

From source file:org.summer.dsl.builder.impl.javasupport.ProjectClasspathChangeListener.java

public void elementChanged(ElementChangedEvent event) {
    if (workspace != null && workspace.isAutoBuilding()) {
        try {/*from   w w  w .j a  v a 2s . c o m*/
            if (event.getDelta() != null) {
                Set<IJavaProject> javaProjects = getJavaProjectsWithClasspathChange(event.getDelta());
                if (!javaProjects.isEmpty()) {
                    Set<IProject> projects = Sets.newHashSet(Iterables
                            .filter(Iterables.transform(javaProjects, new Function<IJavaProject, IProject>() {
                                public IProject apply(IJavaProject from) {
                                    return from.getProject();
                                }
                            }), Predicates.notNull()));
                    dirtyStateManager.notifyListeners(new CoarseGrainedChangeEvent());
                    buildManager.scheduleBuildIfNecessary(projects);
                }
            }
        } catch (WrappedException e) {
            log.error(e.getCause().getMessage(), e.getCause());
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
        }
    }
}