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

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

Introduction

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

Prototype

public static <T extends CharSequence> T defaultIfEmpty(final T str, final T defaultStr) 

Source Link

Document

Returns either the passed in CharSequence, or if the CharSequence is empty or null , the value of defaultStr .

 StringUtils.defaultIfEmpty(null, "NULL")  = "NULL" StringUtils.defaultIfEmpty("", "NULL")    = "NULL" StringUtils.defaultIfEmpty(" ", "NULL")   = " " StringUtils.defaultIfEmpty("bat", "NULL") = "bat" StringUtils.defaultIfEmpty("", null)      = null 

Usage

From source file:com.coffeebeans.services.api.security.CoffeeBeansPrincipal.java

public CoffeeBeansPrincipal(String email, String username) {
    this.email = email;
    this.username = StringUtils.defaultIfEmpty(username, StringUtils.substringBefore(email, "@"));
}

From source file:com.todev.rabbitmqmanagement.ui.exchange.list.ExchangeListEntry.java

@Override
public void displayName(String name) {
    String text = StringUtils.defaultIfEmpty(name, DEFAULT_EXCHANGE_NAME);
    nameView.setText(text);
}

From source file:mtsar.api.csv.TaskCSV.java

public static Iterator<Task> parse(Stage stage, CSVParser csv) {
    final Set<String> header = csv.getHeaderMap().keySet();
    checkArgument(!Sets.intersection(header, Sets.newHashSet(HEADER)).isEmpty(), "Unknown CSV header: %s",
            String.join(",", header));

    return StreamSupport.stream(csv.spliterator(), false).map(row -> {
        final String id = row.isSet("id") ? row.get("id") : null;
        final String[] tags = row.isSet("tags") && !StringUtils.isEmpty(row.get("tags"))
                ? row.get("tags").split("\\|")
                : new String[0];
        final String type = row.get("type");
        final String description = row.isSet("description") ? row.get("description") : null;
        final String[] answers = row.isSet("answers") && !StringUtils.isEmpty(row.get("answers"))
                ? row.get("answers").split("\\|")
                : new String[0];
        final String datetime = row.isSet("datetime") ? row.get("datetime") : null;

        return new Task.Builder().setId(StringUtils.isEmpty(id) ? null : Integer.valueOf(id))
                .setStage(stage.getId()).addAllTags(Arrays.asList(tags))
                .setDateTime(new Timestamp(StringUtils.isEmpty(datetime) ? System.currentTimeMillis()
                        : Long.parseLong(datetime) * 1000L))
                .setType(StringUtils.defaultIfEmpty(type, TaskDAO.TASK_TYPE_SINGLE)).setDescription(description)
                .addAllAnswers(Arrays.asList(answers)).build();
    }).iterator();//from   w ww  .j  a v  a 2 s  .c  o m
}

From source file:mtsar.api.csv.AnswerCSV.java

public static Iterator<Answer> parse(Stage stage, CSVParser csv) {
    final Set<String> header = csv.getHeaderMap().keySet();
    checkArgument(!Sets.intersection(header, Sets.newHashSet(HEADER)).isEmpty(), "Unknown CSV header: %s",
            String.join(",", header));

    return StreamSupport.stream(csv.spliterator(), false).map(row -> {
        final String id = row.isSet("id") ? row.get("id") : null;
        final String[] tags = row.isSet("tags") && !StringUtils.isEmpty(row.get("tags"))
                ? row.get("tags").split("\\|")
                : new String[0];
        final String type = row.isSet("type") ? row.get("type") : null;
        final String workerId = row.get("worker_id");
        final String taskId = row.get("task_id");
        final String[] answers = row.isSet("answers") && !StringUtils.isEmpty(row.get("answers"))
                ? row.get("answers").split("\\|")
                : new String[0];
        final String datetime = row.isSet("datetime") ? row.get("datetime") : null;

        return new Answer.Builder().setId(StringUtils.isEmpty(id) ? null : Integer.valueOf(id))
                .setStage(stage.getId()).addAllTags(Arrays.asList(tags))
                .setDateTime(new Timestamp(StringUtils.isEmpty(datetime) ? System.currentTimeMillis()
                        : Long.parseLong(datetime) * 1000L))
                .setType(StringUtils.defaultIfEmpty(type, AnswerDAO.ANSWER_TYPE_DEFAULT))
                .setWorkerId(Integer.valueOf(workerId)).setTaskId(Integer.valueOf(taskId))
                .addAllAnswers(Arrays.asList(answers)).build();
    }).iterator();//from   w  ww  . ja  va  2 s.  c  o m
}

From source file:com.hurence.logisland.classloading.PluginLoader.java

/**
 * Scan for plugins.//from   www  .  j a  v a  2  s.c  om
 */
