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.obm.push.contacts.ContactCreationIdempotenceService.java

@VisibleForTesting
HashCode hash(MSContact contact) {/*from  w  w w.  java 2 s  .co m*/
    return Hashing.sha1().newHasher().putUnencodedChars(Strings.nullToEmpty(contact.getLastName()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getFirstName()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getMiddleName()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getFileAs()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getEmail1Address()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getEmail2Address()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getEmail3Address()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getAssistantName()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getAssistantPhoneNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getAssistnamePhoneNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getBusiness2PhoneNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getBusinessAddressCity()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getBusinessPhoneNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getWebPage()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getBusinessAddressCountry()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getDepartment()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getBusinessFaxNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getMiddleName()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getHomeAddressCity()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getHomeAddressCountry()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getHomeFaxNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getHomePhoneNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getHome2PhoneNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getHomeAddressPostalCode()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getHomeAddressState()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getHomeAddressStreet()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getMobilePhoneNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getSuffix()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getCompanyName()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getOtherAddressCity()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getOtherAddressCountry()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getCarPhoneNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getOtherAddressPostalCode()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getOtherAddressState()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getOtherAddressStreet()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getPagerNumber()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getTitle()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getBusinessPostalCode()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getSpouse()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getBusinessState()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getBusinessStreet()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getJobTitle()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getOfficeLocation()))
            .putUnencodedChars(Strings.nullToEmpty(contact.getRadioPhoneNumber())).hash();
}

From source file:io.github.runassudo.ptoffline.pte.AbstractNetworkProvider.java

@Override
public Style lineStyle(final @Nullable String network, final @Nullable Product product,
        final @Nullable String label) {
    final Map<String, Style> styles = this.styles;
    if (styles != null && product != null) {
        if (network != null) {
            // check for line match
            final Style lineStyle = styles
                    .get(network + STYLES_SEP + product.code + Strings.nullToEmpty(label));
            if (lineStyle != null)
                return lineStyle;

            // check for product match
            final Style productStyle = styles.get(network + STYLES_SEP + product.code);
            if (productStyle != null)
                return productStyle;

            // check for night bus, as that's a common special case
            if (product == Product.BUS && label != null && label.startsWith("N")) {
                final Style nightStyle = styles.get(network + STYLES_SEP + "BN");
                if (nightStyle != null)
                    return nightStyle;
            }//from   www  .j  a va2 s . co m
        }

        // check for line match
        final String string = product.code + Strings.nullToEmpty(label);
        final Style lineStyle = styles.get(string);
        if (lineStyle != null)
            return lineStyle;

        // check for product match
        final Style productStyle = styles.get(Character.toString(product.code));
        if (productStyle != null)
            return productStyle;

        // check for night bus, as that's a common special case
        if (product == Product.BUS && label != null && label.startsWith("N")) {
            final Style nightStyle = styles.get("BN");
            if (nightStyle != null)
                return nightStyle;
        }
    }

    // standard colors
    return Standard.STYLES.get(product);
}

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

