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

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

Introduction

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

Prototype

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

Source Link

Document

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

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

Usage

From source file:org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.java

public boolean configureVM() throws CoreException {
    String javaHome = preferenceManager.getPreferences().getJavaHome();
    if (javaHome != null) {
        File jvmHome = new File(javaHome);
        if (jvmHome.isDirectory()) {
            IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
            File location = defaultVM.getInstallLocation();
            if (!location.equals(jvmHome)) {
                IVMInstall vm = findVM(jvmHome);
                if (vm == null) {
                    IVMInstallType installType = JavaRuntime
                            .getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
                    long unique = System.currentTimeMillis();
                    while (installType.findVMInstall(String.valueOf(unique)) != null) {
                        unique++;/*  w  ww.  j  a  va 2s .c o m*/
                    }
                    String vmId = String.valueOf(unique);
                    VMStandin vmStandin = new VMStandin(installType, vmId);
                    String name = StringUtils.defaultIfBlank(jvmHome.getName(), "JRE");
                    vmStandin.setName(name);
                    vmStandin.setInstallLocation(jvmHome);
                    vm = vmStandin.convertToRealVM();
                }
                JavaRuntime.setDefaultVMInstall(vm, new NullProgressMonitor());
                JDTUtils.setCompatibleVMs(vm.getId());
                return true;
            }
        }
    }
    return false;
}

From source file:org.eclipse.jdt.ls.core.internal.JVMConfigurator.java

public static boolean configureDefaultVM(Preferences preferences) throws CoreException {
    if (preferences == null) {
        return false;
    }/*ww w  .j  av a 2  s.c  om*/
    String javaHome = preferences.getJavaHome();
    if (javaHome != null) {
        File jvmHome = new File(javaHome);
        if (jvmHome.isDirectory()) {
            IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
            File location = defaultVM.getInstallLocation();
            if (!location.equals(jvmHome)) {
                IVMInstall vm = findVM(jvmHome);
                if (vm == null) {
                    IVMInstallType installType = JavaRuntime
                            .getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
                    long unique = System.currentTimeMillis();
                    while (installType.findVMInstall(String.valueOf(unique)) != null) {
                        unique++;
                    }
                    String vmId = String.valueOf(unique);
                    VMStandin vmStandin = new VMStandin(installType, vmId);
                    String name = StringUtils.defaultIfBlank(jvmHome.getName(), "JRE");
                    vmStandin.setName(name);
                    vmStandin.setInstallLocation(jvmHome);
                    vm = vmStandin.convertToRealVM();
                }
                JavaRuntime.setDefaultVMInstall(vm, new NullProgressMonitor());
                JDTUtils.setCompatibleVMs(vm.getId());
                return true;
            }
        }
    }
    return false;
}

From source file:org.goko.common.bindings.validator.StringRealNumberValidator.java

@Override
public IStatus validate(Object value) {
    if (value instanceof BigDecimal || value instanceof Integer || value instanceof Double
            || value instanceof Float) {
        return ValidationStatus.ok();
    }//from www  .j a  v a  2 s. com
    if (value != null && value instanceof String && StringUtils
            .defaultIfBlank(value.toString(), StringUtils.EMPTY).matches("-?[0-9]+(\\.[0-9]*)?")) {
        return ValidationStatus.ok();
    }
    return ValidationStatus
            .error("Invalid number : value '" + String.valueOf(value) + "' is not a valid number.");
}

From source file:org.goko.core.gcode.bean.commands.MotionCommand.java

private String replace(String target, String pattern, BigDecimalQuantity<?> coord) {
    if (StringUtils.defaultIfBlank(target, StringUtils.EMPTY).contains(pattern)) {
        return target.replace(pattern, String.valueOf(coord.value()));
    }/* w  w w  . j  a v a  2 s  . c o  m*/
    return target;
}

From source file:org.jbb.lib.eventbus.JbbEventBus.java

private void includeMetaData(JbbEvent event) {
    String requestId = StringUtils.defaultIfBlank(RequestIdUtils.getCurrentRequestId(), null);
    event.setSourceRequestId(Optional.ofNullable(requestId));

    SecurityContentUser securityContentUser = userDetailsSource.getFromApplicationContext();
    if (securityContentUser != null && securityContentUser.getUserId() != null
            && !LONG_ZERO.equals(securityContentUser.getUserId())) {
        event.setSourceMemberId(Optional.of(securityContentUser.getUserId()));
    }/*from  w  w w  .  ja va 2  s  .co  m*/

    event.setSourceIpAddress(Optional.ofNullable(servletRequestHolder.getCurrentIpAddress()));
    event.setSourceSessionId(Optional.ofNullable(servletRequestHolder.getCurrentSessionId()));
}

