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

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

Introduction

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

Prototype

public static String capitalize(final String str) 

Source Link

Document

Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .

Usage

From source file:org.finra.dm.service.helper.DmHelper.java

/**
 * Validates the given instance definition. Generates an appropriate error message using the given name. The name specified is one of "master", "core", or
 * "task".//from w  w  w. j  a v a2s.  co  m
 *
 * @param name name of instance group
 * @param instanceDefinition the instance definition to validate
 *
 * @throws IllegalArgumentException when any validation error occurs
 */
private void validateInstanceDefinition(String name, InstanceDefinition instanceDefinition) {
    String capitalizedName = StringUtils.capitalize(name);

    Assert.isTrue(instanceDefinition.getInstanceCount() >= 1,
            "At least 1 " + name + " instance must be specified.");
    Assert.hasText(instanceDefinition.getInstanceType(),
            "An instance type for " + name + " instances must be specified.");

    if (instanceDefinition.getInstanceSpotPrice() != null) {
        Assert.isNull(instanceDefinition.getInstanceMaxSearchPrice(), capitalizedName
                + " instance max search price must not be specified when instance spot price is specified.");

        Assert.isTrue(instanceDefinition.getInstanceSpotPrice().compareTo(BigDecimal.ZERO) > 0,
                capitalizedName + " instance spot price must be greater than 0");
    }

    if (instanceDefinition.getInstanceMaxSearchPrice() != null) {
        Assert.isNull(instanceDefinition.getInstanceSpotPrice(), capitalizedName
                + " instance spot price must not be specified when max search price is specified.");

        Assert.isTrue(instanceDefinition.getInstanceMaxSearchPrice().compareTo(BigDecimal.ZERO) > 0,
                capitalizedName + " instance max search price must be greater than 0");

        if (instanceDefinition.getInstanceOnDemandThreshold() != null) {
            Assert.isTrue(instanceDefinition.getInstanceOnDemandThreshold().compareTo(BigDecimal.ZERO) > 0,
                    capitalizedName + " instance on-demand threshold must be greater than 0");
        }
    } else {
        Assert.isNull(instanceDefinition.getInstanceOnDemandThreshold(), capitalizedName
                + " instance on-demand threshold must not be specified when instance max search price is not specified.");
    }
}

From source file:org.finra.herd.service.helper.AlternateKeyHelper.java

/**
 * Validates and returns a trimmed alternate key parameter value.
 *
 * @param indefiniteArticle the indefinite article to use with the specified parameter name
 * @param parameterName the alternate key parameter name
 * @param parameterValue the alternate key parameter value
 *
 * @return the trimmed alternate key parameter value
 * @throws IllegalArgumentException if alternate key parameter is missing or not valid
 */// w ww . j  ava 2s. c om
public String validateStringParameter(String indefiniteArticle, String parameterName, String parameterValue)
        throws IllegalArgumentException {
    Assert.hasText(parameterValue, String.format("%s %s must be specified.", indefiniteArticle, parameterName));
    Assert.doesNotContain(parameterValue, "/", String.format("%s can not contain a forward slash character.",
            StringUtils.capitalize(parameterName)));
    return parameterValue.trim();
}

From source file:org.finra.herd.service.helper.EmrClusterDefinitionHelper.java

/**
 * Validates the given instance definition. Generates an appropriate error message using the given name. The name specified is one of "master", "core", or
 * "task"./*from   w ww  . ja  v  a 2  s  . c  o  m*/
 *
 * @param name name of instance group
 * @param instanceDefinition the instance definition to validate
 * @param minimumInstanceCount The minimum instance count.
 *
 * @throws IllegalArgumentException when any validation error occurs
 */
