本文整理汇总了Java中org.springframework.util.StringUtils.capitalize方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.capitalize方法的具体用法?Java StringUtils.capitalize怎么用?Java StringUtils.capitalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.capitalize方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateApplicationName
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Generate a suitable application name based on the specified name. If no suitable
* application name can be generated from the specified {@code name}, the
* {@link Env#fallbackApplicationName} is used instead.
* <p>
* No suitable application name can be generated if the name is {@code null} or if it
* contains an invalid character for a class identifier.
* @see Env#fallbackApplicationName
* @see Env#invalidApplicationNames
*/
public String generateApplicationName(String name) {
if (!StringUtils.hasText(name)) {
return env.fallbackApplicationName;
}
String text = splitCamelCase(name.trim());
// TODO: fix this
String result = unsplitWords(text);
if (!result.endsWith("Application")) {
result = result + "Application";
}
String candidate = StringUtils.capitalize(result);
if (hasInvalidChar(candidate)
|| env.invalidApplicationNames.contains(candidate)) {
return env.fallbackApplicationName;
}
else {
return candidate;
}
}
示例2: replaceVariables
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
public String replaceVariables(String message, Entity self, Entity target) {
if (message == null) {
return null;
}
if (self.equals(target)) {
message = message.replace("%self%", self.getName());
message = message.replace("%target%", target.getName());
} else {
message = message.replace("%self%", self.getName());
message = message.replace("%target%", (target == null ? "NULL" : target.getName()));
}
message = message.replace("%him%", "him");
message = message.replace("%selfpos%", self.getName() + "'s");
message = message.replace("%targetpos%", (target == null ? "NULL" : target.getName()) + "'s");
message = message.replace("%his%", "his");
message = message.replace("%he%", "he");
message = message.replace("%himself%", "himself");
message = message.replace("%hispos%", "his");
return StringUtils.capitalize(message);
}
示例3: canRead
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Override
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
if (target == null) {
return false;
}
Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass());
if (type.isArray()) {
return false;
}
if (this.member instanceof Method) {
Method method = (Method) this.member;
String getterName = "get" + StringUtils.capitalize(name);
if (getterName.equals(method.getName())) {
return true;
}
getterName = "is" + StringUtils.capitalize(name);
return getterName.equals(method.getName());
}
else {
Field field = (Field) this.member;
return field.getName().equals(name);
}
}
示例4: toCamelCaseFormat
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Return a camel cased representation of this instance.
*/
public String toCamelCaseFormat() {
String[] tokens = this.property.split("\\-|\\.");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < tokens.length; i++) {
String part = tokens[i];
if (i > 0) {
part = StringUtils.capitalize(part);
}
sb.append(part);
}
return sb.toString();
}
示例5: invokeSetter
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* 调用Setter方法.
*
* @param propertyType
* 用于查找Setter方法,为空时使用value的Class替代.
*/
public static void invokeSetter(Object obj, String propertyName,
Object value, Class<?> propertyType) {
Class<?> type = propertyType != null ? propertyType : value.getClass();
String setterMethodName = "set" + StringUtils.capitalize(propertyName);
invokeMethod(obj, setterMethodName, new Class[] { type },
new Object[] { value });
}
示例6: getBeanClassName
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Override
protected String getBeanClassName(Element element) {
String elementName
= Conventions.attributeNameToPropertyName(
element.getLocalName());
return RedissonNamespaceParserSupport.IMPL_CLASS_PATH_PREFIX
+ StringUtils.capitalize(elementName);
}
示例7: findSetter
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
private AnnotatedMethod findSetter(BeanDescription beanDesc,
BeanPropertyWriter writer) {
String name = "set" + StringUtils.capitalize(writer.getName());
Class<?> type = writer.getPropertyType();
AnnotatedMethod setter = beanDesc.findMethod(name, new Class<?>[] { type });
// The enabled property of endpoints returns a boolean primitive but is set
// using a Boolean class
if (setter == null && type.equals(Boolean.TYPE)) {
setter = beanDesc.findMethod(name, new Class<?>[] { Boolean.class });
}
return setter;
}
示例8: getPropertyMethodSuffixes
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Return the method suffixes for a given property name. The default implementation
* uses JavaBean conventions with additional support for properties of the form 'xY'
* where the method 'getXY()' is used in preference to the JavaBean convention of
* 'getxY()'.
*/
protected String[] getPropertyMethodSuffixes(String propertyName) {
String suffix = getPropertyMethodSuffix(propertyName);
if (suffix.length() > 0 && Character.isUpperCase(suffix.charAt(0))) {
return new String[] { suffix };
}
return new String[] { suffix, StringUtils.capitalize(suffix) };
}
示例9: getPropertyMethodSuffix
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Return the method suffix for a given property name. The default implementation
* uses JavaBean conventions.
*/
protected String getPropertyMethodSuffix(String propertyName) {
if (propertyName.length() > 1 && Character.isUpperCase(propertyName.charAt(1))) {
return propertyName;
}
return StringUtils.capitalize(propertyName);
}
示例10: invokeGetter
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* 调用Getter方法.
*/
public static Object invokeGetter(Object obj, String propertyName) {
String getterMethodName = "get" + StringUtils.capitalize(propertyName);
return invokeMethod(obj, getterMethodName, new Class[] {},
new Object[] {});
}
示例11: getResourceKey
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Return composite resource key for specified extension key.
* If extension has no resource or extension with specified key doesn't exist the method
* returns {@code null}.
*
* @param extensionKey the extension key
* @param extensionResourceVersion ignored in current implementation
* @return composite resource key or {@code null} if not found
*/
@Override
public LepResourceKey getResourceKey(LepKey extensionKey, Version extensionResourceVersion) {
if (extensionKey == null) {
return null;
}
LepKey groupKey = extensionKey.getGroupKey();
String extensionKeyId = extensionKey.getId();
String extensionName;
String[] groupSegments;
if (groupKey == null) {
groupSegments = EMPTY_GROUP_SEGMENTS;
extensionName = extensionKeyId;
} else {
groupSegments = groupKey.getId().split(EXTENSION_KEY_SEPARATOR_REGEXP);
// remove group from id
extensionName = extensionKeyId.replace(groupKey.getId(), "");
if (extensionName.startsWith(XmLepConstants.EXTENSION_KEY_SEPARATOR)) {
extensionName = extensionName.substring(XmLepConstants.EXTENSION_KEY_SEPARATOR.length());
}
}
// change script name: capitalize first character & add script type extension
String scriptName = extensionName.replaceAll(EXTENSION_KEY_SEPARATOR_REGEXP, SCRIPT_NAME_SEPARATOR_REGEXP);
scriptName = StringUtils.capitalize(scriptName);
String urlPath = URL_DELIMITER;
if (groupSegments.length > 0) {
urlPath += String.join(URL_DELIMITER, groupSegments) + URL_DELIMITER;
}
urlPath += scriptName + SCRIPT_EXTENSION_SEPARATOR + SCRIPT_EXTENSION_GROOVY;
// TODO if possible add check that returned resourceKey contains resources (for speed up executor reaction)
// Check example : return isResourceExists(resourceKey) ? resourceKey : null;
UrlLepResourceKey urlLepResourceKey = UrlLepResourceKey.valueOfUrlResourcePath(urlPath);
if (extensionResourceVersion == null) {
log.debug("LEP extension key: '{}' translated to --> composite resource key: '{}'", extensionKey, urlLepResourceKey);
} else {
log.debug("LEP extension 'key: {}, v{}' translated to --> composite resource key: '{}'", extensionKey,
extensionResourceVersion, urlLepResourceKey);
}
return urlLepResourceKey;
}
示例12: getResourceKey
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Return composite resource key for specified extension key.
* If extension has no resource or extension with specified key doesn't exist the method
* returns {@code null}.
*
* @param extensionKey the extension key
* @param extensionResourceVersion ignored in current implementation
* @return composite resource key or {@code null} if not found
*/
@Override
public LepResourceKey getResourceKey(LepKey extensionKey, Version extensionResourceVersion) {
if (extensionKey == null) {
return null;
}
LepKey groupKey = extensionKey.getGroupKey();
String extensionKeyId = extensionKey.getId();
String extensionName;
String[] groupSegments;
if (groupKey == null) {
groupSegments = EMPTY_GROUP_SEGMENTS;
extensionName = extensionKeyId;
} else {
groupSegments = groupKey.getId().split(EXTENSION_KEY_SEPARATOR_REGEXP);
// remove group from id
extensionName = extensionKeyId.replace(groupKey.getId(), "");
if (extensionName.startsWith(EXTENSION_KEY_SEPARATOR)) {
extensionName = extensionName.substring(EXTENSION_KEY_SEPARATOR.length());
}
}
// change script name: capitalize first character & add script type extension
String scriptName = extensionName.replaceAll(EXTENSION_KEY_SEPARATOR_REGEXP, SCRIPT_NAME_SEPARATOR_REGEXP);
scriptName = StringUtils.capitalize(scriptName);
String urlPath = URL_DELIMITER;
if (groupSegments.length > 0) {
urlPath += String.join(URL_DELIMITER, groupSegments) + URL_DELIMITER;
}
urlPath += scriptName + SCRIPT_EXTENSION_SEPARATOR + XmLepConstants.SCRIPT_EXTENSION_GROOVY;
// TODO if possible add check that returned resourceKey contains resources (for speed up executor reaction)
// Check example : return isResourceExists(resourceKey) ? resourceKey : null;
UrlLepResourceKey urlLepResourceKey = UrlLepResourceKey.valueOfUrlResourcePath(urlPath);
if (extensionResourceVersion == null) {
log.debug("LEP extension key: '{}' translated to --> composite resource key: '{}'", extensionKey, urlLepResourceKey);
} else {
log.debug("LEP extension 'key: {}, v{}' translated to --> composite resource key: '{}'", extensionKey,
extensionResourceVersion, urlLepResourceKey);
}
return urlLepResourceKey;
}
示例13: pretty
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
private String pretty(String type) {
return StringUtils.capitalize(type) + "s";
}
示例14: getAttributeName
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Return the JMX attribute name to use for the given JavaBeans property.
* <p>When using strict casing, a JavaBean property with a getter method
* such as {@code getFoo()} translates to an attribute called
* {@code Foo}. With strict casing disabled, {@code getFoo()}
* would translate to just {@code foo}.
* @param property the JavaBeans property descriptor
* @param useStrictCasing whether to use strict casing
* @return the JMX attribute name to use
*/
public static String getAttributeName(PropertyDescriptor property, boolean useStrictCasing) {
if (useStrictCasing) {
return StringUtils.capitalize(property.getName());
}
else {
return property.getName();
}
}