package foundation.io.define;
|
|
import java.util.Iterator;
|
import java.util.List;
|
|
import foundation.right.Range;
|
import foundation.util.MapList;
|
import foundation.util.Util;
|
|
|
public class IOTask implements Iterable<DataIO> {
|
|
private String name;
|
private IOSource source;
|
private Range range;
|
private MapList<String, DataIO> ioList;
|
private boolean existsUploadFile;
|
private boolean existsDownloadFile;
|
private IOSpeedMode speedMode;
|
|
|
public IOTask(IOSource source) throws Exception {
|
this.source = source;
|
this.ioList = new MapList<String, DataIO>();
|
this.speedMode = IOSpeedMode.Standard;
|
}
|
|
public void setName(String name) {
|
this.name = name;
|
}
|
|
public String getName() {
|
return name;
|
}
|
|
public Range getRange() {
|
return range;
|
}
|
|
public MapList<String, DataIO> getDataIOList() {
|
return ioList;
|
}
|
|
public void addDataIO(DataIO dataIO) {
|
//1.
|
String id = dataIO.getId();
|
ioList.add(id, dataIO);
|
|
//2.
|
IODirection direction = dataIO.getDirection();
|
|
if (IODirection.SheetToTable == direction) {
|
existsUploadFile = true;
|
}
|
else if (IODirection.SheetToMemory == direction) {
|
existsUploadFile = true;
|
}
|
else if (IODirection.TableToSheet == direction) {
|
existsDownloadFile = true;
|
}
|
else if (IODirection.ErrorsToSheet == direction) {
|
existsDownloadFile = true;
|
}
|
}
|
|
public DataIO getDataIO(String id) {
|
if (!ioList.contains(id)) {
|
return null;
|
}
|
|
return ioList.get(id);
|
}
|
|
public DataIO getDataIO(int index) {
|
return ioList.get(index);
|
}
|
|
public void clear() {
|
ioList.clear();
|
}
|
|
@Override
|
public Iterator<DataIO> iterator() {
|
return ioList.iterator();
|
}
|
|
public List<DataIO> getIOList() {
|
return ioList.getItemList();
|
}
|
|
public boolean existsUploadFile() {
|
return existsUploadFile;
|
}
|
|
public boolean existsDownloadFile() {
|
return existsDownloadFile;
|
}
|
|
public boolean existsFile() {
|
return existsUploadFile || existsDownloadFile;
|
}
|
|
public IOSpeedMode getSpeedMode() {
|
return speedMode;
|
}
|
|
public int size() {
|
return ioList.size();
|
}
|
|
public DataIO getDownloadDataIO() {
|
//1. 如果有多个 Data IO,返回那个有template的 IO
|
for (DataIO dataIO: ioList) {
|
if (IODirection.TableToSheet == dataIO.getDirection() || IODirection.ErrorsToSheet == dataIO.getDirection()) {
|
String template = dataIO.getTemplateName();
|
|
if (!Util.isEmpty(template)) {
|
return dataIO;
|
}
|
}
|
}
|
|
//2. 如果没有 template,取第一个可能的
|
for (DataIO dataIO: ioList) {
|
if (IODirection.TableToSheet == dataIO.getDirection() || IODirection.ErrorsToSheet == dataIO.getDirection()) {
|
return dataIO;
|
}
|
}
|
|
return null;
|
}
|
|
public boolean isEmpty() {
|
return ioList.isEmpty();
|
}
|
|
public IOSource getSource() {
|
return source;
|
}
|
|
}
|