@Override
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
        final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
        final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
    if ("0".equals(mot)) {
        if ("M".equals(trainType) && trainNum != null && trainName != null && trainName.endsWith("Meridian"))
            return new Line(id, network, Product.REGIONAL_TRAIN, "M" + trainNum);
        if ("ZUG".equals(trainType) && trainNum != null)
            return new Line(id, network, Product.REGIONAL_TRAIN, trainNum);
    } else if ("1".equals(mot)) {
        if ("ABR".equals(trainType) || "ABELLIO Rail NRW GmbH".equals(trainName))
            return new Line(id, network, Product.SUBURBAN_TRAIN, "ABR" + trainNum);
        if ("SBB".equals(trainType) || "SBB GmbH".equals(trainName))
            return new Line(id, network, Product.REGIONAL_TRAIN, "SBB" + Strings.nullToEmpty(trainNum));
    } else if ("5".equals(mot)) {
        if (name != null && name.startsWith("Stadtbus Linie ")) // Lindau
            return super.parseLine(id, network, mot, symbol, name.substring(15), longName, trainType, trainNum,
                    trainName);/*from ww w .  j a  v a2s  . c  om*/
        else
            return super.parseLine(id, network, mot, symbol, name, longName, trainType, trainNum, trainName);
    } else if ("16".equals(mot)) {
        if ("EC".equals(trainType) && trainNum != null)
            return new Line(id, network, Product.HIGH_SPEED_TRAIN, "EC" + trainNum);
        if ("IC".equals(trainType) && trainNum != null)
            return new Line(id, network, Product.HIGH_SPEED_TRAIN, "IC" + trainNum);
        if ("ICE".equals(trainType) && trainNum != null)
            return new Line(id, network, Product.HIGH_SPEED_TRAIN, "ICE" + trainNum);
        if ("CNL".equals(trainType) && trainNum != null)
            return new Line(id, network, Product.HIGH_SPEED_TRAIN, "CNL" + trainNum);
        if ("THA".equals(trainType) && trainNum != null) // Thalys
            return new Line(id, network, Product.HIGH_SPEED_TRAIN, "THA" + trainNum);
        if ("TGV".equals(trainType) && trainNum != null) // Train a grande Vitesse
            return new Line(id, network, Product.HIGH_SPEED_TRAIN, "TGV" + trainNum);
        if ("RJ".equals(trainType) && trainNum != null) // railjet
            return new Line(id, network, Product.HIGH_SPEED_TRAIN, "RJ" + trainNum);
        if ("WB".equals(trainType) && trainNum != null) // WESTbahn
            return new Line(id, network, Product.HIGH_SPEED_TRAIN, "WB" + trainNum);
        if ("HKX".equals(trainType) && trainNum != null) // Hamburg-Kln-Express
            return new Line(id, network, Product.HIGH_SPEED_TRAIN, "HKX" + trainNum);
        if ("D".equals(trainType) && trainNum != null) // Schnellzug
            return new Line(id, network, Product.HIGH_SPEED_TRAIN, "D" + trainNum);

        if ("IR".equals(trainType) && trainNum != null) // InterRegio
            return new Line(id, network, Product.REGIONAL_TRAIN, "IR" + trainNum);
    }

    return super.parseLine(id, network, mot, symbol, name, longName, trainType, trainNum, trainName);
}

From source file:io.druid.indexer.path.StaticPathSpec.java

private static void addInputPath(Job job, Iterable<String> pathStrings,
        Class<? extends InputFormat> inputFormatClass) {
    Configuration conf = job.getConfiguration();
    StringBuilder inputFormats = new StringBuilder(Strings.nullToEmpty(conf.get(MultipleInputs.DIR_FORMATS)));

    String[] paths = Iterables.toArray(pathStrings, String.class);
    for (int i = 0; i < paths.length - 1; i++) {
        if (inputFormats.length() > 0) {
            inputFormats.append(',');
        }/*from w  w  w  .j  a  v a 2 s  . c o m*/
        inputFormats.append(paths[i]).append(';').append(inputFormatClass.getName());
    }
    if (inputFormats.length() > 0) {
        conf.set(MultipleInputs.DIR_FORMATS, inputFormats.toString());
    }
    // add last one separately for possible initialization in MultipleInputs
    MultipleInputs.addInputPath(job, new Path(paths[paths.length - 1]), inputFormatClass);
}

From source file:net.sourceforge.ganttproject.chart.gantt.MouseMotionListenerImpl.java

