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

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

Introduction

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

Prototype

public static String nullToEmpty(@Nullable String string) 

Source Link

Document

Returns the given string if it is non-null; the empty string otherwise.

Usage

From source file:org.gradle.api.publish.ivy.internal.artifact.AbstractIvyArtifact.java

@Override
public void setConf(@Nullable String conf) {
    this.conf = Strings.nullToEmpty(conf);
}

From source file:com.attribyte.essem.query.GraphQuery.java

/**
 * Creates a graph query from an HTTP request.
 * @param request The HTTP request./*from w  w  w  . j a  va  2s . co m*/
 * @param defaultRange The default range expression.
 */
public GraphQuery(final HttpServletRequest request, final String defaultRange) {

    SearchRequest.Builder requestBuilder = SearchRequest.builder();
    BooleanQuery.Builder queryBuilder = BooleanQuery.builder();
    matchAnyOf(request, "host", Fields.HOST_FIELD, queryBuilder);
    matchAnyOf(request, "app", Fields.APPLICATION_FIELD, queryBuilder);
    matchAnyOf(request, "application", Fields.APPLICATION_FIELD, queryBuilder);
    matchAnyOf(request, "instance", Fields.INSTANCE_FIELD, queryBuilder);
    matchAnyOf(request, "name", Fields.NAME_FIELD, queryBuilder);
    matchAnyOf(request, "metric", Fields.TYPE_FIELD, queryBuilder);
    parseMinMax(request, queryBuilder);

    IntRangeQuery rangeQuery = parseRange(request, defaultRange);
    queryBuilder.mustMatch(rangeQuery);
    String rangeStr = Strings.nullToEmpty(request.getParameter(RANGE_PARAMETER)).trim();
    if (rangeStr.length() == 0) {
        rangeStr = defaultRange;
    }
    this.range = new Range(rangeStr, rangeQuery.minValue, rangeQuery.maxValue);

    requestBuilder.setQuery(queryBuilder.build());

    String[] fields = request.getParameterValues("field");
    if (fields == null || fields.length == 0) {
        requestBuilder.addFields(numericFields);
        fields = numericFields.toArray(new String[numericFields.size()]);
    } else {
        for (String field : fields) {
            requestBuilder.addField(field);
        }
    }

    List<String> aggregateOn = parseAggregate(request, nonNumericFields);

    if (aggregateOn == INVALID_AGGREGATE) {
        this.error = "Only 'name', 'host', 'application', 'instance' are valid for 'aggregateOn'";
        this.isAggregation = false;
        this.searchRequest = null;
        this.downsampleFunction = null;
        this.downsampleInterval = null;
    } else if (aggregateOn.size() == 0) {
        requestBuilder.addField(Fields.NAME_FIELD);
        requestBuilder.addField(Fields.APPLICATION_FIELD);
        requestBuilder.addField(Fields.HOST_FIELD);
        requestBuilder.addField(Fields.INSTANCE_FIELD);
        requestBuilder.addField(Fields.TIMESTAMP_FIELD);
        String sortStr = getParameter(request, "sort", "asc").toLowerCase();
        Sort sort = sortStr.equals("desc") ? TS_DESC : TS_ASC;
        requestBuilder.setSort(sort);
        requestBuilder.setStart(Util.getParameter(request, START_INDEX_PARAMETER, 0));
        requestBuilder.setLimit(Util.getParameter(request, LIMIT_PARAMETER, DEFAULT_LIMIT));
        this.isAggregation = false;
        this.searchRequest = requestBuilder.build();
        this.downsampleInterval = null;
        this.downsampleFunction = null;
        this.error = null;
    } else {
        DateHistogramAggregation.Interval aggregationInterval = parseResolution(request);
        if (aggregationInterval != null) {
            this.downsampleInterval = aggregationInterval.name().toLowerCase();
            BucketAggregation.Order order = BucketAggregation.Order.fromString(request.getParameter("sort"),
                    BucketAggregation.Order.KEY_ASC);

            List<String> numericFields = Lists.newArrayListWithExpectedSize(fields.length);
            for (String field : fields) {
                if (!nonNumericFields.containsKey(field)) {
                    numericFields.add(field);
                }
            }

            if (numericFields.size() > 0) {
                List<Aggregation> fieldAggregations = Lists.newArrayListWithExpectedSize(numericFields.size());
                this.downsampleFunction = getParameter(request, DOWNSAMPLE_FN_PARAMETER, DEFAULT_DOWNSAMPLE_FN);

                MetricAggregation protoAggregation = metricAggregationProtos
                        .get(this.downsampleFunction.toLowerCase().trim());
                if (protoAggregation == null) {
                    protoAggregation = metricAggregationProtos.get(DEFAULT_DOWNSAMPLE_FN);
                }

                for (String field : numericFields) {
                    fieldAggregations.add(protoAggregation.newInstance(field, field));
                }

                DateHistogramAggregation histogramAggregation = new DateHistogramAggregation(
                        protoAggregation.getType(), Fields.TIMESTAMP_FIELD, aggregationInterval, order,
                        fieldAggregations);

                if (aggregateOn.size() == 1) {
                    requestBuilder.addAggregation(
                            new TermsAggregation(aggregateOn.get(0), aggregateOn.get(0), MAX_AGGREGATION_SIZE,
                                    Collections.<Aggregation>singletonList(histogramAggregation)));
                } else {
                    Collections.reverse(aggregateOn);
                    Iterator<String> aggregateFieldIter = aggregateOn.iterator();
                    String currField = aggregateFieldIter.next();
                    TermsAggregation currAggregation = new TermsAggregation(currField, currField,
                            MAX_AGGREGATION_SIZE, Collections.<Aggregation>singletonList(histogramAggregation));
                    while (aggregateFieldIter.hasNext()) {
                        currField = aggregateFieldIter.next();
                        currAggregation = new TermsAggregation(currField, currField, MAX_AGGREGATION_SIZE,
                                Collections.<Aggregation>singletonList(currAggregation));
                    }
                    requestBuilder.addAggregation(currAggregation);
                }

                //We never want aggregation query hits...

                requestBuilder.setStart(0);
                requestBuilder.setLimit(0);

                this.isAggregation = true;
                this.error = null;
                this.searchRequest = requestBuilder.build();

            } else {
                this.isAggregation = false;
                this.downsampleFunction = null;
                this.searchRequest = null;
                this.error = "At least one numeric field must be specified";
            }

        } else {
            this.error = "A valid '" + RESOLUTION_PARAMETER + "' must be specified";
            this.searchRequest = null;
            this.downsampleInterval = null;
            this.downsampleFunction = null;
            this.isAggregation = false;
        }
    }
}

