Example usage for com.google.common.base Strings emptyToNull

List of usage examples for com.google.common.base Strings emptyToNull

Introduction

In this page you can find the example usage for com.google.common.base Strings emptyToNull.

Prototype

@Nullable
public static String emptyToNull(@Nullable String string) 

Source Link

Document

Returns the given string if it is nonempty; null otherwise.

Usage

From source file:com.linecorp.armeria.server.grpc.ArmeriaServerCall.java

ArmeriaServerCall(HttpHeaders clientHeaders, MethodDescriptor<I, O> method,
        CompressorRegistry compressorRegistry, DecompressorRegistry decompressorRegistry,
        HttpResponseWriter res, int maxInboundMessageSizeBytes, int maxOutboundMessageSizeBytes,
        ServiceRequestContext ctx, SerializationFormat serializationFormat, MessageMarshaller jsonMarshaller) {
    requireNonNull(clientHeaders, "clientHeaders");
    this.method = requireNonNull(method, "method");
    this.ctx = requireNonNull(ctx, "ctx");
    this.serializationFormat = requireNonNull(serializationFormat, "serializationFormat");
    this.messageReader = new HttpStreamReader(requireNonNull(decompressorRegistry, "decompressorRegistry"),
            new ArmeriaMessageDeframer(this, maxInboundMessageSizeBytes, ctx.alloc())
                    .decompressor(clientDecompressor(clientHeaders, decompressorRegistry)),
            this);
    this.messageFramer = new ArmeriaMessageFramer(ctx.alloc(), maxOutboundMessageSizeBytes);
    this.res = requireNonNull(res, "res");
    this.compressorRegistry = requireNonNull(compressorRegistry, "compressorRegistry");
    this.clientAcceptEncoding = Strings.emptyToNull(clientHeaders.get(GrpcHeaderNames.GRPC_ACCEPT_ENCODING));
    this.decompressorRegistry = requireNonNull(decompressorRegistry, "decompressorRegistry");
    marshaller = new GrpcMessageMarshaller<>(ctx.alloc(), serializationFormat, method, jsonMarshaller);
}

From source file:com.eucalyptus.cloudformation.ws.CloudFormationCfnAuthenticationHandler.java

private static Cache<Tuple2<String, String>, Option<Tuple2<String, String>>> cache() {
    return MEMOIZED_CACHE_BUILDER.apply(
            MoreObjects.firstNonNull(Strings.emptyToNull(CloudFormationProperties.CFN_INSTANCE_AUTH_CACHE),
                    DEFAULT_INSTANCE_AUTH_CACHE_SPEC));
}

From source file:org.dcache.alarms.server.LogEntryServerWrapper.java

public void setPath(String path) {
    this.path = Strings.emptyToNull(path);
}

From source file:com.google.devtools.build.xcode.plmerge.PlistMerging.java

/**
 * Generates a Plistmerging combining values from sourceFiles and immutableSourceFiles, and
 * modifying them based on substitutions and keysToRemoveIfEmptyString.
 *///from   w  w w. j a  v a 2 s .c  o m
public static PlistMerging from(Control control, KeysToRemoveIfEmptyString keysToRemoveIfEmptyString)
        throws IOException {

    FileSystem fileSystem = FileSystems.getDefault();

    ImmutableList.Builder<Path> sourceFilePathsBuilder = new Builder<>();
    for (String pathString : control.getSourceFileList()) {
        sourceFilePathsBuilder.add(fileSystem.getPath(pathString));
    }
    ImmutableList.Builder<Path> immutableSourceFilePathsBuilder = new Builder<>();
    for (String pathString : control.getImmutableSourceFileList()) {
        immutableSourceFilePathsBuilder.add(fileSystem.getPath(pathString));
    }

    return from(sourceFilePathsBuilder.build(), immutableSourceFilePathsBuilder.build(),
            control.getVariableSubstitutionMap(), keysToRemoveIfEmptyString,
            Strings.emptyToNull(control.getExecutableName()));
}

From source file:com.google.gerrit.server.query.change.ListChanges.java

