-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdgeTable.java
More file actions
executable file
·152 lines (124 loc) · 4.4 KB
/
EdgeTable.java
File metadata and controls
executable file
·152 lines (124 loc) · 4.4 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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;
}
moveField(index,-1);
}
public void moveFieldDown(int index) { //move the field closer to the end of the list
if (index == (nativeFields.length - 1)) {
return;
}
moveField(index,1);
}
//TODO: - REFACTORED CODE
/**
* This method takes in an index and direction to determine whether
* to move a field up or down.
* @param index
* @param direction
*/
public void moveField(int index, int direction) {
int tempNative = nativeFields[index + direction]; //save element at destination index
nativeFields[index + direction] = nativeFields[index]; //copy target element to destination
nativeFields[index] = tempNative; //copy saved element to target's original location
int tempRelated = relatedFields[index + direction]; //save element at destination index
relatedFields[index + direction] = 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[]
assignArrays(alNativeFields, "nativeFields");
assignArrays(alRelatedTables, "relatedTables");
relatedFields = new int[nativeFields.length];
for (int i = 0; i < relatedFields.length; i++) {
relatedFields[i] = 0;
}
}
//TODO: - REFACTORED CODE
/**
* Method that will take in two arrays and loop
* through them in order to get the columns/fields
* from each table.
*
* @param lists
*/
public void assignArrays(ArrayList lists, String fieldName) {
Integer[] temp;
temp = (Integer[])lists.toArray(new Integer[lists.size()]);
int[] array = new int[temp.length];
for (int i = 0; i < temp.length; i++) {
array[i] = temp[i].intValue();
}
if(fieldName.equals("nativeFields")) {
nativeFields = array;
} else {
relatedTables = array;
}
}
public void appendString(StringBuffer buffer, int[] array) {
for (int i = 0; i < array.length; i++) {
buffer.append(array[i]);
if (i < (array.length - 1)){
buffer.append(EdgeConvertFileParser.DELIM);
}
}
}
//TODO: - REFACTORED CODE
/**
* Method that will take in a string buffer
* and the array to be parsed. It will loop
* through the array and parse it to get the field values
* and append it to a string to print out.
*
*/
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: ");
appendString(sb, nativeFields);
sb.append("\r\nRelatedTables: ");
appendString(sb, relatedTables);
sb.append("\r\nRelatedFields: ");
appendString(sb, relatedFields);
sb.append("\r\n}\r\n");
return sb.toString();
}
}