From source file:com.facebook.buck.parser.AbstractParserConfig.java

/**
 * A (possibly empty) sequence of paths to files that should be included by default when
 * evaluating a build file./*from w  ww  .  j  av a  2s .  co m*/
 */
@Value.Lazy
public Iterable<String> getDefaultIncludes() {
    ImmutableMap<String, String> entries = getDelegate().getEntriesForSection(BUILDFILE_SECTION_NAME);
    String includes = Strings.nullToEmpty(entries.get("includes"));
    return Splitter.on(' ').trimResults().omitEmptyStrings().split(includes);
}

From source file:biz.ganttproject.core.chart.canvas.FontChooser.java

public Font getFont(String style) {
    if ("hidden".equalsIgnoreCase(myProperties.getProperty(style + ".visibility"))) {
        return null;
    }//from  ww w  . j a  va 2 s. c o  m
    Font f = myFonts.get(style);
    if (f == null) {
        String propValue = Strings.nullToEmpty(myProperties.getProperty(style + ".font")).trim();
        if (propValue.isEmpty()) {
            // If .font property is not set then we use the base font
            f = myBaseFont.get();
        } else {
            String[] components = propValue.split("\\s+");
            String last = components[components.length - 1];
            String family = "";
            float absoluteSize;
            try {
                // If the last component of .font property is int/float then
                // we check whether it is a relative increment (it should be prefixed with sign)
                // or an absolute value
                if (last.startsWith("+") || last.startsWith("-")) {
                    absoluteSize = Float.parseFloat(last) + myBaseFont.get().getSize();
                } else {
                    absoluteSize = Float.parseFloat(last);
                }
                if (components.length > 1) {
                    family = Joiner.on(' ').join(Arrays.asList(components).subList(0, components.length - 1));
                }
                if (family.isEmpty()) {
                    f = myBaseFont.get().deriveFont(absoluteSize);
                } else {
                    f = Font.decode(family + " 10");
                    if (f == null) {
                        f = myBaseFont.get();
                    }
                    f = f.deriveFont(absoluteSize);
                }
            } catch (NumberFormatException e) {
                f = Font.decode(propValue);
            }
        }
        myFonts.put(style, f);
    }
    return f;
}

From source file:fr.da2i.lup1.entity.formation.Member.java

public String getAddress() {
    return Strings.nullToEmpty(address);
}