public void query(Writer out) throws OrmException, QueryParseException, IOException {
    if (imp.isDisabled()) {
        throw new QueryParseException("query disabled");
    }/*from  www. ja  va 2  s. co  m*/
    if (queries == null || queries.isEmpty()) {
        queries = Collections.singletonList("status:open");
    } else if (queries.size() > 10) {
        // Hard-code a default maximum number of queries to prevent
        // users from submitting too much to the server in a single call.
        throw new QueryParseException("limit of 10 queries");
    }

    List<List<ChangeInfo>> res = Lists.newArrayListWithCapacity(queries.size());
    for (String query : queries) {
        List<ChangeData> changes = imp.queryChanges(query);
        boolean moreChanges = imp.getLimit() > 0 && changes.size() > imp.getLimit();
        if (moreChanges) {
            if (reverse) {
                changes = changes.subList(1, changes.size());
            } else {
                changes = changes.subList(0, imp.getLimit());
            }
        }
        ChangeData.ensureChangeLoaded(db, changes);
        ChangeData.ensureCurrentPatchSetLoaded(db, changes);
        ChangeData.ensureCurrentApprovalsLoaded(db, changes);

        List<ChangeInfo> info = Lists.newArrayListWithCapacity(changes.size());
        for (ChangeData cd : changes) {
            info.add(toChangeInfo(cd));
        }
        if (moreChanges && !info.isEmpty()) {
            if (reverse) {
                info.get(0)._moreChanges = true;
            } else {
                info.get(info.size() - 1)._moreChanges = true;
            }
        }
        res.add(info);
    }

    if (!accounts.isEmpty()) {
        for (Account account : db.get().accounts().get(accounts.keySet())) {
            AccountAttribute a = accounts.get(account.getId());
            a.name = Strings.emptyToNull(account.getFullName());
        }
    }

    if (format.isJson()) {
        format.newGson().toJson(res.size() == 1 ? res.get(0) : res, new TypeToken<List<ChangeInfo>>() {
        }.getType(), out);
        out.write('\n');
    } else {
        boolean firstQuery = true;
        for (List<ChangeInfo> info : res) {
            if (firstQuery) {
                firstQuery = false;
            } else {
                out.write('\n');
            }
            for (ChangeInfo c : info) {
                String id = new Change.Key(c.id).abbreviate();
                String subject = c.subject;
                if (subject.length() + id.length() > 80) {
                    subject = subject.substring(0, 80 - id.length());
                }
                out.write(id);
                out.write(' ');
                out.write(subject.replace('\n', ' '));
                out.write('\n');
            }
        }
    }
}

From source file:de.schildbach.wallet.ui.ExchangeRatesFragment.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.exchange_rates_fragment_options, menu);

    final MenuItem searchMenuItem = menu.findItem(R.id.exchange_rates_options_search);
    if (Constants.ENABLE_EXCHANGE_RATES) {
        final SearchView searchView = (SearchView) searchMenuItem.getActionView();
        searchView.setOnQueryTextListener(new OnQueryTextListener() {
            @Override/*  w w w.  j a  v  a 2  s .  c o m*/
            public boolean onQueryTextChange(final String newText) {
                query = Strings.emptyToNull(newText.trim());
                getLoaderManager().restartLoader(ID_RATE_LOADER, null, rateLoaderCallbacks);

                return true;
            }

            @Override
            public boolean onQueryTextSubmit(final String query) {
                searchView.clearFocus();

                return true;
            }
        });

        // Workaround for not being able to style the SearchView
        final int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null,
                null);
        final View searchInput = searchView.findViewById(id);
        if (searchInput instanceof EditText)
            ((EditText) searchInput).setTextColor(Color.WHITE);
    } else {
        searchMenuItem.setVisible(false);
    }

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:org.libreoffice.ci.gerrit.buildbot.review.ReviewPublisher.java

private PostReview.Input createReview(final String changeComment) {
    PostReview.Input review = new PostReview.Input();
    review.message = Strings.emptyToNull(changeComment);
    review.labels = Maps.newTreeMap();// w  w  w . j  a va 2s. c o  m
    review.drafts = PostReview.DraftHandling.PUBLISH;
    review.strictLabels = false;
    return review;
}

From source file:org.glowroot.common.config.AlertConfig.java

