-
Notifications
You must be signed in to change notification settings - Fork 27
/
EdgeTable.java
123 lines (106 loc) · 4.33 KB
/
EdgeTable.java
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import java.util.*;
public class EdgeTable {
private int numFigure;
private String name;
private ArrayList alRelatedTables, alNativeFields;
private int[] relatedTables, relatedFields, nativeFields;
public EdgeTable(String inputString) {
StringTokenizer st = new StringTokenizer(inputString, EdgeConvertFileParser.DELIM);
numFigure = Integer.parseInt(st.nextToken());
name = st.nextToken();
alRelatedTables = new ArrayList();
alNativeFields = new ArrayList();
}
public int getNumFigure() {
return numFigure;
}
public String getName() {
return name;
}
public void addRelatedTable(int relatedTable) {
alRelatedTables.add(new Integer(relatedTable));
}
public int[] getRelatedTablesArray() {
return relatedTables;
}
public int[] getRelatedFieldsArray() {
return relatedFields;
}
public void setRelatedField(int index, int relatedValue) {
relatedFields[index] = relatedValue;
}
public int[] getNativeFieldsArray() {
return nativeFields;
}
public void addNativeField(int value) {
alNativeFields.add(new Integer(value));
}
public void moveFieldUp(int index) { //move the field closer to the beginning of the list
if (index == 0) {
return;
}
int tempNative = nativeFields[index - 1]; //save element at destination index
nativeFields[index - 1] = nativeFields[index]; //copy target element to destination
nativeFields[index] = tempNative; //copy saved element to target's original location
int tempRelated = relatedFields[index - 1]; //save element at destination index
relatedFields[index - 1] = relatedFields[index]; //copy target element to destination
relatedFields[index] = tempRelated; //copy saved element to target's original location
}
public void moveFieldDown(int index) { //move the field closer to the end of the list
if (index == (nativeFields.length - 1)) {
return;
}
int tempNative = nativeFields[index + 1]; //save element at destination index
nativeFields[index + 1] = nativeFields[index]; //copy target element to destination
nativeFields[index] = tempNative; //copy saved element to target's original location
int tempRelated = relatedFields[index + 1]; //save element at destination index
relatedFields[index + 1] = relatedFields[index]; //copy target element to destination
relatedFields[index] = tempRelated; //copy saved element to target's original location
}
public void makeArrays() { //convert the ArrayLists into int[]
Integer[] temp;
temp = (Integer[])alNativeFields.toArray(new Integer[alNativeFields.size()]);
nativeFields = new int[temp.length];
for (int i = 0; i < temp.length; i++) {
nativeFields[i] = temp[i].intValue();
}
temp = (Integer[])alRelatedTables.toArray(new Integer[alRelatedTables.size()]);
relatedTables = new int[temp.length];
for (int i = 0; i < temp.length; i++) {
relatedTables[i] = temp[i].intValue();
}
relatedFields = new int[nativeFields.length];
for (int i = 0; i < relatedFields.length; i++) {
relatedFields[i] = 0;
}
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Table: " + numFigure + "\r\n");
sb.append("{\r\n");
sb.append("TableName: " + name + "\r\n");
sb.append("NativeFields: ");
for (int i = 0; i < nativeFields.length; i++) {
sb.append(nativeFields[i]);
if (i < (nativeFields.length - 1)){
sb.append(EdgeConvertFileParser.DELIM);
}
}
sb.append("\r\nRelatedTables: ");
for (int i = 0; i < relatedTables.length; i++) {
sb.append(relatedTables[i]);
if (i < (relatedTables.length - 1)){
sb.append(EdgeConvertFileParser.DELIM);
}
}
sb.append("\r\nRelatedFields: ");
for (int i = 0; i < relatedFields.length; i++) {
sb.append(relatedFields[i]);
if (i < (relatedFields.length - 1)){
sb.append(EdgeConvertFileParser.DELIM);
}
}
sb.append("\r\n}\r\n");
return sb.toString();
}
}