Java Code Examples for org.springframework.util.StringUtils#uncapitalize()

The following examples show how to use org.springframework.util.StringUtils#uncapitalize() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private String getFieldName( Method method )
{
    String name;

    String[] getters = new String[]{
        "is", "has", "get"
    };

    name = method.getName();

    for ( String getter : getters )
    {
        if ( name.startsWith( getter ) )
        {
            name = name.substring( getter.length() );
        }
    }

    return StringUtils.uncapitalize( name );
}
 
Example 2
/**
 * Constructor.
 * @param information type information about the underlying entity type.
 * @param datastoreMappingContext a mapping context used to get metadata for related
 *     persistent entities.
 */
public DatastorePersistentEntityImpl(TypeInformation<T> information,
		DatastoreMappingContext datastoreMappingContext) {
	super(information);

	Class<?> rawType = information.getType();

	this.datastoreMappingContext = datastoreMappingContext;
	this.context = new StandardEvaluationContext();
	this.kind = findAnnotation(Entity.class);
	this.discriminatorField = findAnnotation(DiscriminatorField.class);
	this.discriminatorValue = findAnnotation(DiscriminatorValue.class);
	this.classBasedKindName = this.hasTableName() ? this.kind.name()
			: StringUtils.uncapitalize(rawType.getSimpleName());
	this.kindNameExpression = detectExpression();
}
 
Example 3
@Override
public String tableName() {
	if (this.tableName == null) {
		if (this.hasAnnotatedTableName()) {
			try {
				this.tableName = validateTableName(
						(this.tableNameExpression != null)
								? this.tableNameExpression.getValue(this.context, String.class)
								: this.table.name());
			}
			catch (RuntimeException ex) {
				throw new SpannerDataException(
						"Error getting table name for " + getType().getSimpleName(),
						ex);
			}
		}
		else {
			this.tableName = StringUtils.uncapitalize(this.rawType.getSimpleName());
		}
	}
	return this.tableName;
}
 
Example 4
/**
 * Map setter method call based on getter method names.
 * @param methodName
 * @return
 */
private String getMethodCall(String methodName) {
    if (methodName.startsWith("get")) {
        return StringUtils.uncapitalize(methodName.substring(3));
    } else if (methodName.startsWith("is")) {
        return StringUtils.uncapitalize(methodName.substring(2));
    }

    return methodName;
}
 
Example 5
Source Project: spring-analysis-note   File: ModelMapTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testAddMap() throws Exception {
	Map<String, String> map = new HashMap<>();
	map.put("one", "one-value");
	map.put("two", "two-value");
	ModelMap model = new ModelMap();
	model.addAttribute(map);
	assertEquals(1, model.size());
	String key = StringUtils.uncapitalize(ClassUtils.getShortName(map.getClass()));
	assertTrue(model.containsKey(key));
}
 
Example 6
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry){
    Class beanClass = ActivemqOfflineInfoHelper.class;
    RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
    String beanName = StringUtils.uncapitalize(beanClass.getSimpleName());
    //在这里可以拿到所有注解的信息,可以根据不同注解来返回不同的class,从而达到开启不同功能的目的
    //通过这种方式可以自定义beanName
    registry.registerBeanDefinition(beanName, beanDefinition);
}
 
Example 7
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry){
    Class beanClass = CustomOfflineInfoHelper.class;
    RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
    String beanName = StringUtils.uncapitalize(beanClass.getSimpleName());
    //在这里可以拿到所有注解的信息,可以根据不同注解来返回不同的class,从而达到开启不同功能的目的
    //通过这种方式可以自定义beanName
    registry.registerBeanDefinition(beanName, beanDefinition);
}
 
Example 8
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry){
    Class beanClass = RabbitmqOfflineInfoHelper.class;
    RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
    String beanName = StringUtils.uncapitalize(beanClass.getSimpleName());
    //在这里可以拿到所有注解的信息,可以根据不同注解来返回不同的class,从而达到开启不同功能的目的
    //通过这种方式可以自定义beanName
    registry.registerBeanDefinition(beanName, beanDefinition);
}
 
Example 9
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry){
    Class beanClass = RocketmqOfflineInfoHelper.class;
    RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
    String beanName = StringUtils.uncapitalize(beanClass.getSimpleName());
    //在这里可以拿到所有注解的信息,可以根据不同注解来返回不同的class,从而达到开启不同功能的目的
    //通过这种方式可以自定义beanName
    registry.registerBeanDefinition(beanName, beanDefinition);
}
 
Example 10
private Link fullyQualifiedLink(URI baseUri, ContentStoreInfo store, Object id, String fieldName) {
	LinkBuilder builder = BasicLinkBuilder.linkToCurrentMapping();

	if (baseUri != null) {
		builder = builder.slash(baseUri);
	}

	String property = StringUtils.uncapitalize(ContentStoreUtils.propertyName(fieldName));
	return builder.slash(ContentStoreUtils.storePath(store))
			.slash(id)
			.slash(property)
			.withRel(property);
}
 
Example 11
@Test
public void testAddMap() throws Exception {
	Map<String, String> map = new HashMap<String, String>();
	map.put("one", "one-value");
	map.put("two", "two-value");
	ModelMap model = new ModelMap();
	model.addAttribute(map);
	assertEquals(1, model.size());
	String key = StringUtils.uncapitalize(ClassUtils.getShortName(map.getClass()));
	assertTrue(model.containsKey(key));
}
 
Example 12
Source Project: sdn-rx   File: TestSequenceGenerator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String generateId(String primaryLabel, Object entity) {
	return StringUtils.uncapitalize(primaryLabel) + "-" + sequence.incrementAndGet();
}
 
Example 13
protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) {
	String beanClassName = interceptorDefinition.getBeanClassName();
	return (StringUtils.hasLength(beanClassName) ?
			StringUtils.uncapitalize(ClassUtils.getShortName(beanClassName)) : "");
}
 
Example 14
/**
 * Build Java configuration snippet for endpoints.
 * @param model
 * @param id
 * @param endpointType
 * @return
 */
public String getJavaConfig(T model, String id, String endpointType) {
    StringBuilder builder = new StringBuilder();

    String methodName;
    if (StringUtils.hasText(id)) {
        Matcher matcher = invalidMethodNamePattern.matcher(id);
        if (matcher.find()) {
            methodName = StringUtils.trimAllWhitespace(id.replaceAll("\\.", "").replaceAll("-", ""));
            builder.append(String.format("%n\[email protected](\"%s\")%n", id));
        } else {
            methodName = id;
            builder.append(String.format("%n\[email protected]%n"));
        }
    } else {
        methodName = StringUtils.uncapitalize(model.getClass().getSimpleName());
        builder.append(String.format("%n\[email protected]%n"));
    }

    builder.append(String.format("\tpublic %s %s() {%n", getSourceModelClass().getSimpleName(), methodName));

    builder.append(String.format("\t\treturn CitrusEndpoints.%s%n", endpointType));

    ReflectionUtils.doWithMethods(model.getClass(), method -> {
        Object object = ReflectionUtils.invokeMethod(method, model);
        if (object != null) {
            String methodCall = getMethodCall(method.getName());
            Optional<AbstractModelConverter.MethodCallDecorator> decorator = decorators.stream().filter(d -> d.supports(methodCall)).findAny();

            if (decorator.isPresent()) {
                if (decorator.get().allowMethodCall(object)) {
                    builder.append(decorator.get().decorate(methodName, String.format("\t\t\t.%s(%s)%n", decorator.get().decorateMethodName(), decorator.get().decorateArgument(object)), object));
                }
            } else if (object instanceof String) {
                builder.append(String.format("\t\t\t.%s(\"%s\")%n", methodCall, object));
            } else {
                builder.append(String.format("\t\t\t.%s(%s)%n", methodCall, object));
            }
        }
    }, method -> (method.getName().startsWith("get") || method.getName().startsWith("is"))
            && !method.getName().equals("getClass")
            && !method.getName().equals("getId")
            && method.getParameterCount() == 0);

    builder.append(String.format("\t\t\t.build();%n"));
    builder.append(String.format("\t}%n"));

    return builder.toString();
}
 
Example 15
Source Project: sos   File: EventRelProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getCollectionResourceRelFor(Class<?> type) {
	return StringUtils.uncapitalize(type.getSimpleName());
}
 
Example 16
protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) {
	return StringUtils.uncapitalize(ClassUtils.getShortName(interceptorDefinition.getBeanClassName()));
}
 
Example 17
/**
 * Build Java code snippet from given model and identifier.
 * @param model
 * @param id
 * @return
 */
public String getJavaConfig(T model, String id) {
    StringBuilder builder = new StringBuilder();

    String methodName;
    String beanId = StringUtils.hasText(id) ? id : StringUtils.uncapitalize(model.getClass().getSimpleName());
    Matcher matcher = invalidMethodNamePattern.matcher(beanId);
    if (matcher.find()) {
        methodName = StringUtils.trimAllWhitespace(beanId.replaceAll("\\.", "").replaceAll("-", ""));
        builder.append(String.format("%n\[email protected](\"%s\")%n", beanId));
    } else {
        methodName = beanId;
        builder.append(String.format("%n\[email protected]%n"));
    }

    builder.append(String.format("\tpublic %s %s() {%n", getSourceModelClass().getSimpleName(), methodName));

    builder.append(String.format("\t\t%s %s = new %s();%n", getSourceModelClass().getSimpleName(), methodName, getSourceModelClass().getSimpleName()));

    ReflectionUtils.doWithMethods(model.getClass(), method -> {
        Object object = ReflectionUtils.invokeMethod(method, model);
        if (object != null) {
            Optional<AbstractModelConverter.MethodCallDecorator> decorator = decorators.stream().filter(d -> d.supports(getSetterMethod(method.getName()))).findAny();
            if (decorator.isPresent()) {
                if (decorator.get().allowMethodCall(object)) {
                    builder.append(decorator.get().decorate(methodName, String.format("\t\t%s.%s(%s);%n", methodName, decorator.get().decorateMethodName(), decorator.get().decorateArgument(object)), object));
                }
            } else if (object instanceof String) {
                builder.append(String.format("\t\t%s.%s(\"%s\");%n", methodName, getSetterMethod(method.getName()), object));
            } else {
                builder.append(String.format("\t\t%s.%s(%s);%n", methodName, getSetterMethod(method.getName()), object));
            }
        }
    }, method -> (method.getName().startsWith("get") || method.getName().startsWith("is"))
            && !method.getName().equals("getClass")
            && !method.getName().equals("getId")
            && method.getParameterCount() == 0);

    builder.append(String.format("\t\treturn %s;%n", methodName));
    builder.append(String.format("\t}%n"));

    return builder.toString();
}
 
Example 18
private String toRegionTemplateBeanName(@NonNull String regionName) {
	return StringUtils.uncapitalize(regionName) + TEMPLATE;
}
 
Example 19
protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) {
	return StringUtils.uncapitalize(ClassUtils.getShortName(interceptorDefinition.getBeanClassName()));
}
 
Example 20
public String getImplementationBeanName() {
	return this.storeInterfaceName + "#" + StringUtils.uncapitalize(ClassUtils.getShortName(implementationClassName));
}