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:diskCacheV111.doors.DcapDoorSettings.java

public void init() {
    isAuthorizationStrong = (auth != null) && auth.equals("strong");
    isAuthorizationRequired = (auth != null) && (auth.equals("strong") || auth.equals("required"));
    anonymousAccessLevel = (anon != null) ? UnionLoginStrategy.AccessLevel.valueOf(anon.toUpperCase())
            : UnionLoginStrategy.AccessLevel.READONLY;

    if (clientVersion != null) {
        try {/*  w w w. j av a2 s . co m*/
            List<String> values = Splitter.on(':').limit(2).trimResults().splitToList(clientVersion);
            if (values.get(0).isEmpty()) {
                throw new IllegalArgumentException("missing minimum version");
            }
            minClientVersion = new DCapDoorInterpreterV3.Version(values.get(0));
            if (values.size() > 1) {
                if (values.get(1).isEmpty()) {
                    throw new IllegalArgumentException("missing maximum version");
                }
                maxClientVersion = new DCapDoorInterpreterV3.Version(values.get(1));
            }
        } catch (IllegalArgumentException e) {
            _log.error("Ignoring client version limits: syntax error with '{}': {}", clientVersion,
                    e.getMessage());
        }
    }

    ioQueueName = Strings.emptyToNull(ioQueueName);

    doorRestriction = isReadOnly ? Restrictions.readOnly() : Restrictions.none();

    checkStagePermission = new CheckStagePermission(stageConfigurationFilePath);
    checkStagePermission.setAllowAnonymousStaging(allowAnonymousStaging);
}

From source file:de.schildbach.pte.SeptaProvider.java

@Override
public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
        final int maxDepartures, final boolean equivs) throws IOException {
    checkNotNull(Strings.emptyToNull(stationId));

    final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
    final QueryDeparturesResult result = new QueryDeparturesResult(header);

    // scrape page
    final StringBuilder uri = new StringBuilder(stationBoardEndpoint);
    appendXmlStationBoardParameters(uri, time, stationId, maxDepartures, false, null);
    final CharSequence page = ParserUtils.scrape(uri.toString());

    // parse page
    final Matcher mPageCoarse = P_DEPARTURES_PAGE_COARSE.matcher(page);
    if (mPageCoarse.matches()) {
        // messages
        if (mPageCoarse.group(5) != null) {
            result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, stationId),
                    Collections.<Departure>emptyList(), null));
            return result;
        } else if (mPageCoarse.group(6) != null)
            return new QueryDeparturesResult(header, Status.INVALID_STATION);
        else if (mPageCoarse.group(7) != null)
            return new QueryDeparturesResult(header, Status.SERVICE_DOWN);

        final String[] placeAndName = splitStationName(ParserUtils.resolveEntities(mPageCoarse.group(1)));
        final Calendar currentTime = new GregorianCalendar(timeZone);
        currentTime.clear();//w  w  w.  j  a v a  2  s. c  om
        ParserUtils.parseAmericanDate(currentTime, mPageCoarse.group(2));
        ParserUtils.parseAmericanTime(currentTime, mPageCoarse.group(3));

        final List<Departure> departures = new ArrayList<Departure>(8);
        String oldZebra = null;

        final Matcher mDepCoarse = P_DEPARTURES_COARSE.matcher(mPageCoarse.group(4));
        while (mDepCoarse.find()) {
            final String zebra = mDepCoarse.group(1);
            if (oldZebra != null && zebra.equals(oldZebra))
                throw new IllegalArgumentException("missed row? last:" + zebra);
            else
                oldZebra = zebra;

            final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(2));
            if (mDepFine.matches()) {
                final Calendar plannedTime = new GregorianCalendar(timeZone);
                plannedTime.setTimeInMillis(currentTime.getTimeInMillis());
                ParserUtils.parseAmericanTime(plannedTime, mDepFine.group(1));

                if (plannedTime.getTimeInMillis()
                        - currentTime.getTimeInMillis() < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
                    plannedTime.add(Calendar.DAY_OF_MONTH, 1);

                final Calendar predictedTime;
                final String prognosis = ParserUtils.resolveEntities(mDepFine.group(2));
                if (prognosis != null) {
                    predictedTime = new GregorianCalendar(timeZone);
                    if (prognosis.equals("pnktlich")) {
                        predictedTime.setTimeInMillis(plannedTime.getTimeInMillis());
                    } else {
                        predictedTime.setTimeInMillis(currentTime.getTimeInMillis());
                        ParserUtils.parseAmericanTime(predictedTime, prognosis);
                    }
                } else {
                    predictedTime = null;
                }

                final String lineType = mDepFine.group(3);

                final Line line = parseLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4)), false);

                final String destinationId = mDepFine.group(5);
                final String destinationName = ParserUtils.resolveEntities(mDepFine.group(6));
                final Location destination;
                if (destinationId != null) {
                    final String[] destinationPlaceAndName = splitStationName(destinationName);
                    destination = new Location(LocationType.STATION, destinationId, destinationPlaceAndName[0],
                            destinationPlaceAndName[1]);
                } else {
                    destination = new Location(LocationType.ANY, null, null, destinationName);
                }

                final Position position = parsePosition(ParserUtils.resolveEntities(mDepFine.group(7)));

                final Departure dep = new Departure(plannedTime.getTime(),
                        predictedTime != null ? predictedTime.getTime() : null, line, position, destination,
                        null, null);

                if (!departures.contains(dep))
                    departures.add(dep);
            } else {
                throw new IllegalArgumentException(
                        "cannot parse '" + mDepCoarse.group(2) + "' on " + stationId);
            }
        }

        result.stationDepartures.add(new StationDepartures(
                new Location(LocationType.STATION, stationId, placeAndName[0], placeAndName[1]), departures,
                null));
        return result;
    } else {
        throw new IllegalArgumentException("cannot parse '" + page + "' on " + stationId);
    }
}