private static MetricCondition create(AgentConfig.AlertConfig.AlertCondition.MetricCondition condition) {
    ImmutableMetricCondition.Builder builder = ImmutableMetricCondition.builder().metric(condition.getMetric());
    builder.transactionType(Strings.emptyToNull(condition.getTransactionType()));
    builder.transactionName(Strings.emptyToNull(condition.getTransactionName()));
    if (condition.hasPercentile()) {
        builder.percentile(condition.getPercentile().getValue());
    }/*from www . java2  s  .  c o  m*/
    builder.errorMessageFilter(Strings.emptyToNull(condition.getErrorMessageFilter()));
    return builder.threshold(condition.getThreshold()).lowerBoundThreshold(condition.getLowerBoundThreshold())
            .timePeriodSeconds(condition.getTimePeriodSeconds())
            .minTransactionCount(condition.getMinTransactionCount()).build();
}

From source file:com.reprezen.swagedit.editor.outline.QuickOutline.java

@Override
protected Control createTitleControl(Composite parent) {
    filterText = new Text(parent, SWT.NONE);
    Dialog.applyDialogFont(filterText);

    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.CENTER;
    filterText.setLayoutData(data);/*from   w  w w .j  av a 2s  . c  o m*/

    filterText.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            if (isInvocationEvent(e)) {
                e.doit = false;
                handleMultiView();
            } else if (e.keyCode == SWT.CR) {
                handleSelection();
                QuickOutline.this.close();
            } else if (e.keyCode == SWT.ARROW_DOWN) {
                treeViewer.getTree().setFocus();
            } else if (e.keyCode == SWT.ARROW_UP) {
                treeViewer.getTree().setFocus();
            } else if (e.character == SWT.ESC) {
                QuickOutline.this.close();
            }
        }

        public void keyReleased(KeyEvent e) {
            // do nothing
        }
    });

    filterText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            // refresh tree to apply filter

            if (filterTimer != null) {
                filterTimer.cancel();
            }
            // reset the timer each time there is a
            // text modification, so that only the last
            // one will be executed.
            filterTimer = new Timer();
            filterTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (filterText.isDisposed()) {
                        return;
                    }

                    // Make sure we access the text in the correct thread.
                    filterText.getDisplay().asyncExec(new Runnable() {
                        @Override
                        public void run() {
                            // refreshing the tree will execute the filter.
                            if (Strings.emptyToNull(filterText.getText()) == null) {
                                treeViewer.refresh();
                                treeViewer.collapseAll();
                            } else {
                                treeViewer.refresh();
                                TreeItem[] items = treeViewer.getTree().getItems();
                                if (items != null && items.length > 0) {
                                    treeViewer.getTree().setSelection(items[0]);
                                    treeViewer.getTree().showItem(items[0]);
                                } else {
                                    treeViewer.setSelection(StructuredSelection.EMPTY);
                                }
                                treeViewer.expandAll();
                            }
                        }
                    });
                }
            }, 500);
        }
    });
    return filterText;
}

From source file:com.reprezen.swagedit.assist.SwaggerProposalProvider.java

protected Collection<Proposal> createObjectProposals(ObjectTypeDefinition type, AbstractNode element,
        String prefix) {/* w  w w  . j a  va  2  s .  c o m*/
    final Collection<Proposal> proposals = new LinkedHashSet<>();

    for (String property : type.getProperties().keySet()) {
        Proposal proposal = createPropertyProposal(property, type.getProperties().get(property));
        if (proposal != null) {
            if (Strings.emptyToNull(prefix) != null && property.startsWith(prefix)) {
                proposals.add(proposal);
            } else if (element.get(property) == null) {
                proposals.add(proposal);
            }
        }
    }

    for (String property : type.getPatternProperties().keySet()) {
        TypeDefinition typeDef = type.getPatternProperties().get(property);

        if (property.startsWith("^")) {
            property = property.substring(1);
        }

        Proposal proposal = createPropertyProposal(property, typeDef);
        if (proposal != null) {
            proposals.add(proposal);
        }
    }

    if (proposals.isEmpty()) {
        proposals.add(new Proposal("_key_" + ":", "_key_", null, null));
    }

    return proposals;
}