All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ys.artifact-network.1.0.5.source-code.struct.btl Maven / Gradle / Ivy

package ${packageName}.structs;

import lombok.Data;
import java.util.Map;
import cn.hutool.core.map.MapUtil;
<%
	var extends = false;
	var extendConstant = "";
	if(strutil.isNotBlank(struct.extendsName)){
		extends = true;
		extendConstant = "extends " + struct.extendsName;
	}else{
		extends = false;
		extendConstant = "implements DTO";
	}
%>
<%if(!extends){%>
import org.artifact.core.lang.DTO;
<%}%>
@Data
/**
 * ${struct.remark}
 */
public class ${struct.structName} ${extendConstant}{
	<%for(field in struct.fields){%>
	/** ${field.key.remark} */
	<%if(strutil.startWith(field.value.type,"java.util.Map")){%>
	private ${field.value.intact} ${field.key.name} = new java.util.HashMap<>();
	<%}else if(strutil.startWith(field.value.type,"java.util.List")){%>
	private ${field.value.intact} ${field.key.name} = new java.util.ArrayList<>();
	<%}else{%>
	private ${field.value.intact} ${field.key.name};
	<%}%>
	<%}%>

	public Map toMap(Map map){
		<%if(extends){%>
		super.toMap(map);
		<%}%>
		<%
		var hashArray = [];
		for(field in struct.fields){
		hashCode = HashUtil.javaDefaultHash(field.key.name)+"";
		if(array.contain(hashArray,hashCode)){
			println("		"+field.key.name+":HashCode重复,请重命名");
			continue;
		}else{
			array.add(hashArray,hashCode);
		}
		%>
		map.put(${hashCode},this.${field.key.name});
	    <%}%>
	    return map;
	}

	public ${struct.structName} forMap(Map map){
        <%if(extends){%>
        super.forMap(map);
        <%}%>
        <%
        for(field in struct.fields){
        hashCode = HashUtil.javaDefaultHash(field.key.name)+"";
        var v = "";
        select(field.value.type){
        case "byte","java.lang.Byte":
            v = "MapUtil.getByte(map ," + hashCode + ")";
        case "short","java.lang.Short":
            v = "MapUtil.getShort(map ," + hashCode + ")";
        case "int","java.lang.Integer":
            v = "MapUtil.getInt(map ," + hashCode + ")";
        case "long","java.lang.Long":
            v = "MapUtil.getLong(map ," + hashCode + ")";
        case "float","java.lang.Float":
            v = "MapUtil.getFloat(map ," + hashCode + ")";
        case "double","java.lang.Double":
            v = "MapUtil.getDouble(map ," + hashCode + ")";
        case "String","java.lang.String":
            v = "MapUtil.getStr(map ," + hashCode + ")";
        case "boolean","java.lang.Boolean":
            v = "MapUtil.getBool(map ," + hashCode + ")";
        default:
            v = "MapUtil.get(map ," + hashCode +"," +field.value.type+ ".class)";
        }
        %>
        this.${field.key.name} = ${v};
        <%}%>
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy