com.jn.langx.text.ParameterizedMessage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of langx-java Show documentation
Show all versions of langx-java Show documentation
Java lang extensions for java6+, a supplement to , replacement of a Guava, commons-lang.
Core utilities, Collection utilities, IO utilities, Cache, Configuration library ...
package com.jn.langx.text;
/**
* 参数化消息
*
* 使用方式:
*
* new ParameterizedMessage("hello {0}, welcome you to {1} . ", new Object[]{"zhang san", "BeiJing"});
*
那么结果就是:
* "hello zhang san, welcome you to BeiJing ."
*
* @author fangjinuo
*/
public class ParameterizedMessage {
private volatile String template;
private Object[] args = null;
public ParameterizedMessage() {
}
public ParameterizedMessage(String template) {
this.template = template;
}
public ParameterizedMessage(String template, Object... args) {
this.template = template;
this.args = args;
}
public String getMessage() {
if (template != null) {
return StringTemplates.format(template, args);
}
return "";
}
@Override
public String toString() {
return getMessage();
}
}