david-PC\david
2018-06-12 f240ac3ccd37c541cab2c21cfc433d3510999a3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package frame.file;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class IOMappingRuntime {
      
    private List<IOMappingItemRuntime> InsertMappingRuntimeList;
    private Map<String, IOMappingItemRuntime> InsertfromMap;
    private Map<String, IOMappingItemRuntime> InserttoMap;
    private List<IOMappingItemRuntime> updateMappingRuntimeList;
    private Map<String, IOMappingItemRuntime> updatefromMap;
    private Map<String, IOMappingItemRuntime> updatetoMap;
      
    public IOMappingRuntime(List<IOMappingItemRuntime> insertMappingRuntime, List<IOMappingItemRuntime> updateMappingRuntime) {
        InsertMappingRuntimeList = new ArrayList<IOMappingItemRuntime>();
        InsertfromMap = new HashMap<String, IOMappingItemRuntime>();
        InserttoMap = new HashMap<String, IOMappingItemRuntime>();
        updateMappingRuntimeList = new ArrayList<IOMappingItemRuntime>();
        updatefromMap = new HashMap<String, IOMappingItemRuntime>();
        updatetoMap = new HashMap<String, IOMappingItemRuntime>();
        
        for (IOMappingItemRuntime ioMappingItemRuntime : insertMappingRuntime) {
            addItem(ioMappingItemRuntime, "insert");
        }
        
        for (IOMappingItemRuntime ioMappingItemRuntime : updateMappingRuntime) {
            addItem(ioMappingItemRuntime, "update");
        }
    }
 
    private void addItem(IOMappingItemRuntime ioMappingItemRuntime, String type) {
        // base,add
        if ("insert".equalsIgnoreCase(type)) {
            InsertMappingRuntimeList.add(ioMappingItemRuntime);
            InsertfromMap.put(ioMappingItemRuntime.getFromField(), ioMappingItemRuntime);
            InserttoMap.put(ioMappingItemRuntime.getToField(), ioMappingItemRuntime);
        }
        else if ("update".equalsIgnoreCase(type)) {
            updateMappingRuntimeList.add(ioMappingItemRuntime);
            updatefromMap.put(ioMappingItemRuntime.getFromField(), ioMappingItemRuntime);
            updatetoMap.put(ioMappingItemRuntime.getToField(), ioMappingItemRuntime);
        }
        
    }
    
    public boolean contaisFromField(String fromField, String type) {
        boolean containsField = containsField(fromField, "from", type);
        return containsField;
    }
    
    public boolean contaisToField(String toField, String type) {
        boolean containsField = containsField(toField, "to", type);
        return containsField;
    }
    
    private boolean containsField(String field, String directionType, String dataType) {
        if (field == null) {
            return false;
        }
        if ("insert".equalsIgnoreCase(dataType)) {
            if ("from".equalsIgnoreCase(directionType)) {
                return InsertfromMap.containsKey(field.toLowerCase());
            }
            else if ("to".equalsIgnoreCase(directionType)) {
                return InserttoMap.containsKey(field.toLowerCase());
            }
        }
        else if ("update".equalsIgnoreCase(dataType)) {
            if ("from".equalsIgnoreCase(directionType)) {
                return updatefromMap.containsKey(field.toLowerCase());
            }
            else if ("to".equalsIgnoreCase(directionType)) {
                return updatetoMap.containsKey(field.toLowerCase());
            }
        }
        
        return false;
    }
 
    public List<IOMappingItemRuntime> getUpdateMappingRuntime() {
        
        return updateMappingRuntimeList;
    }
 
    public List<IOMappingItemRuntime> getInsertMappingRuntime() {
        return InsertMappingRuntimeList;
    }
}