private static void scanAndRegisterPlugins() {
    Set<URL> urls = new HashSet<>();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    while (cl != null) {
        if (cl instanceof URLClassLoader) {
            urls.addAll(Arrays.asList(((URLClassLoader) cl).getURLs()));
            cl = cl.getParent();
        }
    }

    for (URL url : urls) {
        try {
            Archive archive = null;
            try {
                archive = new JarFileArchive(
                        new File(URLDecoder.decode(url.getFile(), Charset.defaultCharset().name())), url);
            } catch (Exception e) {
                //silently swallowing exception. just skip the archive since not an archive
            }
            if (archive == null) {
                continue;
            }
            Manifest manifest = archive.getManifest();
            if (manifest != null) {
                String exportedPlugins = manifest.getMainAttributes()
                        .getValue(ManifestAttributes.MODULE_EXPORTS);
                if (exportedPlugins != null) {
                    String version = StringUtils.defaultIfEmpty(
                            manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_VERSION),
                            "UNKNOWN");

                    logger.info("Loading components from module {}", archive.getUrl().toExternalForm());

                    final Archive arc = archive;

                    if (StringUtils.isNotBlank(exportedPlugins)) {
                        Arrays.stream(exportedPlugins.split(",")).map(String::trim).forEach(s -> {
                            if (registry.putIfAbsent(s, PluginClassloaderBuilder.build(arc)) == null) {
                                logger.info("Registered component '{}' version '{}'", s, version);
                            }

                        });
                    }
                }
            }

        } catch (Exception e) {
            logger.error("Unable to load components from " + url.toExternalForm(), e);
        }
    }
}

From source file:com.sonicle.webtop.vfs.SetupDataFtp.java

@Override
public void buildName() {
    name = MessageFormat.format("{0} ({1})", host, StringUtils.defaultIfEmpty(username, "anonymous"));
}

From source file:com.sojw.ahnchangho.core.util.UriUtils.java

/**
 * Url with param./*from ww w.j  ava2  s.  co m*/
 *
 * @param requestURL the request URL
 * @param queryString the query string
 * @return the string
 */
public static String of(final String requestURL, final String queryString) {
    final String url = StringUtils.defaultIfEmpty(requestURL, StringUtils.EMPTY).toString();
    if (Strings.isNullOrEmpty(url)) {
        return StringUtils.EMPTY;
    }

    return url + (queryString == null ? StringUtils.EMPTY : "?" + queryString);
}

From source file:com.gst.template.domain.Template.java

public Template(final String name, final String text, final TemplateEntity entity, final TemplateType type,
        final List<TemplateMapper> mappers) {
    this.name = StringUtils.defaultIfEmpty(name, null);
    this.entity = entity;
    this.type = type;
    this.text = StringUtils.defaultIfEmpty(text, null);
    this.mappers = mappers;
}

From source file:com.neatresults.mgnltweaks.ui.action.OpenBookmarkAction.java

@Override
public void execute() throws ActionExecutionException {
    String path = StringUtils.defaultIfEmpty(definition.getPath(),
            "/modules/neat-tweaks-developers/apps/neatconfiguration/subApps/browser/actionbar/sections/folders/groups/bookmarksActions/items");
    BrowserLocation location = new BrowserLocation("neatconfiguration", "browser", path + ":treeview:");
    eventBus.fireEvent(new LocationChangedEvent(location));
    // open selected node
    try {//from   w w  w. j  a  v  a2  s.c o  m
        ContentChangedEvent cce = new ContentChangedEvent(
                JcrItemUtil.getItemId(RepositoryConstants.CONFIG, path), true);
        eventBus.fireEvent(cce);
    } catch (RepositoryException e) {
        log.error(
                "Ooops, failed to retrieve node at path {} and open it while executing open bookmark action with {}",
                path, e.getMessage(), e);
    }
}

From source file:com.mirth.connect.client.ui.RegexAttachmentDialog.java

public RegexAttachmentDialog(AttachmentHandlerProperties properties) {
    super(PlatformUI.MIRTH_FRAME, true);
    this.parent = PlatformUI.MIRTH_FRAME;

    setTitle("Set Attachment Properties");
    getContentPane().setBackground(UIConstants.BACKGROUND_COLOR);
    setLayout(new MigLayout("novisualpadding, hidemode 3, insets 12", "[fill, grow]"));
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setPreferredSize(new Dimension(650, 550));

    initComponents();//w  w w. ja v a 2 s.  c om
    initLayout();
    initInboundReplacementTable();
    initOutboundReplacementTable();

    attachmentHandlerProperties = properties;

    regexTextField.setText(
            StringUtils.defaultIfEmpty(attachmentHandlerProperties.getProperties().get("regex.pattern"), ""));
    regexTextField.requestFocus();
    regexTextField.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            if (initialFocus) {
                regexTextField.setCaretPosition(0);
                initialFocus = false;
            }
        }

    });
    mimeTypeField.setText(
            StringUtils.defaultIfEmpty(attachmentHandlerProperties.getProperties().get("regex.mimetype"), ""));

    int count = 0;
    while (attachmentHandlerProperties.getProperties().containsKey("regex.replaceKey" + count)) {
        DefaultTableModel tableModel = (DefaultTableModel) inboundReplacementTable.getModel();
        tableModel.addRow(
                new Object[] { attachmentHandlerProperties.getProperties().get("regex.replaceKey" + count),
                        attachmentHandlerProperties.getProperties().get("regex.replaceValue" + count) });
        count++;
    }

    count = 0;
    while (attachmentHandlerProperties.getProperties().containsKey("outbound.regex.replaceKey" + count)) {
        DefaultTableModel tableModel = (DefaultTableModel) outboundReplacementTable.getModel();
        tableModel.addRow(new Object[] {
                attachmentHandlerProperties.getProperties().get("outbound.regex.replaceKey" + count),
                attachmentHandlerProperties.getProperties().get("outbound.regex.replaceValue" + count) });
        count++;
    }

    setLocationRelativeTo(parent);
    setVisible(true);
}