private void validateInstanceDefinition(String name, InstanceDefinition instanceDefinition,
        Integer minimumInstanceCount) {
    String capitalizedName = StringUtils.capitalize(name);

    Assert.isTrue(instanceDefinition.getInstanceCount() >= minimumInstanceCount,
            String.format("At least %d %s instance must be specified.", minimumInstanceCount, name));
    Assert.hasText(instanceDefinition.getInstanceType(),
            "An instance type for " + name + " instances must be specified.");

    if (instanceDefinition.getInstanceSpotPrice() != null) {
        Assert.isNull(instanceDefinition.getInstanceMaxSearchPrice(), capitalizedName
                + " instance max search price must not be specified when instance spot price is specified.");

        Assert.isTrue(instanceDefinition.getInstanceSpotPrice().compareTo(BigDecimal.ZERO) > 0,
                capitalizedName + " instance spot price must be greater than 0");
    }

    if (instanceDefinition.getInstanceMaxSearchPrice() != null) {
        Assert.isNull(instanceDefinition.getInstanceSpotPrice(), capitalizedName
                + " instance spot price must not be specified when max search price is specified.");

        Assert.isTrue(instanceDefinition.getInstanceMaxSearchPrice().compareTo(BigDecimal.ZERO) > 0,
                capitalizedName + " instance max search price must be greater than 0");

        if (instanceDefinition.getInstanceOnDemandThreshold() != null) {
            Assert.isTrue(instanceDefinition.getInstanceOnDemandThreshold().compareTo(BigDecimal.ZERO) > 0,
                    capitalizedName + " instance on-demand threshold must be greater than 0");
        }
    } else {
        Assert.isNull(instanceDefinition.getInstanceOnDemandThreshold(), capitalizedName
                + " instance on-demand threshold must not be specified when instance max search price is not specified.");
    }
}

From source file:org.finra.herd.service.helper.NamespaceIamRoleAuthorizationHelperTest.java

@Test
public void checkPermissionsAssertRoleNameIsCaseInsensitive() {
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    String iamRoleName1 = "iamRoleName1";
    String iamRoleName2 = "iamRoleName2";
    Collection<String> requestedIamRoleNames = Arrays.asList(StringUtils.capitalize(iamRoleName1),
            StringUtils.capitalize(iamRoleName2));

    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setIamRoleName(iamRoleName1);
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setIamRoleName(iamRoleName2);
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);

    when(configurationHelper.getBooleanProperty(any())).thenReturn(true);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any()))
            .thenReturn(namespaceIamRoleAuthorizationEntities);

    namespaceIamRoleAuthorizationHelper.checkPermissions(expectedNamespaceEntity, requestedIamRoleNames);

    verify(configurationHelper).getBooleanProperty(ConfigurationValue.NAMESPACE_IAM_ROLE_AUTHORIZATION_ENABLED);
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verifyNoMoreInteractions(configurationHelper, namespaceIamRoleAuthorizationDao);
}

From source file:org.flowr.utils.NamingStrategy.java

public static String propertyAccessor(String... names) {
    return "get" + StringUtils.capitalize(className(names)); //$NON-NLS-1$
}

From source file:org.flowr.utils.NamingStrategy.java

private static String camelCase(String name, String separatorChars, String space) {
    String[] tokens = StringUtils.splitPreserveAllTokens(name, separatorChars, 0);
    StringBuilder b = new StringBuilder();
    for (String word : tokens) {
        if (space != null && b.length() > 0) {
            b.append(space);/*from  ww w . j  ava2 s .c  o m*/
        }
        b.append(StringUtils.capitalize(word));
    }
    return b.toString();
}

From source file:org.gbif.dwc.record.DarwinCoreTaxon.java

