Untitled
unknown
plain_text
3 years ago
3.8 kB
8
Indexable
package project1;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.regex.*;
import java.util.*;
class program1 {
public static void main(String[] args) {
String filePath = "D:\\SAMPLE1.txt";
String text = "";
try {
text = new String(Files.readAllBytes(Paths.get(filePath)));
} catch (IOException e) {
System.out.println("Error reading file at path: " + filePath);
}
Scanner sc = new Scanner(text);
List<String> list1 = new ArrayList<>();
Map<String, String> mp = new HashMap<String, String>() {{
put("35=D", "New Single Order");
put("35=8", "Execution Report");
put("35=G", "Order Cancel");
put("39=0", "New");
put("39=E", "Pending");
put("39=1", "Partial Fill");
put("39=2", "Fully Fill");
put("150=0", "New");
put("150=F", "Partial Fill");
put("150=E", "Pending");
put("150=5", "Ammend");
put("150=8", "Rejected");
put("59=0","Day");
}};
while (sc.hasNextLine()) {
String line = sc.nextLine();
//System.out.println(line);
Pattern pattern = Pattern.compile("\\[(.*)\\]");
Matcher matcher = pattern.matcher(line);
String match = "";
while (matcher.find()) {
match = matcher.group(1);
}
String[] split1 = match.split("\\|");
boolean cond = false;
for (int i = 0; i < split1.length; i++) {
// System.out.print(split1[i] + " ");
//TODO: Added this:
// System.out.println();
}
//System.out.println();
Map<String, String> matchMap = new LinkedHashMap<>();
for (String s : split1) {
if (s.contains("35=") || s.contains("150=") || s.contains("39=") || s.contains("59=")) {
matchMap.put(s, mp.get(s));
}
if (s.contains("35=8")) {
cond = true;
}
}
System.out.println(matchMap);
String searchValue1 = "59=";
String searchValue2 = "35=";
if (cond == false) {
for (String key : matchMap.keySet()) {
if (key.contains(searchValue1) || key.contains(searchValue2)) {
list1.add(mp.get(key));
}
}
}
else {
List<String> newList = new ArrayList<>();
for (String key : matchMap.keySet()) {
if (key.contains("39=") || key.contains("150=")) {
newList.add(key);
}
}
if (newList.contains("39=2") && newList.contains("150=F")) {
list1.add("Fully Filled");
} else if (newList.contains("39=1") && newList.contains("150=5")) {
list1.add("Ammend");
} else if (newList.contains("150=8")) {
list1.add("Ammend");
} else {
if(!newList.isEmpty()) {
list1.add(mp.get(newList.get(0)));
}
else
{
System.out.println(mp.get("35=8"));
}
}
}
}
for (String element : list1) {
System.out.println(element);
}
}
}Editor is loading...