From source file:org.jbb.lib.properties.SafeBlankPropertyAspect.java

@Around("execution(* org.jbb.lib.properties.ModuleProperties.getProperty(..)) && args(key)")
public Object makeSafeBlankProperty(ProceedingJoinPoint joinPoint, String key) {
    ModuleProperties properties = (ModuleProperties) joinPoint.getTarget();
    String currentProperty = properties.getProperty(key);
    return StringUtils.defaultIfBlank(currentProperty, null);
}

From source file:org.jvnet.hudson.test.PluginAutomaticTestBuilder.java

/**
 * @param params//from  w  w  w .  j a  va 2  s . c o m
 *      Various information about the plugin that maven-hpi-plugin adds.
 *      As of 1.119, this includes the followings:
 *
 *      basedir (String) : directory that contains pom.xml
 *      artifactId (String) : artifact ID from the pom.xml
 *      packaging (String) : packaging of from the pom.xml (used to determine if the pom is a plugin or not)
 *      outputDirectory (String) : target/classes dir where class files and resources can be found
 *      testOutputDirectory (String) : target/test-classes.
 *      requirePI (String) : either {@code true} to verify that all the jelly scripts have the Jelly XSS PI in
 *      them or {@code false} to ignore any missing ones.
 */
public static TestSuite build(Map<String, ?> params) throws Exception {
    TestSuite master = new TestSuite();
    if (params.containsKey("outputDirectory")) { // shouldn't happen, but be defensive
        File outputDirectory = new File((String) params.get("outputDirectory"));
        TestSuite inJenkins = JellyTestSuiteBuilder.build(outputDirectory, toBoolean(params.get("requirePI")));
        inJenkins.addTest(new OtherTests("testCliSanity", params));
        String packaging = StringUtils.defaultIfBlank((String) params.get("packaging"), "hpi");
        if ("hpi".equals(packaging)) {
            inJenkins.addTest(new OtherTests("testPluginActive", params));
        }
        master.addTest(inJenkins);
        master.addTest(new PropertiesTestSuite(outputDirectory));
    }
    return master;
}

From source file:org.kie.workbench.common.forms.migration.tool.pipelines.basic.FormDefinitionGenerator.java

private void maybeArrangeNestedForms(FormMigrationSummary summary, List<FormMigrationSummary> modelForms) {
    final Form originalForm = summary.getOriginalForm().get();
    final FormDefinition formDefinition = summary.getNewForm().get();

    formDefinition.getFields().stream().filter(fieldDefinition -> fieldDefinition instanceof HasNestedForm)
            .map(fieldDefinition -> (HasNestedForm) fieldDefinition).forEach(hasNestedForm -> {
                modelForms.stream().filter(modelSummary -> modelSummary.getOriginalForm().getPath()
                        .getFileName().equals(hasNestedForm.getNestedForm())).findFirst()
                        .ifPresent(modelSummary -> {
                            hasNestedForm.setNestedForm(modelSummary.getNewForm().get().getId());
                            updateNestedFormsModelProperties(formDefinition, (FieldDefinition) hasNestedForm,
                                    modelSummary.getOriginalForm().get());
                        });/*w w w  .  j  a v a2  s. c  o  m*/
            });

    formDefinition.getFields().stream().filter(fieldDefinition -> fieldDefinition instanceof IsCRUDDefinition)
            .map(fieldDefinition -> (IsCRUDDefinition) fieldDefinition).forEach(crudDefinition -> {
                // update Creation Form
                updateCrudDefinitionForms(modelForms,
                        modelSummary -> modelSummary.getOriginalForm().getPath().getFileName()
                                .equals(crudDefinition.getCreationForm()),
                        modelSummary -> crudDefinition
                                .setCreationForm(modelSummary.getNewForm().get().getId()));

                // update Edition Form
                updateCrudDefinitionForms(modelForms,
                        modelSummary -> modelSummary.getOriginalForm().getPath().getFileName()
                                .equals(crudDefinition.getEditionForm()),
                        modelSummary -> crudDefinition.setEditionForm(modelSummary.getNewForm().get().getId()));

                // update Table Columns Form
                updateCrudDefinitionForms(modelForms, modelSummary -> {
                    Field originalField = originalForm.getField(((FieldDefinition) crudDefinition).getName());
                    return modelSummary.getOriginalForm().getPath().getFileName()
                            .equals(StringUtils.defaultIfBlank(originalField.getTableSubform(),
                                    originalField.getDefaultSubform()));
                }, modelSummary -> {
                    FormDefinition modelFormDefinition = modelSummary.getNewForm().get();

                    modelFormDefinition.getFields().forEach(fieldDefinition -> {
                        if (!(fieldDefinition instanceof EmbedsForm)) {
                            crudDefinition.getColumnMetas().add(new TableColumnMeta(fieldDefinition.getLabel(),
                                    fieldDefinition.getBinding()));
                        }
                    });
                    updateNestedFormsModelProperties(formDefinition, (FieldDefinition) crudDefinition,
                            modelSummary.getOriginalForm().get());
                });
            });
}

