add comprehensive javadoc comments for all classes
- Add class-level documentation for all mapper and multilingual classes - Add complete javadoc for all public methods with @param and @return tags - Add field-level comments for better code readability - Improve documentation for initialization blocks and constructors Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -7,35 +7,69 @@ import com.imyeyu.utils.StringInterpolator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 抽象语言映射器,提供语言映射的基础实现,提供字符串插值、调试模式等基础功能
|
||||
*
|
||||
* @author 夜雨
|
||||
* @version 2024-04-01 16:25
|
||||
*/
|
||||
public abstract class AbstractLanguageMapper implements LanguageMapping {
|
||||
|
||||
/** 字符串插值器,用于处理占位符替换 */
|
||||
protected final StringInterpolator INTERPOLATOR = StringInterpolator.createDollarInterpolator();
|
||||
|
||||
/** 当前映射器所属语言 */
|
||||
protected final Language.Enum language;
|
||||
|
||||
/** 是否启用调试模式,启用后将抛出异常而不是返回默认值 */
|
||||
protected boolean isDebugging = false;
|
||||
|
||||
/**
|
||||
* 构造语言映射器
|
||||
*
|
||||
* @param language 所属语言
|
||||
*/
|
||||
public AbstractLanguageMapper(Language.Enum language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前映射器所属语言
|
||||
*
|
||||
* @return 语言枚举
|
||||
*/
|
||||
public Language.Enum getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置调试模式,调试模式下,找不到映射时将抛出异常而不是返回默认值
|
||||
*
|
||||
* @param debugging true 为启用调试模式
|
||||
*/
|
||||
public void setDebugging(boolean debugging) {
|
||||
isDebugging = debugging;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文本
|
||||
*
|
||||
* @param key 键
|
||||
* @param def 默认值(没有找到映射值时)
|
||||
* @return 获取结果
|
||||
*/
|
||||
@Override
|
||||
public String text(String key, String def) {
|
||||
String result = text(key);
|
||||
return result.equals(key) ? def : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入参数获取文本,使用 ${key} 格式进行占位符替换
|
||||
*
|
||||
* @param key 键
|
||||
* @param args 参数映射表
|
||||
* @return 替换占位符后的文本
|
||||
*/
|
||||
@Override
|
||||
public String textArgs(String key, Map<String, Object> args) {
|
||||
return INTERPOLATOR.inject(text(key), args);
|
||||
|
||||
Reference in New Issue
Block a user