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

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

Introduction

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

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

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

Usage

From source file:com.gst.portfolio.tax.domain.TaxComponent.java

public Map<String, Object> update(final JsonCommand command) {
    final Map<String, Object> changes = new HashMap<>();

    if (command.isChangeInStringParameterNamed(TaxApiConstants.nameParamName, this.name)) {
        final String newValue = command.stringValueOfParameterNamed(TaxApiConstants.nameParamName);
        changes.put(TaxApiConstants.nameParamName, newValue);
        this.name = StringUtils.defaultIfEmpty(newValue, null);
    }/*from  w  w  w . ja v a2  s .c om*/

    if (command.isChangeInBigDecimalParameterNamed(TaxApiConstants.percentageParamName, this.percentage)) {
        final BigDecimal newValue = command
                .bigDecimalValueOfParameterNamed(TaxApiConstants.percentageParamName);
        changes.put(TaxApiConstants.percentageParamName, newValue);

        LocalDate oldStartDate = new LocalDate(this.startDate);
        updateStartDate(command, changes, true);
        LocalDate newStartDate = new LocalDate(this.startDate);

        TaxComponentHistory history = TaxComponentHistory.createTaxComponentHistory(this.percentage,
                oldStartDate, newStartDate);
        this.taxComponentHistories.add(history);
        this.percentage = newValue;

    }

    return changes;
}

From source file:com.opengamma.component.tool.AbstractTool.java

/**
 * Initializes and runs the tool from standard command-line arguments.
 * <p>/*from  w w w.  j a v  a2 s. co  m*/
 * The base class defined three options:<br />
 * c/config - the config file, mandatory unless default specified<br />
 * l/logback - the logback configuration, default tool-logback.xml<br />
 * h/help - prints the help tool<br />
 *
 * @param args the command-line arguments, not null
 * @param defaultConfigResource the default configuration resource location, null if mandatory on command line
 * @param defaultLogbackResource the default logback resource, null to use tool-logback.xml as the default
 * @param toolContextClass the type of tool context to create, should match the generic type argument
 * @return true if successful, false otherwise
 */
public boolean initAndRun(final String[] args, final String defaultConfigResource,
        final String defaultLogbackResource, final Class<? extends T> toolContextClass) {
    ArgumentChecker.notNull(args, "args");

    final Options options = createOptions(defaultConfigResource == null);
    final CommandLineParser parser = new PosixParser();
    CommandLine line;
    try {
        line = parser.parse(options, args);
    } catch (final ParseException e) {
        usage(options);
        return false;
    }
    _commandLine = line;
    if (line.hasOption(HELP_OPTION)) {
        usage(options);
        return true;
    }
    String logbackResource = line.getOptionValue(LOGBACK_RESOURCE_OPTION);
    logbackResource = StringUtils.defaultIfEmpty(logbackResource, ToolUtils.getDefaultLogbackConfiguration());
    String[] configResources = line.getOptionValues(CONFIG_RESOURCE_OPTION);
    if (configResources == null || configResources.length == 0) {
        configResources = new String[] { defaultConfigResource };
    }
    return init(logbackResource) && run(configResources, toolContextClass);
}

From source file:de.thischwa.pmcms.view.context.object.SiteLinkTool.java

/**
 * Set the link to the committed level.//from  w ww .j  a  v  a2 s. com
 * 
 * @param levelLinkTo
 * @return SiteLinkTool
 */
public SiteLinkTool getLevel(final Level levelLinkTo) {
    if (levelLinkTo == null)
        throw new FatalException("Link to level shouldn't be null!");
    if (isExportView) {
        setResource(PathTool.getURLRelativePathToLevel(currentLevel, levelLinkTo)
                .concat(StringUtils.defaultIfEmpty(welcomePageName, "PAGE_NOT_EXISTS")));
    } else {
        if (PoInfo.getRootPage(levelLinkTo) != null)
            setPageForPreview(PoInfo.getRootPage(levelLinkTo));
    }
    return this;
}

