Example usage for org.apache.commons.lang3 StringUtils trimToNull

List of usage examples for org.apache.commons.lang3 StringUtils trimToNull

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils trimToNull.

Prototype

public static String trimToNull(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null .

Usage

From source file:com.webbfontaine.valuewebb.utils.TTMailUtils.java

public List<String> getDuplicationWarningMailingList() {
    List<String> emails = new ArrayList<>();

    if (StringUtils.trimToNull(ApplicationProperties.getDuplicationWarningMailingList()) != null) {
        String[] duplicationWarningEmails = RECIPIENT_PATTERN
                .split(ApplicationProperties.getDuplicationWarningMailingList());
        emails.addAll(Arrays.asList(duplicationWarningEmails));
    }/* w w  w  .ja  v a  2  s  .c om*/
    return emails;
}

From source file:com.mirth.connect.server.util.javascript.JavaScriptTask.java

public Object executeScript(Script compiledScript, Scriptable scope) throws InterruptedException {
    try {//from   w ww  .j  a v  a2  s.co m
        // if the executor is halting this task, we don't want to initialize the context yet
        synchronized (this) {
            ThreadUtils.checkInterruptedStatus();
            context = Context.getCurrentContext();
            Thread.currentThread().setContextClassLoader(contextFactory.getApplicationClassLoader());
            logger.debug(StringUtils.defaultString(StringUtils.trimToNull(getClass().getSimpleName()),
                    getClass().getName()) + " using context factory: " + contextFactory.hashCode());

            /*
             * This should never be called but exists in case executeScript is called from a
             * different thread than the one that entered the context.
             */
            if (context == null) {
                contextCreated = true;
                context = JavaScriptScopeUtil.getContext(contextFactory);
            }

            if (context instanceof MirthContext) {
                ((MirthContext) context).setRunning(true);
            }
        }

        return compiledScript.exec(context, scope);
    } finally {
        if (contextCreated) {
            Context.exit();
            contextCreated = false;
        }
    }
}

From source file:com.squarespace.template.plugins.platform.CommerceUtils.java

public static BigDecimal getAmountFromMoneyNode(JsonNode moneyNode) {
    String value = StringUtils.trimToNull(moneyNode.path("value").asText());
    return value == null ? DEFAULT_MONEY_AMOUNT : new BigDecimal(value);
}

From source file:alfio.manager.EventStatisticsManager.java

private static String prepareSearchTerm(String search) {
    String toSearch = StringUtils.trimToNull(search);
    return toSearch == null ? null : ("%" + toSearch + "%");
}

From source file:hoot.services.controllers.info.AboutResourceTest.java

@Test
@Category(UnitTest.class)
public void getCoreVersionInfo() throws IOException {
    mockBuildInfo();//from  ww  w .j  a  v a  2s  .com

    VersionInfo responseData = null;
    try {
        responseData = resource().path("/about/coreVersionInfo").accept(MediaType.APPLICATION_JSON)
                .get(VersionInfo.class);
    } catch (UniformInterfaceException e) {
        ClientResponse r = e.getResponse();
        Assert.fail("Unexpected response " + r.getStatus() + " " + r.getEntity(String.class));
    }

    Assert.assertEquals("Hootenanny Core", responseData.getName());
    //not a great way to test these, but haven't thought of anything better yet
    Assert.assertNotNull(StringUtils.trimToNull(responseData.getVersion()));
    Assert.assertNotNull(StringUtils.trimToNull(responseData.getBuiltBy()));
}

From source file:com.jayway.restassured.http.ContentType.java

public boolean matches(String contentType) {
    String expectedContentType = StringUtils.trimToNull(contentType);
    if (expectedContentType == null) {
        return false;
    }//w  ww  . java2s  .c om

    for (String supportedContentType : getContentTypeStrings()) {
        if (supportedContentType.equalsIgnoreCase(expectedContentType)) {
            return true;
        }
    }
    return false;
}

From source file:com.clearspring.metriccatcher.Loader.java

/**
 * Load properties, build a MetricCatcher, start catching
 *
 * @param propertiesFile The config file
 * @throws IOException if the properties file cannot be read
 *///from   ww  w .ja  v  a2 s .co  m
public Loader(File propertiesFile) throws IOException {
    logger.info("Starting metriccatcher");

    logger.info("Loading configuration from: " + propertiesFile.getAbsolutePath());
    Properties properties = new Properties();
    try {
        properties.load(new FileReader(propertiesFile));
        for (Object key : properties.keySet()) { // copy properties into system properties
            System.setProperty((String) key, (String) properties.get(key));
        }
    } catch (IOException e) {
        logger.error("error reading properties file: " + e);
        System.exit(1);
    }

    int reportingInterval = 60;
    String intervalProperty = properties.getProperty(METRICCATCHER_INTERVAL);
    if (intervalProperty != null) {
        try {
            reportingInterval = Integer.parseInt(intervalProperty);
        } catch (NumberFormatException e) {
            logger.warn("Couldn't parse " + METRICCATCHER_INTERVAL + " setting", e);
        }
    }

    boolean disableJvmMetrics = false;
    String disableJvmProperty = properties.getProperty(METRICCATCHER_DISABLE_JVM_METRICS);
    if (disableJvmProperty != null) {
        disableJvmMetrics = BooleanUtils.toBoolean(disableJvmProperty);
        if (disableJvmMetrics) {
            logger.info("Disabling JVM metric reporting");
        }
    }

    boolean reportingEnabled = false;
    // Start a Ganglia reporter if specified in the config
    String gangliaHost = properties.getProperty(METRICCATCHER_GANGLIA_HOST);
    String gangliaPort = properties.getProperty(METRICCATCHER_GANGLIA_PORT);
    if (gangliaHost != null && gangliaPort != null) {
        logger.info("Creating Ganglia reporter pointed at " + gangliaHost + ":" + gangliaPort);
        GangliaReporter gangliaReporter = new GangliaReporter(gangliaHost, Integer.parseInt(gangliaPort));
        gangliaReporter.printVMMetrics = !disableJvmMetrics;
        gangliaReporter.start(reportingInterval, TimeUnit.SECONDS);
        reportingEnabled = true;
    }

    // Start a Graphite reporter if specified in the config
    String graphiteHost = properties.getProperty(METRICCATCHER_GRAPHITE_HOST);
    String graphitePort = properties.getProperty(METRICCATCHER_GRAPHITE_PORT);
    if (graphiteHost != null && graphitePort != null) {
        String graphitePrefix = properties.getProperty(METRICCATCHER_GRAPHITE_PREFIX);
        if (graphitePrefix == null) {
            graphitePrefix = InetAddress.getLocalHost().getHostName();
        }
        logger.info("Creating Graphite reporter pointed at " + graphiteHost + ":" + graphitePort
                + " with prefix '" + graphitePrefix + "'");
        GraphiteReporter graphiteReporter = new GraphiteReporter(graphiteHost, Integer.parseInt(graphitePort),
                StringUtils.trimToNull(graphitePrefix));
        graphiteReporter.printVMMetrics = !disableJvmMetrics;
        graphiteReporter.start(reportingInterval, TimeUnit.SECONDS);
        reportingEnabled = true;
    }

    String reporterConfigFile = properties.getProperty(METRICCATCHER_REPORTER_CONFIG);
    if (reporterConfigFile != null) {
        logger.info("Trying to load reporterConfig from file: {}", reporterConfigFile);
        try {
            ReporterConfig.loadFromFileAndValidate(reporterConfigFile).enableAll();
        } catch (Exception e) {
            logger.error("Failed to load metrics-reporter-config, metric sinks will not be activated", e);
        }
        reportingEnabled = true;
    }

    if (!reportingEnabled) {
        logger.error("No reporters enabled.  MetricCatcher can not do it's job");
        throw new RuntimeException("No reporters enabled");
    }

    int maxMetrics = Integer.parseInt(properties.getProperty(METRICCATCHER_MAX_METRICS, "500"));
    logger.info("Max metrics: " + maxMetrics);
    Map<String, Metric> lruMap = new LRUMap<String, Metric>(10, maxMetrics);

    int port = Integer.parseInt(properties.getProperty(METRICCATCHER_UDP_PORT, "1420"));
    logger.info("Listening on UDP port " + port);
    DatagramSocket socket = new DatagramSocket(port);

    metricCatcher = new MetricCatcher(socket, lruMap);
    metricCatcher.start();

    // Register a shutdown hook and wait for termination
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            shutdown();
        };
    });
}

