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:de.metas.ui.web.pickingV2.packageable.PackageableRowsRepository.java

private ITranslatableString buildNetAmtTranslatableString(final Collection<Packageable> packageables) {
    return packageables.stream().map(Packageable::getSalesOrderLineNetAmt).filter(Predicates.notNull())
            .collect(Money.sumByCurrencyAndStream()).map(moneyService::toTranslatableString)
            .collect(ITranslatableString.joining(", "));
}

From source file:org.jclouds.openstack.nova.v1_1.domain.Image.java

public Map<String, String> getMetadata() {
    // in case this was assigned in gson
    return ImmutableMap.copyOf(Maps.filterValues(this.metadata, Predicates.notNull()));
}

From source file:org.apache.jackrabbit.oak.security.user.UserPrincipalProvider.java

@Nonnull
@Override//  w  w w  .j ava2 s.  c o m
public Iterator<? extends Principal> findPrincipals(final String nameHint, final int searchType) {
    try {
        AuthorizableType type = AuthorizableType.getType(searchType);
        StringBuilder statement = new StringBuilder()
                .append(QueryUtil.getSearchRoot(type, config.getParameters())).append("//element(*,")
                .append(QueryUtil.getNodeTypeName(type)).append(')').append("[jcr:like(@rep:principalName,'")
                .append(buildSearchPattern(nameHint)).append("')]");

        Result result = root.getQueryEngine().executeQuery(statement.toString(), javax.jcr.query.Query.XPATH,
                NO_BINDINGS, namePathMapper.getSessionLocalMappings());

        Iterator<Principal> principals = Iterators.filter(
                Iterators.transform(result.getRows().iterator(), new ResultRowToPrincipal()),
                Predicates.notNull());

        if (matchesEveryone(nameHint, searchType)) {
            principals = Iterators.concat(principals,
                    Iterators.singletonIterator(EveryonePrincipal.getInstance()));
            return Iterators.filter(principals, new EveryonePredicate());
        } else {
            return principals;
        }
    } catch (ParseException e) {
        log.debug(e.getMessage());
        return Iterators.emptyIterator();
    }
}

From source file:ru.crazyproger.plugins.webtoper.nls.codeinsight.NlsLineMarkerProvider.java

private void fillLineMarkers(MarkerInfo info) {
    Collection<PsiElement> targets = transform(info.getNavigationTargets(), new Property2PsiElementFunction());
    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(info.getIcon());
    targets = filter(targets, Predicates.notNull());
    builder.setTargets(targets);/*  w w  w  .  j a  v a 2s.  c  o  m*/
    String tooltipText;
    if (targets.size() > 1) { // todo #WT-39
        tooltipText = message(info.getMultiBundleKey());
    } else {
        PsiFile psiFile = targets.iterator().next().getContainingFile();
        assert psiFile instanceof NlsFileImpl;
        tooltipText = message(info.getOneBundleKey(), ((NlsFileImpl) psiFile).getNlsName());
    }
    builder.setTooltipText(tooltipText);
    builder.setPopupTitle(message(info.getToolTipKey()));
    info.getResult().add(builder.createLineMarkerInfo(info.getTarget()));
}

From source file:com.spectralogic.ds3cli.command.GetDetailedObjects.java

private Predicate<DetailedS3Object> getOwnerPredicate() {
    if (Guard.isMapNullOrEmpty(this.filterParams)) {
        return Predicates.notNull();
    }//from  w w w . ja v a 2  s  .c  o m
    final String owner = paramLookup(OWNER);
    if (Guard.isStringNullOrEmpty(owner)) {
        return Predicates.notNull();
    }
    return new Predicate<DetailedS3Object>() {
        @Override
        public boolean apply(@Nullable final DetailedS3Object input) {
            return input.getOwner().equals(owner);
        }
    };
}

From source file:org.apache.brooklyn.location.jclouds.AbstractComputeServiceRegistry.java

protected Iterable<? extends Module> linkingContext(ConfigBag conf) {
    if (!conf.containsKey(JcloudsLocationConfig.LINK_CONTEXT))
        return Collections.EMPTY_SET;
    Context context = new LinkContextSupplier(conf).get();
    return Iterables.filter(ImmutableSet.of(ContextLinking.linkContext(context)), Predicates.notNull());
}

From source file:org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal.ExternalGroupPrincipalProvider.java