From source file:org.killbill.billing.plugin.analytics.http.ReportsServlet.java

private void doHandleReports(final HttpServletRequest req, final HttpServletResponse resp,
        final TenantContext context) throws ServletException, IOException {
    final String[] rawReportNames = req.getParameterValues(REPORTS_QUERY_NAME);
    if (rawReportNames == null || rawReportNames.length == 0) {
        listReports(req, resp, context);
        return;/*www .  j  a v  a 2 s . c o m*/
    }

    final LocalDate startDate = Strings.emptyToNull(req.getParameter(REPORTS_QUERY_START_DATE)) != null
            ? DATE_FORMAT.parseLocalDate(req.getParameter(REPORTS_QUERY_START_DATE))
            : null;
    final LocalDate endDate = Strings.emptyToNull(req.getParameter(REPORTS_QUERY_END_DATE)) != null
            ? DATE_FORMAT.parseLocalDate(req.getParameter(REPORTS_QUERY_END_DATE))
            : null;

    final boolean sqlOnly = req.getParameter(REPORT_QUERY_SQL_ONLY) != null;

    if (sqlOnly) {
        for (final String sql : reportsUserApi.getSQLForReport(rawReportNames, startDate, endDate, context)) {
            resp.getOutputStream().write(("\n" + sql + "\n").getBytes(Charset.forName("UTF-8")));
        }
        resp.setContentType("text/plain");
    } else {
        final SmootherType smootherType = Smoother
                .fromString(Strings.emptyToNull(req.getParameter(REPORTS_SMOOTHER_NAME)));

        // TODO PIERRE Switch to an equivalent of StreamingOutputStream?
        final List<Chart> results = reportsUserApi.getDataForReport(rawReportNames, startDate, endDate,
                smootherType, context);

        final String format = Objects.firstNonNull(Strings.emptyToNull(req.getParameter(REPORTS_DATA_FORMAT)),
                JSON_DATA_FORMAT);
        if (CSV_DATA_FORMAT.equals(format)) {
            final OutputStream out = resp.getOutputStream();
            writeAsCSV(results, out);
            resp.setContentType("text/csv");
        } else {
            resp.getOutputStream().write(jsonMapper.writeValueAsBytes(results));
            resp.setContentType("application/json");
        }
    }
}

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

public void setUrl(String url) {
    this.url = Strings.emptyToNull(url);
}

From source file:org.eclipse.buildship.core.launch.BaseLaunchRequestJob.java

private String toNonEmpty(List<String> stringValues, String defaultMessage) {
    String string = Strings.emptyToNull(CollectionsUtils.joinWithSpace(stringValues));
    return string != null ? string : defaultMessage;
}

From source file:com.eucalyptus.vm.VmNetworkConfig.java

static String ipOrDefault(final String ip) {
    return Objects.firstNonNull(Strings.emptyToNull(ip), VmNetworkConfig.DEFAULT_IP);
}

From source file:ezbake.deployer.publishers.EzReverseProxyRegister.java

/**
 * Since for OpenShift these will be mostly following the same pattern, might as well, just auto create
 * the UserFacingUrlPrefix and UpStreamPath if they are missing
 *
 * @param registration - the registration to set the UserFacingUrlPrefix and UpStreamPath
 *///from w  w w.  ja  v  a  2  s .  c o m
private void autoSetMissing(UpstreamServerRegistration registration, String userFacingUrl) {
    String prefix = Objects.firstNonNull(Strings.emptyToNull(userFacingUrl), registration.getAppName());
    if (!registration.isSetUserFacingUrlPrefix())
        registration.setUserFacingUrlPrefix(getUserFacingDomain() + "/" + prefix + "/");
    if (!registration.isSetUpstreamPath())
        registration.setUpstreamPath("");
}

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

public void setUser(String user) {
    this.user = Strings.emptyToNull(user);
}

From source file:org.obm.icalendar.ical4jwrapper.ICalendarEvent.java

public String transparency() {
    Transp transp = vEvent.getTransparency();
    if (transp != null) {
        return Strings.emptyToNull(transp.getValue());
    }/*from w w  w .j a  v a2s .com*/
    return null;
}

From source file:org.datacleaner.windows.SalesforceDatastoreDialog.java

@Override
protected SalesforceDatastore createDatastore() {
    final String name = _datastoreNameTextField.getText();
    final String username = _usernameTextField.getText();
    final char[] passwordChars = _passwordTextField.getPassword();
    final String password = String.valueOf(passwordChars);
    final String securityToken = _securityTokenTextField.getText();
    final String endpointUrl = Strings.emptyToNull(getUrlFromComboBox());

    return new SalesforceDatastore(name, username, password, securityToken, endpointUrl);
}