stationversion.java
来自「工厂版本管理系统,STRUTS2框架,用于管理商品的版本,便于有效的控制版本」· Java 代码 · 共 133 行
JAVA
133 行
package com.utstar.fcs.domain.workinstruction;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class StationVersion implements Cloneable{
private Long id;
private String version;
// private Set<Field> fields = new HashSet<Field>();
private Map<FieldDefinition, Field> fields = new HashMap<FieldDefinition, Field>();
private Station station;
public StationVersion() {
// TODO Auto-generated constructor stub
}
public StationVersion cloneEntity() {
try {
return (StationVersion) clone();
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException("CloneEntity Fail");
}
}
public static StationVersion getSample(Station station) {
StationVersion sv = new StationVersion();
sv.setStation(station);
Iterator<FieldDefinition> fdIt = station.getStationType()
.getFieldDefinitions().iterator();
while (fdIt.hasNext()) {
FieldDefinition fd = fdIt.next();
Field field = FieldFactory.createFieldSample(fd);
field.setFieldDefinition(fd);
field.setStationVersion(sv);
sv.addField(field);
}
return sv;
}
public Field addField(Field field) {
fields.put(field.getFieldDefinition(), field);
field.setStationVersion(this);
return field;
}
public Field findField(Long fieldDefinitionId) {
Iterator<Field> it = fields.values().iterator();
while (it.hasNext()) {
Field f = it.next();
if (f.getFieldDefinition().getId() == fieldDefinitionId)
return f;
}
return null;
}
public String getFieldValue(Long fieldDefinitionId) {
// Long fieldDefinitionId = Long.parseLong(stringFieldDefinitionId
// .substring(4));
Field f = findField(fieldDefinitionId);
if (f == null)
return "";
else
return f.getStringValue();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public Map<FieldDefinition, Field> getFields() {
return fields;
}
public void setFields(Map<FieldDefinition, Field> fields) {
this.fields = fields;
}
public Station getStation() {
return station;
}
public void setStation(Station station) {
this.station = station;
}
@Override
protected Object clone() throws CloneNotSupportedException {
StationVersion stationVersion = (StationVersion) super.clone();
stationVersion.fields =new HashMap<FieldDefinition, Field>();
stationVersion.station = station;
stationVersion.setId(null);
Iterator<FieldDefinition> it1 = fields.keySet().iterator();
while (it1.hasNext()) {
FieldDefinition key = it1.next();
Field value = fields.get(key);
Field field2 = (Field) value.clone();
stationVersion.addField(field2);
}
return stationVersion;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?