From source file:ch.admin.suis.msghandler.config.Outbox.java

@Override
public String toString() {
    return MessageFormat.format("name: {0}; type of the outgoing messages: {1}; sedex ID of the sender: {2};",
            //        StringUtils.defaultIfEmpty(getDirectory(), ClientCommons.NOT_SPECIFIED),
            getDirectory(), null == type ? ClientCommons.NOT_SPECIFIED : type.toString(),
            StringUtils.defaultIfEmpty(getSedexId(), ClientCommons.NOT_SPECIFIED));
}

From source file:com.gst.organisation.staff.domain.Staff.java

private Staff(final Office staffOffice, final String firstname, final String lastname, final String externalId,
        final String mobileNo, final boolean isLoanOfficer, final Boolean isActive,
        final LocalDate joiningDate) {
    this.office = staffOffice;
    this.firstname = StringUtils.defaultIfEmpty(firstname, null);
    this.lastname = StringUtils.defaultIfEmpty(lastname, null);
    this.externalId = StringUtils.defaultIfEmpty(externalId, null);
    this.mobileNo = StringUtils.defaultIfEmpty(mobileNo, null);
    this.loanOfficer = isLoanOfficer;
    this.active = (isActive == null) ? true : isActive;
    deriveDisplayName(firstname);/*from  ww w  .j  a  v a 2s .  c o  m*/
    if (joiningDate != null) {
        this.joiningDate = joiningDate.toDateTimeAtStartOfDay().toDate();
    }
}

From source file:com.hand.hap.mybatis.util.OGNL.java

/**
 * FOR INTERNAL USE ONLY//from   ww  w . j  ava 2  s. c o m
 * 
 * @param parameter
 * @return
 */
public static String getOrderByClause_TL(Object parameter) {
    if (parameter == null) {
        return null;
    }
    StringBuilder sb = new StringBuilder(64);
    if (parameter instanceof BaseDTO) {
        String sortName = ((BaseDTO) parameter).getSortname();
        Field[] ids = DTOClassInfo.getIdFields(parameter.getClass());
        if (StringUtil.isNotEmpty(sortName)) {
            if (!COL_PATTERN.matcher(sortName).matches()) {
                throw new RuntimeException("Invalid sortname:" + sortName);
            }
            String order = ((BaseDTO) parameter).getSortorder();
            if (!("ASC".equalsIgnoreCase(order) || "DESC".equalsIgnoreCase(order) || order == null)) {
                throw new RuntimeException("Invalid sortorder:" + order);
            }
            String columnName = unCamel(sortName);
            Field[] mlfs = DTOClassInfo.getMultiLanguageFields(parameter.getClass());
            for (Field f : mlfs) {
                if (f.getName().equals(columnName)) {
                    if (f.getAnnotation(MultiLanguageField.class) == null) {
                        sb.append("b.");
                    } else {
                        sb.append("t.");
                    }
                    break;
                }
            }

            sb.append(columnName).append(" ");
            sb.append(StringUtils.defaultIfEmpty(order, "ASC"));

            if (ids.length > 0 && !ids[0].getName().equals(sortName)) {
                sb.append(",b.").append(DTOClassInfo.getColumnName(ids[0])).append(" ASC");
            }
        } else {
            if (ids.length > 0) {
                sb.append("b.").append(DTOClassInfo.getColumnName(ids[0])).append(" ASC");
            }
        }
    }
    return StringUtils.trimToNull(sb.toString());
}

From source file:com.adobe.acs.samples.models.SampleSlingModel.java

/**
 * This getter wraps business logic around how an logic data point (title) is represented for this resource.
 *
 * @return The Page Title if exists, with fallback to the jcr:title
 *///from   w w w  .  j  ava  2  s  .  c om
public String getTitle() {
    return StringUtils.defaultIfEmpty(pageTitle, title);
}

From source file:info.magnolia.link.Link.java

