IndieGame/config/Table/Tools/Luban/Templates/java-json/table.sbn
DOBEST\zhaoyingjie f242607587 初始化工程
2024-10-11 10:12:15 +08:00

82 lines
3.2 KiB
Plaintext

{{~if __namespace_with_top_module != ''~}}
package {{__namespace_with_top_module}};
{{~end~}}
import luban.*;
import com.google.gson.JsonElement;
{{~if __this.comment != '' ~}}
/**
* {{escape_comment __this.comment}}
*/
{{~end~}}
public final class {{__name}} {
{{~if __this.is_map_table
key_type = __this.key_ttype
~}}
private final java.util.HashMap<{{declaring_box_type_name key_type}}, {{declaring_box_type_name __value_type}}> _dataMap;
private final java.util.ArrayList<{{declaring_box_type_name __value_type}}> _dataList;
public {{__name}}(JsonElement _buf) {
_dataMap = new java.util.HashMap<{{declaring_box_type_name key_type}}, {{declaring_box_type_name __value_type}}>();
_dataList = new java.util.ArrayList<{{declaring_box_type_name __value_type}}>();
for (com.google.gson.JsonElement _e_ : _buf.getAsJsonArray()) {
{{declaring_box_type_name __value_type}} _v;
{{deserialize '_v' '_e_' __value_type}}
_dataList.add(_v);
_dataMap.put(_v.{{format_field_name __code_style __this.index_field.name}}, _v);
}
}
public java.util.HashMap<{{declaring_box_type_name key_type}}, {{declaring_box_type_name __value_type}}> getDataMap() { return _dataMap; }
public java.util.ArrayList<{{declaring_box_type_name __value_type}}> getDataList() { return _dataList; }
{{~if __value_type.is_dynamic~}}
@SuppressWarnings("unchecked")
public <T extends {{declaring_box_type_name __value_type}}> T getAs({{declaring_type_name key_type}} key) { return (T)_dataMap.get(key); }
{{~end~}}
public {{declaring_box_type_name __value_type}} get({{declaring_type_name key_type}} key) { return _dataMap.get(key); }
{{~else if __this.is_list_table ~}}
private final java.util.ArrayList<{{declaring_box_type_name __value_type}}> _dataList;
public {{__name}}(JsonElement _buf) {
_dataList = new java.util.ArrayList<{{declaring_box_type_name __value_type}}>();
for (com.google.gson.JsonElement _e_ : _buf.getAsJsonArray()) {
{{declaring_box_type_name __value_type}} _v;
{{deserialize '_v' '_e_' __value_type}}
_dataList.add(_v);
}
}
public java.util.ArrayList<{{declaring_box_type_name __value_type}}> getDataList() { return _dataList; }
public {{declaring_box_type_name __value_type}} get(int index) { return _dataList.get(index); }
{{~else~}}
private final {{declaring_type_name __value_type}} _data;
public final {{declaring_type_name __value_type}} data() { return _data; }
public {{__name}}(JsonElement _buf) {
int n = _buf.getAsJsonArray().size();
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
{{deserialize '_data' '_buf.getAsJsonArray().get(0).getAsJsonObject()' __value_type}}
}
{{~ for field in __value_type.def_bean.hierarchy_export_fields ~}}
{{~if field.comment != '' ~}}
/**
* {{escape_comment field.comment}}
*/
{{~end~}}
public {{declaring_type_name field.ctype}} {{getter_name field.name}}() { return _data.{{format_field_name __code_style field.name}}; }
{{~end~}}
{{~end~}}
}