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:net.minecraftforge.gradle.patcher.TaskExtractNew.java

@TaskAction
public void doStuff() throws IOException {
    ending = Strings.nullToEmpty(ending);

    InputSupplier cleanSupplier = getSupplier(getCleanSource());
    InputSupplier dirtySupplier = getSupplier(getDirtySource());

    Set<String> cleanFiles = Sets.newHashSet(cleanSupplier.gatherAll(ending));

    File output = getOutput();//from   w  w  w. ja  v  a2  s  .c om
    output.getParentFile().mkdirs();

    boolean isClassEnding = false; //TODO: Figure out Abrar's logic for this... ending.equals(".class"); // this is a trigger for custom stuff

    ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(output));
    for (String path : dirtySupplier.gatherAll(ending)) {
        if ((isClassEnding && matchesClass(cleanFiles, path)) || cleanFiles.contains(path)) {
            continue;
        }

        zout.putNextEntry(new ZipEntry(path));

        InputStream stream = dirtySupplier.getInput(path);
        ByteStreams.copy(stream, zout);
        stream.close();

        zout.closeEntry();
    }

    zout.close();
    cleanSupplier.close();
    dirtySupplier.close();
}

From source file:de.gesundkrank.wikipedia.hadoop.WikiRevisionWritable.java

public String getText() {
    return Strings.nullToEmpty(text);
}

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

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

From source file:com.opengamma.strata.report.framework.expression.RootEvaluator.java

private EvaluationResult evaluateMeasures(ResultsRow resultsRow, CalculationFunctions functions,
        List<String> remainingTokens) {

    // if no measures, return list of valid measures
    if (remainingTokens.isEmpty() || Strings.nullToEmpty(remainingTokens.get(0)).trim().isEmpty()) {
        List<String> measureNames = ResultsRow.measureNames(resultsRow.getTarget(), functions);
        return EvaluationResult.failure("No measure specified. Use one of: {}", measureNames);
    }/*from w ww  . jav  a2 s  . c  om*/
    // evaluate the measure name
    String measureToken = remainingTokens.get(0);
    return EvaluationResult.of(resultsRow.getResult(measureToken),
            remainingTokens.subList(1, remainingTokens.size()));
}

From source file:com.notifier.desktop.transport.bluetooth.impl.BluetoothTransportImpl.java