@Nonnull
@Override// w w  w.  jav a2s .  co  m
public Iterator<? extends Principal> findPrincipals(@Nullable String nameHint, int searchType) {
    if (PrincipalManager.SEARCH_TYPE_NOT_GROUP != searchType) {
        Result result = findPrincipals(Strings.nullToEmpty(nameHint), false);
        if (result != null) {
            return Iterators.filter(new GroupPrincipalIterator(nameHint, result), Predicates.notNull());
        }
    }

    return Iterators.emptyIterator();
}

From source file:org.eclipse.buildship.core.preferences.internal.PersistentModelConverter.java

private static <T> void storeList(Properties properties, String key, Collection<T> values,
        Function<T, String> conversion) {
    List<String> stringList = FluentIterable.from(values).transform(conversion).filter(Predicates.notNull())
            .toList();/*from  w  w  w.ja  v a2s .c om*/
    properties.put(key, Joiner.on(File.pathSeparator).join(stringList));
}

From source file:de.metas.ui.web.handlingunits.process.WEBUI_Add_Batch_SerialNo_To_CUs.java

/** @return true if view was changed and needs invalidation */
private final boolean removeSelectedRowsIfHUDestoyed() {
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (selectedRowIds.isEmpty()) {
        return false;
    } else if (selectedRowIds.isAll()) {
        return false;
    }/*from w w w  .j av  a 2 s  . c  o  m*/

    final HUEditorView view = getView();
    final ImmutableSet<HuId> selectedHUIds = view.streamByIds(selectedRowIds).map(HUEditorRow::getHuId)
            .filter(Predicates.notNull()).collect(ImmutableSet.toImmutableSet());

    return removeHUsIfDestroyed(selectedHUIds);
}

From source file:org.polarsys.reqcycle.styling.ui.dialogs.CaseStyleEditorDialog.java

