下面列出了org.springframework.util.StringUtils#trimAllWhitespace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void setProcessEngineName(SpringProcessEngineConfiguration configuration) {
String processEngineName = StringUtils.trimAllWhitespace(camundaBpmProperties.getProcessEngineName());
if (!StringUtils.isEmpty(processEngineName) && !processEngineName.contains("-")) {
if (camundaBpmProperties.getGenerateUniqueProcessEngineName()) {
if (!processEngineName.equals(ProcessEngines.NAME_DEFAULT)) {
throw new RuntimeException(String.format("A unique processEngineName cannot be generated "
+ "if a custom processEngineName is already set: %s", processEngineName));
}
processEngineName = CamundaBpmProperties.getUniqueName(camundaBpmProperties.UNIQUE_ENGINE_NAME_PREFIX);
}
configuration.setProcessEngineName(processEngineName);
} else {
logger.warn("Ignoring invalid processEngineName='{}' - must not be null, blank or contain hyphen", camundaBpmProperties.getProcessEngineName());
}
}
public static String generate(String name, String email) {
Assert.hasText(name, "Name is required");
if (!StringUtils.hasText(email)) {
name = name.toLowerCase();
name = StringUtils.trimAllWhitespace(name);
email = String.format("%1$s%2$s", name,
AT_EMAIL_ADDRESSES.get(index.nextInt(AT_EMAIL_ADDRESSES.size())));
}
return email;
}
private boolean getBoolValue(String range) {
range = StringUtils.trimAllWhitespace(range);
String[] parts = StringUtils.commaDelimitedListToStringArray(range);
if (parts.length != 2) {
throw new IllegalArgumentException("Condition.bool set args error.");
}
return parts[0].equals(parts[1]);
}
/**
* 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();
}
@Test
public void exportFromExampleRegionToJson() {
try {
System.setProperty(EXPORT_ENABLED_PROPERTY, Boolean.TRUE.toString());
StringWriter writer = new StringWriter();
writerSupplier = () -> writer;
Region<Long, Customer> example =
getExampleRegion(newApplicationContext(withResource("data-example.json")));
assertExampleRegion(example);
assertThat(example).isEmpty();
Customer playDoe = Customer.newCustomer(42L, "Play Doe");
example.put(playDoe.getId(), playDoe);
assertThat(example).hasSize(1);
assertThat(example.get(42L)).isEqualTo(playDoe);
closeApplicationContext();
String actualJson = StringUtils.trimAllWhitespace(writer.toString());
String expectedJson = String.format("[{\"@type\":\"%s\",\"id\":42,\"name\":\"PlayDoe\"}]",
playDoe.getClass().getName());
assertThat(actualJson).isEqualTo(expectedJson);
}
finally {
System.clearProperty(EXPORT_ENABLED_PROPERTY);
}
}
private String[] trim(String[] array) {
array = ArrayUtils.nullSafeArray(array, String.class);
for (int index = 0; index < array.length; index++) {
array[index] = StringUtils.trimAllWhitespace(array[index]);
}
return array;
}
/**
* Set the name of the field to be retrieved.
* Refers to either a static field or a non-static field,
* depending on a target object being set.
* @see #setTargetClass
* @see #setTargetObject
*/
public void setTargetField(String targetField) {
this.targetField = StringUtils.trimAllWhitespace(targetField);
}
/**
* The bean name of this FieldRetrievingFactoryBean will be interpreted
* as "staticField" pattern, if neither "targetClass" nor "targetObject"
* nor "targetField" have been specified.
* This allows for concise bean definitions with just an id/name.
*/
@Override
public void setBeanName(String beanName) {
this.beanName = StringUtils.trimAllWhitespace(BeanFactoryUtils.originalBeanName(beanName));
}
/**
* Set the name of the field to be retrieved.
* Refers to either a static field or a non-static field,
* depending on a target object being set.
* @see #setTargetClass
* @see #setTargetObject
*/
public void setTargetField(@Nullable String targetField) {
this.targetField = (targetField != null ? StringUtils.trimAllWhitespace(targetField) : null);
}
/**
* Set a fully qualified static field name to retrieve,
* e.g. "example.MyExampleClass.MY_EXAMPLE_FIELD".
* Convenient alternative to specifying targetClass and targetField.
* @see #setTargetClass
* @see #setTargetField
*/
public void setStaticField(String staticField) {
this.staticField = StringUtils.trimAllWhitespace(staticField);
}
/**
* Specify the name of a target bean to apply the property path to.
* Alternatively, specify a target object directly.
* @param targetBeanName the bean name to be looked up in the
* containing bean factory (e.g. "testBean")
* @see #setTargetObject
*/
public void setTargetBeanName(String targetBeanName) {
this.targetBeanName = StringUtils.trimAllWhitespace(targetBeanName);
}
/**
* Specify the property path to apply to the target.
* @param propertyPath the property path, potentially nested
* (e.g. "age" or "spouse.age")
*/
public void setPropertyPath(String propertyPath) {
this.propertyPath = StringUtils.trimAllWhitespace(propertyPath);
}
/**
* The bean name of this PropertyPathFactoryBean will be interpreted
* as "beanName.property" pattern, if neither "targetObject" nor
* "targetBeanName" nor "propertyPath" have been specified.
* This allows for concise bean definitions with just an id/name.
*/
@Override
public void setBeanName(String beanName) {
this.beanName = StringUtils.trimAllWhitespace(BeanFactoryUtils.originalBeanName(beanName));
}
/**
* Set a fully qualified static field name to retrieve,
* e.g. "example.MyExampleClass.MY_EXAMPLE_FIELD".
* Convenient alternative to specifying targetClass and targetField.
* @see #setTargetClass
* @see #setTargetField
*/
public void setStaticField(String staticField) {
this.staticField = StringUtils.trimAllWhitespace(staticField);
}
/**
* The bean name of this FieldRetrievingFactoryBean will be interpreted
* as "staticField" pattern, if neither "targetClass" nor "targetObject"
* nor "targetField" have been specified.
* This allows for concise bean definitions with just an id/name.
*/
@Override
public void setBeanName(String beanName) {
this.beanName = StringUtils.trimAllWhitespace(BeanFactoryUtils.originalBeanName(beanName));
}
/**
* Set a fully qualified static field name to retrieve,
* e.g. "example.MyExampleClass.MY_EXAMPLE_FIELD".
* Convenient alternative to specifying targetClass and targetField.
* @see #setTargetClass
* @see #setTargetField
*/
public void setStaticField(String staticField) {
this.staticField = StringUtils.trimAllWhitespace(staticField);
}
/**
* Set the name of the field to be retrieved.
* Refers to either a static field or a non-static field,
* depending on a target object being set.
* @see #setTargetClass
* @see #setTargetObject
*/
public void setTargetField(String targetField) {
this.targetField = StringUtils.trimAllWhitespace(targetField);
}
/**
* Specify the name of a target bean to apply the property path to.
* Alternatively, specify a target object directly.
* @param targetBeanName the bean name to be looked up in the
* containing bean factory (e.g. "testBean")
* @see #setTargetObject
*/
public void setTargetBeanName(String targetBeanName) {
this.targetBeanName = StringUtils.trimAllWhitespace(targetBeanName);
}
/**
* Specify the property path to apply to the target.
* @param propertyPath the property path, potentially nested
* (e.g. "age" or "spouse.age")
*/
public void setPropertyPath(String propertyPath) {
this.propertyPath = StringUtils.trimAllWhitespace(propertyPath);
}
/**
* Specify the name of a target bean to apply the property path to.
* Alternatively, specify a target object directly.
* @param targetBeanName the bean name to be looked up in the
* containing bean factory (e.g. "testBean")
* @see #setTargetObject
*/
public void setTargetBeanName(String targetBeanName) {
this.targetBeanName = StringUtils.trimAllWhitespace(targetBeanName);
}