@Override
public void doStart() {
    LocalDevice localDevice = null;//from ww w  .j  av  a 2 s. c o m
    try {
        localDevice = LocalDevice.getLocalDevice();
        address = localDevice.getBluetoothAddress();
    } catch (BluetoothStateException e) {
        String message = Strings.nullToEmpty(e.getMessage());
        if ("BluetoothStack not detected".equals(message)) {
            throw new IllegalStateException("Bluetooth not detected, disabling it.", e);
        } else if (message.contains("libbluetooth.so")) {
            throw new IllegalStateException(
                    "You have to install the package libbluetooth-dev on Ubuntu or bluez-libs-devel on Fedora or bluez-devel on openSUSE to be able to receive bluetooth notifications.");
        } else {
            throw new RuntimeException(e);
        }
    }
    enabled = true;
    if (localDevice != null && acceptorThread == null) {
        acceptorThread = new Thread(new Runnable() {
            @Override
            public void run() {
                StreamConnectionNotifier notifier = null;
                try {
                    if (OperatingSystems.CURRENT_FAMILY == OperatingSystems.Family.MAC) {
                        notifier = (StreamConnectionNotifier) Connector.open(URL_MAC);
                    } else {
                        notifier = (StreamConnectionNotifier) Connector.open(URL_WINDOWS_LINUX);
                    }
                    while (!Thread.currentThread().isInterrupted()) {
                        StreamConnection connection = null;
                        InputStream inputStream = null;
                        try {
                            // acceptAndOpen() will never return without connection and it
                            // cannot be interrupted
                            connection = notifier.acceptAndOpen();
                            inputStream = connection.openInputStream();
                            byte[] data = ByteStreams.toByteArray(inputStream);
                            if (enabled) {
                                Notification notification = notificationParser.parse(data);
                                if (notification != null) {
                                    notificationManager.notificationReceived(notification);
                                }
                            }
                        } catch (InterruptedIOException e) {
                            break;
                        } catch (Exception e) {
                            if (e instanceof InterruptedException) {
                                break;
                            } else {
                                logger.error("Error handling bluetooth notification", e);
                                application.showError(Application.NAME + " Bluetooth Error",
                                        "An error ocurred while receiving bluetooth notification.");
                            }
                        } finally {
                            Closeables.closeQuietly(inputStream);
                            if (connection != null) {
                                try {
                                    connection.close();
                                } catch (Exception e) {
                                    logger.warn("Error closing bluetooth connection", e);
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    logger.error("Error setting up bluetooth", e);
                    application.showError("Error setting up Bluetooth",
                            "An error occurred while setting up bluetooth to receive connections.");
                } finally {
                    if (notifier != null) {
                        try {
                            notifier.close();
                        } catch (Exception e) {
                            logger.warn("Error closing bluetooth", e);
                        }
                    }
                    acceptorThread = null; // Allows a new thread to be started if this one dies
                }
            }
        }, NAME);
        acceptorThread.setDaemon(true);
        acceptorThread.start();
    }
}

From source file:org.zenoss.metrics.reporter.HttpPoster.java

private HttpPoster(final URL url, final String user, final String password, ObjectMapper mapper) {
    this.url = url;
    this.mapper = mapper;
    if (!Strings.nullToEmpty(user).trim().isEmpty()) {
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(url.getHost(), url.getPort()),
                new UsernamePasswordCredentials(user, password));
        this.needsAuth = true;
    } else {/*from w w w . j  ava2s  . co m*/
        this.needsAuth = false;
    }
}

From source file:org.jclouds.virtualbox.functions.IpAddressesLoadingCache.java

@Override
public synchronized String get(MachineNameOrIdAndNicSlot machineNameOrIdAndNicPort) throws ExecutionException {
    if (masters.containsKey(machineNameOrIdAndNicPort)) {
        return masters.get(machineNameOrIdAndNicPort);
    }/*from  w  ww .  j av a2 s  . c om*/
    String query = String.format("/VirtualBox/GuestInfo/Net/%s/V4/IP", machineNameOrIdAndNicPort.getSlotText());
    String ipAddress = Strings.nullToEmpty(manager.get().getVBox()
            .findMachine(machineNameOrIdAndNicPort.getMachineNameOrId()).getGuestPropertyValue(query));
    if (!ipAddress.isEmpty()) {
        logger.debug("<< vm(%s) has IP address(%s) at slot(%s)", machineNameOrIdAndNicPort.getMachineNameOrId(),
                ipAddress, machineNameOrIdAndNicPort.getSlotText());
    }
    masters.put(machineNameOrIdAndNicPort, ipAddress);
    return ipAddress;
}

From source file:com.arcbees.website.client.BootstrapperImpl.java

private void validateNameTokenLanguageAndRevealPlace() {
    PlaceRequest currentPlaceRequest = placeManager.getCurrentPlaceRequest();
    String nameToken = Strings.nullToEmpty(History.getToken());
    String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();

    if ("en".compareToIgnoreCase(currentLocale) == 0) {
        if (!Strings.isNullOrEmpty(nameToken) && !NameTokens.isEn(nameToken)) {
            revealTranslatedNameToken(currentPlaceRequest, nameToken);
            return;
        }//from ww  w.  j av a2  s. co m
    } else if ("fr".compareToIgnoreCase(currentLocale) == 0) {
        if (NameTokens.isEn(nameToken)) {
            revealTranslatedNameToken(currentPlaceRequest, nameToken);
            return;
        }
    }

    placeManager.revealCurrentPlace();
}

From source file:de.schildbach.pte.MetProvider.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 ("Regional Train :".equals(longName))
            return new Line(id, network, Product.REGIONAL_TRAIN, symbol);
        if ("Regional Train".equals(trainName))
            return new Line(id, network, Product.REGIONAL_TRAIN, null);
        if ("vPK".equals(symbol) && "Regional Train Pakenham".equals(longName))
            return new Line(id, network, Product.REGIONAL_TRAIN, "V/Line");
    } else if ("1".equals(mot)) {
        if (trainType == null && trainNum != null)
            return new Line(id, network, Product.SUBURBAN_TRAIN, trainNum);
        if ("Metropolitan Train".equals(trainName) && trainNum == null)
            return new Line(id, network, Product.SUBURBAN_TRAIN, Strings.nullToEmpty(name));
    }/*  ww  w . j  av a2s .  c o m*/

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

From source file:org.sonar.plugins.buildbreaker.IssuesSeverityBreaker.java

/**
 * Constructor used to inject dependencies.
 *
 * @param analysisMode the analysis mode
 * @param projectIssues the project's issues
 * @param settings the project settings//  w w  w  . jav a  2 s.  c  o m
 */
public IssuesSeverityBreaker(AnalysisMode analysisMode, ProjectIssues projectIssues, Settings settings) {
    this.analysisMode = analysisMode;
    this.projectIssues = projectIssues;
    issuesSeveritySetting = Strings.nullToEmpty(settings.getString(BuildBreakerPlugin.ISSUES_SEVERITY_KEY))
            .toUpperCase(Locale.US);
    issuesSeveritySettingValue = Severity.ALL.indexOf(issuesSeveritySetting);
}