/**
 * Create contents of the dialog.//  w  w w.ja  v a 2 s  . c o m
 * 
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    setTitle("Styling configuration");

    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    Label lblName = new Label(container, SWT.NONE);
    lblName.setText("Name :");

    text = new Text(container, SWT.BORDER);
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    text.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            validateInput();
        }
    });

    Group composite = new Group(container, SWT.NONE);
    composite.setText("Style predicates");
    composite.setToolTipText("");
    composite.setLayout(new GridLayout(2, false));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    listViewer = new ListViewer(composite, SWT.BORDER | SWT.V_SCROLL);
    listViewer.setUseHashlookup(true);
    List list = listViewer.getList();
    list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    listViewer.addDoubleClickListener(this);

    Composite composite_1 = new Composite(composite, SWT.NONE);
    composite_1.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1));
    composite_1.setLayout(new GridLayout(1, false));

    Button btnAdd = new Button(composite_1, SWT.NONE);
    btnAdd.setToolTipText("Add new styling predicate");
    btnAdd.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            final Collection<IPredicate> predicates = predicatesConfManager.getPredicates(true);

            final Iterable<IPredicate> alreadyUsed = Iterables.filter(
                    Iterables.transform(stylingModel.getStyles(), new Function<CaseStyle, IPredicate>() {

                        @Override
                        public IPredicate apply(CaseStyle arg0) {
                            if (arg0 instanceof StylingPredicate) {
                                StylingPredicate sp = (StylingPredicate) arg0;
                                return sp.getPredicate();
                            }
                            return null;
                        }

                    }), Predicates.notNull());
            Collection<IPredicate> selectionPredicates = Lists
                    .newArrayList(Iterables.filter(predicates, new Predicate<IPredicate>() {
                        public boolean apply(IPredicate arg0) {
                            for (IPredicate p : alreadyUsed) {
                                if (p.getDisplayName().equals(arg0.getDisplayName())) {
                                    return false;
                                }
                            }
                            return true;
                        };
                    }));

            Collection<IPredicate> selection = PredicatesUIHelper.openPredicatesChooser(selectionPredicates,
                    selectionPredicates, "Creating Styling Model", "Select a predicate to apply.", false);
            if (selection != null) {
                EList<CaseStyle> casesStyle = stylingModel.getStyles();
                CaseStyle newStyle = StylingFactory.eINSTANCE.createStylingPredicate();
                casesStyle.add(newStyle);

                IPredicate p = selection.iterator().next();
                ((StylingPredicate) newStyle).setPredicate(p);

                listViewer.setInput(stylingModel.getStyles());
                listViewer.setSelection(new StructuredSelection(newStyle));
            }
        }
    });
    btnAdd.setImage(ResourceManager.getPluginImage("org.polarsys.reqcycle.styling.ui", "icons/add_obj.gif"));

    Button btnRemove = new Button(composite_1, SWT.NONE);
    btnRemove.setToolTipText("Remove the selected styling predicate");
    btnRemove.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!listViewer.getSelection().isEmpty()) {
                IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection();
                CaseStyle caseStyle = (CaseStyle) selection.getFirstElement();
                if (caseStyle != null) {
                    EList<CaseStyle> casesStyle = stylingModel.getStyles();
                    casesStyle.remove(caseStyle);

                    listViewer.setInput(stylingModel.getStyles());
                }

            }
        }
    });
    btnRemove.setImage(
            ResourceManager.getPluginImage("org.polarsys.reqcycle.styling.ui", "icons/delete_obj.gif"));

    Button btnEdit = new Button(composite_1, SWT.NONE);
    btnEdit.setToolTipText("Edit the selected styling predicate");
    btnEdit.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!listViewer.getSelection().isEmpty()) {
                IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection();
                CaseStyle caseStyle = (CaseStyle) selection.getFirstElement();
                if (caseStyle != null) {
                    editStylePredicate(caseStyle);
                }
            }
        }
    });
    btnEdit.setImage(ResourceManager.getPluginImage("org.polarsys.reqcycle.styling.ui", "icons/edit_obj.png"));
    new Label(composite_1, SWT.NONE);

    Button btnUp = new Button(composite_1, SWT.NONE);
    btnUp.setToolTipText("Move up the selected styling predicate");
    btnUp.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!listViewer.getSelection().isEmpty()) {
                IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection();
                CaseStyle caseStyle = (CaseStyle) selection.getFirstElement();
                if (caseStyle != null) {
                    EList<CaseStyle> list = stylingModel.getStyles();
                    int pos = list.indexOf(caseStyle);
                    if (pos > 0) {
                        list.move(pos, pos - 1);

                        listViewer.setInput(stylingModel.getStyles());
                        listViewer.setSelection(selection);
                    }
                }
            }
        }
    });
    btnUp.setImage(ResourceManager.getPluginImage("org.polarsys.reqcycle.styling.ui", "icons/prev_nav-1.gif"));

    Button btnDown = new Button(composite_1, SWT.NONE);
    btnDown.setToolTipText("Move down the selected styling predicate");
    btnDown.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!listViewer.getSelection().isEmpty()) {
                IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection();
                CaseStyle caseStyle = (CaseStyle) selection.getFirstElement();
                if (caseStyle != null) {
                    EList<CaseStyle> list = stylingModel.getStyles();
                    int pos = list.indexOf(caseStyle);
                    if ((pos != -1) && (pos != list.size() - 1)) {
                        list.move(pos, pos + 1);

                        listViewer.setInput(stylingModel.getStyles());
                        listViewer.setSelection(selection);
                    }
                }
            }
        }
    });
    btnDown.setImage(
            ResourceManager.getPluginImage("org.polarsys.reqcycle.styling.ui", "icons/next_nav-1.gif"));

    initDataBindings();

    initProviders(listViewer);

    Label lblDefaultPredicate = new Label(container, SWT.NONE);
    lblDefaultPredicate.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblDefaultPredicate.setText("Default :");

    Button btnEdit_1 = new Button(container, SWT.NONE);
    btnEdit_1.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            StyleModelEditorDialog editor = new StyleModelEditorDialog(Display.getDefault().getActiveShell(),
                    stylingModel.getDefault(), stylingModel);
            if (editor.open() == Window.OK) {
                listViewer.setInput(stylingModel.getStyles());
            }
        }
    });
    btnEdit_1.setText("Edit");

    Label label = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));

    Label lblNewLabel = new Label(container, SWT.NONE);
    lblNewLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    lblNewLabel.setText(
            "Basic styling is the style used to display requirements in ReqCycle views (except Requirements view).");

    Label lblBasic = new Label(container, SWT.NONE);
    lblBasic.setText("Basic :");

    Button btnEdit_2 = new Button(container, SWT.NONE);
    btnEdit_2.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            StyleModelEditorDialog editor = new StyleModelEditorDialog(Display.getDefault().getActiveShell(),
                    stylingModel.getBasic(), stylingModel);
            if (editor.open() == Window.OK) {
                listViewer.setInput(stylingModel.getStyles());
            }
        }
    });
    btnEdit_2.setText("Edit");

    return area;
}