From source file:org.kegbot.app.setup.SetupKegbotUrlFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final AppConfiguration prefs = ((KegbotApplication) getActivity().getApplication()).getConfig();

    mView = inflater.inflate(R.layout.setup_kegbot_url_fragment, null);
    mText = (EditText) mView.findViewById(R.id.kegbotUrl);
    mSchemeText = (TextView) mView.findViewById(R.id.kegbotUrlScheme);
    mUseSsl = (CheckBox) mView.findViewById(R.id.useSsl);

    mUseSsl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override/*from   www  . j a  va 2s .  co m*/
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                mSchemeText.setText(R.string.kegbot_url_scheme_https);
            } else {
                mSchemeText.setText(R.string.kegbot_url_scheme_http);
            }
        }
    });
    mUseSsl.setChecked(mText.getText().toString().startsWith("https"));

    final String existingUrl = prefs.getKegbotUrl();
    if (!Strings.isNullOrEmpty(existingUrl)) {
        // Don't clobber the hint if empty.
        final Matcher matcher = URL_PATTERN.matcher(existingUrl);
        if (matcher.matches()) {
            mText.setText(Strings.nullToEmpty(matcher.group(2)));
            mUseSsl.setChecked(Strings.nullToEmpty(matcher.group(1)).startsWith("https"));
        }
    }

    mText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            final String textStr = mText.getText().toString();

            if (textStr.endsWith(".keghub.com") && !mUseSsl.isChecked()) {
                mUseSsl.setChecked(true);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });

    return mView;
}

From source file:com.ning.arecibo.dashboard.resources.HostsStore.java

private void start() {
    service.scheduleWithFixedDelay(new Runnable() {
        @Override//from  www .j  a v a2 s.  com
        public void run() {
            final ImmutableMultimap.Builder<String, Map<String, String>> builder = new ImmutableMultimap.Builder<String, Map<String, String>>();
            final Iterable<String> hosts = client.getHosts();

            for (final String hostName : hosts) {
                final String coreType = Strings.nullToEmpty(galaxyStatusManager.getCoreType(hostName));
                builder.put(coreType, ImmutableMap.<String, String>of("hostName", hostName, "globalZone",
                        Strings.nullToEmpty(galaxyStatusManager.getGlobalZone(hostName)), "configPath",
                        Strings.nullToEmpty(galaxyStatusManager.getConfigPath(hostName)), "configSubPath",
                        Strings.nullToEmpty(galaxyStatusManager.getConfigSubPath(hostName)), "coreType",
                        coreType));
            }

            updateCacheIfNeeded(builder.build());
        }
    }, config.getSampleKindsUpdaterDelay().getMillis(), config.getSampleKindsUpdaterDelay().getMillis(),
            TimeUnit.MILLISECONDS);
    // We give an initial delay for the Galaxy manager to query the Gonsole first

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            service.shutdownNow();
        }
    });
}

From source file:de.metas.ui.web.letter.WebuiLetterRepository.java

public void createC_Letter(@NonNull final WebuiLetter letter) {
    final I_C_Letter persistentLetter = InterfaceWrapperHelper.newInstance(I_C_Letter.class);
    persistentLetter.setLetterSubject(letter.getSubject());
    persistentLetter.setLetterBody(Strings.nullToEmpty(letter.getContent()));
    persistentLetter.setLetterBodyParsed(letter.getContent());

    persistentLetter.setAD_BoilerPlate_ID(letter.getTextTemplateId());

    persistentLetter.setC_BPartner_ID(letter.getBpartnerId());
    persistentLetter.setC_BPartner_Location_ID(letter.getBpartnerLocationId());
    persistentLetter.setC_BP_Contact_ID(letter.getBpartnerContactId());
    persistentLetter.setBPartnerAddress(Strings.nullToEmpty(letter.getBpartnerAddress()));

    InterfaceWrapperHelper.save(persistentLetter);
}

From source file:org.sonar.server.component.db.SnapshotDao.java

public int updateSnapshotAndChildrenLastFlagAndStatus(DbSession session, SnapshotDto snapshot, boolean isLast,
        String status) {/*from  www. j a v  a 2  s  .c  o m*/
    Long rootId = snapshot.getId();
    String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%";
    Long pathRootId = snapshot.getRootIdOrSelf();

    return mapper(session).updateSnapshotAndChildrenLastFlagAndStatus(rootId, pathRootId, path, isLast, status);
}

From source file:uk.org.ngo.squeezer.model.Album.java

private Album(Parcel source) {
    setId(source.readString());/*from   www  .j  a v  a 2 s.  co  m*/
    name = source.readString();
    artist = source.readString();
    year = source.readInt();
    setArtwork_track_id(source.readString());
    mArtworkUrl = Uri.parse(Strings.nullToEmpty(source.readString()));
}