-
Notifications
You must be signed in to change notification settings - Fork 0
/
EachTab.java
95 lines (74 loc) · 1.72 KB
/
EachTab.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
package StockMarktApp;
import java.util.ArrayList;
public class EachTab {
private String[] tabArray;
private boolean symbolValidity;
private ArrayList<String> arrayTxt;
public EachTab(String str){
tabArray = str.split("\n");
divideInput(str);
}
public ArrayList<String> getTabsArray(){
return arrayTxt;
}
public boolean isValidSymbol(){
return symbolValidity;
}
private void divideInput(String ipt){
arrayTxt = new ArrayList<String>();
for(int i=0; i < tabArray.length; i++){
symbolValidity = isStockSymbol(tabArray[i]);
if(!symbolValidity){
break;
}
if(hasCommaCompany(tabArray[i])){
String[] component = tabArray[i].split(",");
component = fixComma(component);
organizeLine(component);
}else{
String[] component = tabArray[i].split(",");
organizeLine(component);
}
}
}
private String[] fixComma(String[] array){
for(int i=0; i<array.length-1; i++){
if(i == 0){
array[0] = array[0] +","+ array[1];
}else{
array[i] = array[i+1];
}
}
return array;
}
private void organizeLine(String[] strArray){
for(int i=0; i<6; i++){
if(i == 0){
arrayTxt.add(removeQuotes(strArray[i]));
}else if(i == 5){
arrayTxt.add(removeQuotes(strArray[i]));
}else{
arrayTxt.add(strArray[i]);
}
}
}
private String removeQuotes(String str){
return str.substring(1, str.length()-1);
}
private boolean isStockSymbol(String str) {
return str.substring(str.length()-4, str.length()-1).equals("N/A");
}
private boolean hasCommaCompany(String str){
int i = 1;
while( i < str.length() ){
if(str.charAt(i) == '"'){
return false;
}else if(str.charAt(i) == ','){
return true;
}else{
i++;
}
}
return false;
}
}