public String buildHigherClassification(Character lowestRank) {
    StringBuilder buf = new StringBuilder();
    if (kingdom != null) {
        buf.append(StringUtils.capitalize(kingdom.toLowerCase()));
        buf.append(CLASSIFICATION_DELIMITER);
    }/*from ww w .  j  av  a 2 s  .com*/
    if (lowestRank == null || lowestRank != 'k') {
        if (phylum != null) {
            buf.append(StringUtils.capitalize(phylum.toLowerCase()));
            buf.append(CLASSIFICATION_DELIMITER);
        }
        if (lowestRank == null || lowestRank != 'p') {
            if (classs != null) {
                buf.append(StringUtils.capitalize(classs.toLowerCase()));
                buf.append(CLASSIFICATION_DELIMITER);
            }
            if (lowestRank == null || lowestRank != 'c') {
                if (order != null) {
                    buf.append(StringUtils.capitalize(order.toLowerCase()));
                    buf.append(CLASSIFICATION_DELIMITER);
                }
                if (lowestRank == null || lowestRank != 'o') {
                    if (family != null) {
                        buf.append(StringUtils.capitalize(family.toLowerCase()));
                        buf.append(CLASSIFICATION_DELIMITER);
                    }
                    if (lowestRank == null || lowestRank != 'f') {
                        if (genus != null) {
                            buf.append(StringUtils.capitalize(genus.toLowerCase()));
                            buf.append(CLASSIFICATION_DELIMITER);
                        }
                        if (lowestRank == null || lowestRank != 'g') {
                            if (subgenus != null) {
                                buf.append(StringUtils.capitalize(subgenus.toLowerCase()));
                                buf.append(CLASSIFICATION_DELIMITER);
                            }
                        }
                    }
                }
            }
        }
    }

    if (buf.length() > CLASSIFICATION_DELIMITER.length()) {
        buf.delete(buf.length() - CLASSIFICATION_DELIMITER.length(), buf.length());
    }
    return buf.toString();
}

From source file:org.gbif.dwc.record.DarwinCoreTaxon.java

private String getPropertyName(Term prop) {
    String propName = StringUtils.capitalize(prop.simpleName());
    if (propName.equalsIgnoreCase("Class")) {
        propName = "Classs";
    }//from w  w  w .  j  a v a2 s  .  c o m
    return propName;
}

From source file:org.gbif.ipt.action.manage.MappingAction.java

/**
 * Update resource core type. This must be done every time the resource's core type mapping is being modified, or
 * deleted. If it is the 1st mapping of the core type, the core type won't have been set yet. Only if 1 or more
 * mapped fields were saved, can we consider the mapping to have been legitimate. Furthermore, if the
 * core type mapping is being deleted, then the resource must reset its core type to null.
 * //from ww  w . j  a  v a  2  s  .  com
 * @param mapping ExtensionMapping
 * @param mappedFields the number of mapped fields in the mapping - set to 0 if the mapping is to be deleted
 */
void updateResourceCoreType(ExtensionMapping mapping, int mappedFields) {
    // proceed only if we're dealing with the core type mapping
    if (mapping.isCore()) {
        // must be 1 or more mapped fields for mapping to be legitimate
        if (mappedFields > 0) {
            // set resource core type, based on core extension's coreRowType
            String coreRowType = StringUtils.trimToNull(mapping.getExtension().getRowType());
            if (Constants.DWC_ROWTYPE_TAXON.equalsIgnoreCase(coreRowType)) {
                resource.setCoreType(StringUtils.capitalize(CoreRowType.CHECKLIST.toString()));
            } else if (Constants.DWC_ROWTYPE_OCCURRENCE.equalsIgnoreCase(coreRowType)) {
                resource.setCoreType(StringUtils.capitalize(CoreRowType.OCCURRENCE.toString()));
            } else {
                resource.setCoreType(StringUtils.capitalize(CoreRowType.OTHER.toString()));
            }
        }
        // otherwise, reset core type!
        else {
            resource.setCoreType(null);
        }
    }
}

From source file:org.gbif.ipt.model.Resource.java

/**
 * At first the core type can be set during resource creation or on the basic metadata page. But once
 * a core mapping has been done, it is derived from the core mapping.
 *
 * @return the core type.//  www  .ja  va  2 s.c  o  m
 */
@Nullable
public String getCoreType() {
    String coreRowType = getCoreRowType();
    if (coreRowType != null) {
        if (coreRowType.equalsIgnoreCase(Constants.DWC_ROWTYPE_TAXON)) {
            coreType = StringUtils.capitalize(CoreRowType.CHECKLIST.toString());
        } else if (coreRowType.equalsIgnoreCase(Constants.DWC_ROWTYPE_OCCURRENCE)) {
            coreType = StringUtils.capitalize(CoreRowType.OCCURRENCE.toString());
        } else if (coreRowType.equalsIgnoreCase(Constants.DWC_ROWTYPE_EVENT)) {
            coreType = StringUtils.capitalize(CoreRowType.SAMPLINGEVENT.toString());
        } else {
            coreType = StringUtils.capitalize(CoreRowType.OTHER.toString());
        }
    }
    return coreType;
}