From source file:org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.AbstractFieldAdapter.java

@Override
public void parseField(Field originalField, FormMigrationSummary formSummary, FormDefinition newFormDefinition,
        Consumer<LayoutComponent> layoutElementConsumer) {
    FieldDefinition fieldDefinition = getFieldDefinition(originalField);

    fieldDefinition.setId(String.valueOf(originalField.getId()));
    fieldDefinition.setName(originalField.getFieldName());
    fieldDefinition.setLabel(lookupI18nValue(originalField.getLabel()));
    fieldDefinition.setHelpMessage(lookupI18nValue(originalField.getTitle()));
    fieldDefinition.setStandaloneClassName(
            StringUtils.defaultIfBlank(originalField.getBag(), originalField.getFieldType().getFieldClass()));
    fieldDefinition.setReadOnly(originalField.getReadonly());
    fieldDefinition.setRequired(originalField.getFieldRequired());

    String binding = StringUtils.defaultString(
            StringUtils.defaultIfBlank(originalField.getInputBinding(), originalField.getOutputBinding()));

    if (!StringUtils.isEmpty(binding)) {
        if (binding.contains("/")) {
            binding = binding.substring(binding.indexOf("/") + 1);
        }/*  w w  w .  jav  a 2  s  . c  om*/

        ModelPropertyImpl property = new ModelPropertyImpl(binding, fieldDefinition.getFieldTypeInfo());
        newFormDefinition.getModel().getProperties().add(property);
    }

    fieldDefinition.setBinding(binding);

    if (fieldDefinition instanceof HasPlaceHolder) {
        ((HasPlaceHolder) fieldDefinition).setPlaceHolder(fieldDefinition.getLabel());
    }

    newFormDefinition.getFields().add(fieldDefinition);
    LayoutComponent component = new LayoutComponent(DRAGGABLE_TYPE);
    component.addProperty(FormLayoutComponent.FORM_ID, newFormDefinition.getId());
    component.addProperty(FormLayoutComponent.FIELD_ID, fieldDefinition.getId());

    layoutElementConsumer.accept(component);
}

From source file:org.kuali.coeus.propdev.impl.budget.core.ProposalBudgetView.java

protected void generatePessimisticLockMessages(ProposalBudgetForm form) {
    Document document = form.getBudget().getDevelopmentProposal().getDocument();
    Person user = GlobalVariables.getUserSession().getPerson();
    int budgetVersion = form.getBudget().getBudgetVersionNumber();
    for (PessimisticLock lock : document.getPessimisticLocks()) {
        if (!lock.isOwnedByUser(user) && getProposalBudgetLockService()
                .doesBudgetVersionMatchDescriptor(lock.getLockDescriptor(), budgetVersion)) {
            String lockDescriptor = StringUtils.defaultIfBlank(lock.getLockDescriptor(), "full");
            String lockOwner = lock.getOwnedByUser().getName();
            String lockTime = RiceConstants.getDefaultTimeFormat().format(lock.getGeneratedTimestamp());
            String lockDate = RiceConstants.getDefaultDateFormat().format(lock.getGeneratedTimestamp());

            if (!getParameterService().getParameterValueAsBoolean("KC-GEN", "All",
                    PessimisticLockConstants.ALLOW_CLEAR_PESSIMISTIC_LOCK_PARM)) {
                GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,
                        ERROR_TRANSACTIONAL_LOCKED, lockDescriptor, lockOwner, lockTime, lockDate);
            } else {
                GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,
                        KC_ERROR_TRANSACTIONAL_LOCKED, lockDescriptor, lockOwner, lockTime, lockDate,
                        lock.getId().toString());
            }// w w w.j a v  a  2  s . c  o m
        }
    }
}