From source file:com.squarespace.template.plugins.platform.CommerceUtils.java

public static String getCurrencyFromMoneyNode(JsonNode moneyNode) {
    String currency = StringUtils.trimToNull(moneyNode.path("currency").asText());
    return currency == null ? DEFAULT_CURRENCY : currency;
}

From source file:com.github.lburgazzoli.camel.CaseToIncidentProcessor.java

@SuppressWarnings("unchecked")
private <T> boolean setIfDifferent(String fieldName, Supplier<T> oldValue, Supplier<T> newValue,
        Consumer<T> setter) {
    T o = oldValue != null ? oldValue.get() : null;
    T n = newValue != null ? newValue.get() : null;

    if (o instanceof String) {
        o = (T) StringUtils.trimToNull((String) o);
    }/*from www  . j av  a  2  s. c o  m*/
    if (n instanceof String) {
        n = (T) StringUtils.trimToNull((String) n);
    }

    if (!Objects.equals(o, n)) {
        LOGGER.debug("Update {} -> old: {}, new: {}", fieldName, o, n);
        setter.accept(n);
        return true;
    } else {
        return false;
    }
}

From source file:it.jaschke.alexandria.model.view.BookListViewModel.java

/**
 * Returns the selection clause used on the query to retrieve the list of books.
 *
 * @return the selection clause used on the query to retrieve the list of books.
 *//*from   w  w  w  .  j a v a 2  s .  c  o  m*/
public String getBookListQuerySelection() {
    return StringUtils.trimToNull(mSearchString) != null ? SELECTION_PARTIAL_TITLE : null;
}