IParser
解析器接口
基本信息
| 属性 | 值 |
|---|---|
| 路径 | com.github.lunatrius.ingameinfo.parser.IParser |
| 行数 | 15(纯接口) |
两个方法
boolean load(InputStream inputStream);
boolean parse(Map<Alignment, List<List<Value>>> format);
load
读原始流到内部结构。不接触 format。
三个实现:
| 实现 | 行数 | 内部结构 |
|---|---|---|
| XmlParser | 119 | DOM Document |
| JsonParser | 99 | Gson JsonObject |
| TextParser | 302 | Token 序列(词法已提前做完) |
parse
把内部结构写进 format。format 是
InGameInfoCore 持有的
Map<Alignment, List<List<Value>>>。
⚠️ parse 不清空传入的 map(TextParser 会 format.put 覆盖,
但不清空)。清空责任在
InGameInfoCore.reloadConfig(:177、:192)。
⚠️ 参数命名 format 与 String.format 同名,在实现类里容易遮蔽。
生命周期
InGameInfoCore 按文件扩展名选实例(:118-124),
然后在 reloadConfig 里短路调用:
if (parser.load(is) && parser.parse(format)) return true;
load 失败则不调 parse。
相关
- IPrinter - 对称的输出接口
- InGameInfoCore - 接口的使用方