public String getExtension() {
    try {/*from   www.ja  v a  2s . c o m*/
        if (StringUtils.isEmpty(this.extension) && this.getJCRNode() != null
                && this.getJCRNode().isNodeType(NodeTypes.Resource.NAME)) {
            File binary = new File(jcrNode);
            extension = binary.getExtension();
        }
    } catch (RepositoryException e) {
        //Just return extension if already set, default if not.
    }
    return StringUtils.defaultIfEmpty(this.extension,
            Components.getComponent(ServerConfiguration.class).getDefaultExtension());
}

From source file:com.bstek.dorado.config.xml.ObjectParser.java

/**
 * ??/* w  w w .  j a v  a2  s. c  om*/
 * 
 * @param definition
 *            ?
 * @param element
 *            ?
 * @param context
 *            ?
 * @throws Exception
 */
protected void initDefinition(ObjectDefinition definition, Element element, ParseContext context)
        throws Exception {
    definition.setResource(context.getResource());

    String realImpl = StringUtils.defaultIfEmpty(element.getAttribute(XmlConstants.ATTRIBUTE_IMPL), impl);
    String parent = element.getAttribute(XmlConstants.ATTRIBUTE_PARENT);
    if (StringUtils.isNotEmpty(realImpl)) {
        /*
         * if (StringUtils.isNotEmpty(parent)) { throw new
         * XmlParseException("[" + XmlConstants.ATTRIBUTE_PARENT +
         * "] attribute should be empty", element, context); }
         */
        ClassUtils.forName(realImpl);
        definition.setImpl(realImpl);
    }

    if (StringUtils.isNotEmpty(parent)) {
        if (!inheritable) {
            throw new XmlParseException("[" + XmlConstants.ATTRIBUTE_PARENT + "] attribute not supported.",
                    element, context);
        }

        DefinitionReference<? extends Definition>[] parentReferences = getParentDefinitionReferences(parent,
                context);
        if (parentReferences != null) {
            definition.setParentReferences(parentReferences);
        }
    }

    if (scopable) {
        String scope = element.getAttribute(XmlConstants.ATTRIBUTE_SCOPE);
        if (StringUtils.isEmpty(scope)) {
            definition.setScope(getDefaultScope());
        } else {
            definition.setScope(Scope.valueOf(scope));
        }
    }

    Map<String, Object> properties = parseProperties(element, context);
    definition.setProperties(properties);

    List<?> results = dispatchChildElements(element, context);
    if (results != null) {
        for (Object result : results) {
            if (result instanceof DefinitionInitOperation) {
                ((DefinitionInitOperation) result).execute(definition, null);
            } else if (result instanceof Operation) {
                definition.addInitOperation((Operation) result);
            }
        }
    }
}

From source file:com.opengamma.component.tool.AbstractComponentTool.java

/**
 * Initializes and runs the tool from standard command-line arguments.
 * <p>// w  w  w .jav a 2s .c  o  m
 * The base class defined three options:<br />
 * c/component server URI - the component server URI, mandatory<br />
 * l/logback - the logback configuration, default tool-logback.xml<br />
 * h/help - prints the help tool<br />
 * 
 * @param args the command-line arguments, not null
 * @param defaultLogbackResource the default logback resource, null to use tool-logback.xml as the default
 * @return true if successful, false otherwise
 */
public boolean initAndRun(String[] args, String defaultLogbackResource) {
    ArgumentChecker.notNull(args, "args");

    Options options = createOptions();
    CommandLineParser parser = new PosixParser();
    CommandLine line;
    try {
        line = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        return false;
    }
    _commandLine = line;
    if (line.hasOption(HELP_OPTION)) {
        usage(options);
        return true;
    }
    String logbackResource = line.getOptionValue(LOGBACK_RESOURCE_OPTION);
    logbackResource = StringUtils.defaultIfEmpty(logbackResource, getDefaultLogbackConfiguration());
    String componentServerUri = line.getOptionValue(COMPONENT_SERVER_URI_OPTION);
    return init(logbackResource) && run(componentServerUri);
}