@Override
public void mouseMoved(MouseEvent e) {
    ChartItem itemUnderPoint = myChartController.getChartItemUnderMousePoint(e.getX(), e.getY());
    Task taskUnderPoint = itemUnderPoint == null ? null : itemUnderPoint.getTask();
    // System.err.println("[OldMouseMotionListenerImpl] mouseMoved:
    // taskUnderPoint="+taskUnderPoint);
    myChartController.hideTooltip();/*from   w ww.  j a va2s  . c  om*/
    if (taskUnderPoint == null) {
        myChartComponent.setDefaultCursor();

        if (itemUnderPoint instanceof CalendarChartItem) {
            CalendarEvent event = findCalendarEvent(((CalendarChartItem) itemUnderPoint).getDate());
            if (event != null) {
                String tooltipText;
                if (event.isRecurring) {
                    tooltipText = GanttLanguage.getInstance().formatText(
                            "timeline.holidayTooltipRecurring.pattern",
                            GanttLanguage.getInstance().getRecurringDateFormat().format(event.myDate),
                            Strings.nullToEmpty(event.getTitle()));
                } else {
                    tooltipText = GanttLanguage.getInstance().formatText("timeline.holidayTooltip.pattern",
                            GanttLanguage.getInstance()
                                    .formatDate(CalendarFactory.createGanttCalendar(event.myDate)),
                            Strings.nullToEmpty(event.getTitle()));
                }
                myChartController.showTooltip(e.getX(), e.getY(), tooltipText);
            }
        }
    } else if (itemUnderPoint instanceof TaskBoundaryChartItem) {
        Cursor cursor = ((TaskBoundaryChartItem) itemUnderPoint).isStartBoundary()
                ? GanttGraphicArea.W_RESIZE_CURSOR
                : GanttGraphicArea.E_RESIZE_CURSOR;
        myChartComponent.setCursor(cursor);
    }
    // special cursor
    else if (itemUnderPoint instanceof TaskProgressChartItem) {
        myChartComponent.setCursor(GanttGraphicArea.CHANGE_PROGRESS_CURSOR);
    } else if (itemUnderPoint instanceof TaskNotesChartItem && taskUnderPoint.getNotes() != null) {
        myChartComponent.setCursor(ChartComponentBase.HAND_CURSOR);
        myChartController.showTooltip(e.getX(), e.getY(), GanttLanguage.getInstance()
                .formatText("task.notesTooltip.pattern", taskUnderPoint.getNotes().replace("\n", "<br>")));
    } else {
        myChartComponent.setCursor(ChartComponentBase.HAND_CURSOR);
    }

}

From source file:io.druid.segment.filter.InFilter.java

private DruidPredicateFactory getPredicateFactory() {
    return new DruidPredicateFactory() {
        @Override// w w  w  .  j  a  va  2 s .  co m
        public Predicate<String> makeStringPredicate() {
            if (extractionFn != null) {
                return new Predicate<String>() {
                    @Override
                    public boolean apply(String input) {
                        return values.contains(Strings.nullToEmpty(extractionFn.apply(input)));
                    }
                };
            } else {
                return new Predicate<String>() {
                    @Override
                    public boolean apply(String input) {
                        return values.contains(Strings.nullToEmpty(input));
                    }
                };
            }
        }

        @Override
        public DruidLongPredicate makeLongPredicate() {
            if (extractionFn != null) {
                return new DruidLongPredicate() {
                    @Override
                    public boolean applyLong(long input) {
                        return values.contains(extractionFn.apply(input));
                    }
                };
            } else {
                return longPredicateSupplier.get();
            }
        }
    };
}

From source file:com.b2international.snowowl.datastore.cdo.CDOCommitInfoUtils.java

/**
 * Returns with the leading UUID from the commit comment if any.
 * If no leading UUID can be extracted from the comment, then this method generates one
 * and returns with it./*w  w w . j ava  2 s .  c  o  m*/
 * @param comment the commit comment.
 * @return a UUID identifying a commit comment.
 */
public static String getUuid(@Nullable final String comment) {

    final String _comment = Strings.nullToEmpty(comment);
    final Matcher matcher = CDOCommitInfoConstants.UUID_PATETRN.matcher(_comment);

    String commitId = null;

    while (matcher.find()) {

        commitId = matcher.group(0);
        break;

    }

    if (StringUtils.isEmpty(commitId)) {
        commitId = UUID.randomUUID().toString();
    }
    return commitId;
}

From source file:com.mgmtp.perfload.refapp.resources.RefAppResource.java

/**
 * Tests get and sends a test string back to the client.
 * //from  www .j  a  va2 s  .  c  o m
 * @param accept
 *            The header string of the "Accept" attribute.
 * @return A JSON or a XML string based on the requested Accept configuration.
 */
@GET
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/test")
public String getData(@HeaderParam("Content-Type") final String accept) {
    Strings.nullToEmpty(accept);

    if (accept.equals(MediaType.APPLICATION_JSON)) {
        return String.format(JSONSTRING, rng.nextInt(10000));
    } else if (accept.equals(MediaType.APPLICATION_XML)) {
        return String.format(XMLSTRING, rng.nextInt(10000));
    }

    return "";
}

From source file:uk.ac.stfc.isis.ibex.configserver.displaying.DisplayConfiguration.java

/**
 * Returns the name of the default synoptic.
 * 
 * @return the default synoptic
 */
public String defaultSynoptic() {
    return Strings.nullToEmpty(defaultSynoptic);
}