加入模板实体,优化部分代码。

This commit is contained in:
makejava 2018-01-10 22:00:04 +08:00
parent e24bfc065d
commit a12d295d79
4 changed files with 125 additions and 10 deletions

View File

@ -0,0 +1,54 @@
package com.sjhy.plugin.entity;
public class Template implements Cloneable {
//模板名称
private String name;
//模板代码
private String code;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Template cloneTemplate() {
try {
return (Template) clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Template template = (Template) o;
return name.equals(template.name) && code.equals(template.code);
}
@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + code.hashCode();
return result;
}
}

View File

@ -0,0 +1,60 @@
package com.sjhy.plugin.entity;
import java.util.ArrayList;
import java.util.List;
public class TemplateGroup implements Cloneable {
//模板组名称
private String name;
//模板集合
private List<Template> templateList;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Template> getTemplateList() {
return templateList;
}
public void setTemplateList(List<Template> templateList) {
this.templateList = templateList;
}
public TemplateGroup cloneTemplateGroup() {
try {
return (TemplateGroup) clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
@Override
protected Object clone() throws CloneNotSupportedException {
TemplateGroup templateGroup = (TemplateGroup) super.clone();
templateGroup.templateList = new ArrayList<>();
this.templateList.forEach(template -> templateGroup.templateList.add(template.cloneTemplate()));
return templateGroup;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TemplateGroup that = (TemplateGroup) o;
return name.equals(that.name) && templateList.equals(that.templateList);
}
@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + templateList.hashCode();
return result;
}
}

View File

@ -32,8 +32,16 @@ public class TypeMapper implements Cloneable, Serializable {
this.javaType = javaType;
}
public TypeMapper cloneTypeMapper() {
try {
return (TypeMapper) super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
@Override
public Object clone() throws CloneNotSupportedException {
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}

View File

@ -28,22 +28,15 @@ public class TypeMapperGroup implements Cloneable, Serializable {
try {
return (TypeMapperGroup) clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return null;
}
@Override
public Object clone() throws CloneNotSupportedException {
TypeMapperGroup typeMapperGroup = (TypeMapperGroup) super.clone();
typeMapperGroup.typeMapperList = new ArrayList<>();
this.typeMapperList.forEach(typeMapper -> {
try {
typeMapperGroup.typeMapperList.add((TypeMapper) typeMapper.clone());
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
});
this.typeMapperList.forEach(typeMapper -> typeMapperGroup.typeMapperList.add(typeMapper.cloneTypeMapper()));
return typeMapperGroup;
}