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

The following examples show how to use org.springframework.util.StringUtils#uncapitalize() . 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
Source File: SpannerPersistentEntityImpl.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: DatastorePersistentEntityImpl.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
/**
 * 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
Source File: Jackson2PropertyIntrospectorService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 4
Source File: AbstractEndpointModelConverter.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
/**
 * 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 File: ModelMapTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: ContentLinksResourceProcessor.java    From spring-content with Apache License 2.0 5 votes vote down vote up
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 7
Source File: RocketmqChatDefinitionRegistrar.java    From netty-chat with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: RabbitmqChatDefinitionRegistrar.java    From netty-chat with Apache License 2.0 5 votes vote down vote up
@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
Source File: CustomChatDefinitionRegistrar.java    From netty-chat with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: ActivemqChatDefinitionRegistrar.java    From netty-chat with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: ModelMapTests.java    From spring-analysis-note with 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 12
Source File: AbstractInterceptorDrivenBeanDefinitionDecorator.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) {
	String beanClassName = interceptorDefinition.getBeanClassName();
	return (StringUtils.hasLength(beanClassName) ?
			StringUtils.uncapitalize(ClassUtils.getShortName(beanClassName)) : "");
}
 
Example 13
Source File: AbstractEndpointModelConverter.java    From citrus-admin with Apache License 2.0 4 votes vote down vote up
/**
 * 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\t@Bean(\"%s\")%n", id));
        } else {
            methodName = id;
            builder.append(String.format("%n\t@Bean%n"));
        }
    } else {
        methodName = StringUtils.uncapitalize(model.getClass().getSimpleName());
        builder.append(String.format("%n\t@Bean%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 14
Source File: EventRelProvider.java    From sos with Apache License 2.0 4 votes vote down vote up
@Override
public String getCollectionResourceRelFor(Class<?> type) {
	return StringUtils.uncapitalize(type.getSimpleName());
}
 
Example 15
Source File: AbstractInterceptorDrivenBeanDefinitionDecorator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) {
	return StringUtils.uncapitalize(ClassUtils.getShortName(interceptorDefinition.getBeanClassName()));
}
 
Example 16
Source File: AbstractModelConverter.java    From citrus-admin with Apache License 2.0 4 votes vote down vote up
/**
 * 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\t@Bean(\"%s\")%n", beanId));
    } else {
        methodName = beanId;
        builder.append(String.format("%n\t@Bean%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 17
Source File: RegionTemplateAutoConfiguration.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
private String toRegionTemplateBeanName(@NonNull String regionName) {
	return StringUtils.uncapitalize(regionName) + TEMPLATE;
}
 
Example 18
Source File: AbstractInterceptorDrivenBeanDefinitionDecorator.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) {
	return StringUtils.uncapitalize(ClassUtils.getShortName(interceptorDefinition.getBeanClassName()));
}
 
Example 19
Source File: TestSequenceGenerator.java    From sdn-rx with 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 20
Source File: StoreFragmentDefinition.java    From spring-content with Apache License 2.0 4 votes vote down vote up
public String getImplementationBeanName() {
	return this.storeInterfaceName + "#" + StringUtils.uncapitalize(ClassUtils.getShortName(implementationClassName));
}