Untitled

 avatar
unknown
plain_text
2 years ago
7.6 kB
11
Indexable
package project1;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.BufferedReader;

import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public 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> GTD = new ArrayList<>();
        List<String>OrderFlow = new ArrayList<>();
        List<String> tg39 = new ArrayList<>();
        List<String> tg35 = new ArrayList<>();
        List<String> rg = new ArrayList<>();
        Map<String, Map<String, String>> mp = new HashMap<>();
        try {
            BufferedReader reader = new BufferedReader(new FileReader("D:\\config.properties.txt"));
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split("=");
                if (!mp.containsKey(parts[0] + "=" + parts[1])) {
                    mp.put(parts[0] + "=" + parts[1], new HashMap<String, String>());
                }
                mp.get(parts[0] + "=" + parts[1]).put("value", parts[2]);
            }
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        boolean found= false;
        while (sc.hasNextLine()) {
            String line = sc.nextLine();
            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;
            Map<String, String> matchMap = new HashMap<>();
 
            for (String s : split1) {
                if (s.contains("35=") || s.contains("150=") || s.contains("39=")|| s.contains("59=")) {
                	Map<String, String> innerMap = mp.get(s);
                    String value = innerMap.get("value");
                	matchMap.put(s, value);
                }
            }
            for (String s2 : split1) {
                if (s2.contains("442")) {
                	Map<String, String> innerMap = mp.get(s2);
                    String value = innerMap.get("value");
                	matchMap.put(s2, value);
                    cond= true;
                }           
            }
            
            String searchValue1 = "59=";
            String searchValue2= "35=";
            String searchValue4= "442=";
            String searchValue5= "39=";
             for(String key : matchMap.keySet()) {
            	 if(key.contains(searchValue5))
            	 {
            		 Map<String, String> innerMap = mp.get(key);
                     String value = innerMap.get("value");
            		 tg39.add(value);
            	 } if(key.contains(searchValue2))
            	 {
            		 Map<String, String> innerMap = mp.get(key);
                     String value = innerMap.get("value");
            		 tg35.add(value);
            	 } if(key.contains(searchValue1))
            	 {
            		 Map<String, String> innerMap = mp.get(key);
                     String value = innerMap.get("value");
            		 GTD.add(value);
            	 } if(key.contains(searchValue4))
            	 {
            		 if(key.contains("442=3") || key.contains("442=2")) {
            			 
            		 }if(!found) {if((key.contains("442=3") || key.contains("442=2"))) {
            			 System.out.println("Order type: Spread order");
            			 found=true;
            		 }else {
            			 System.out.println("Order type: outright");
            			 found=true;
            		 }
            	 }
             }}
            
            if(cond == false) {
            }else {
                List<String> newList = new ArrayList<>();
                for (String key : matchMap.keySet()) {
                    if (key.contains("39=") || key.contains("150=")) {
                        newList.add(key);
                    }
                    if(key.contains("39=")) {
                    	Map<String, String> innerMap = mp.get(key);
                        String value = innerMap.get("value");
                    	tg39.add(value);
                    }
                }
                if (newList.contains("39=2") && newList.contains("150=F")) {
                    OrderFlow.add("Fully Filled");
                } else if (newList.contains("39=1") && newList.contains("150=5")) {
                    OrderFlow.add("Ammend");
                } else if (newList.contains("150=8")) {
                    OrderFlow.add("Rejected");
                }else if (newList.contains("39=0")) {
                    OrderFlow.add("new");
                }else if (newList.contains("39=1")) {
                    OrderFlow.add("partial fill");
                }else if (newList.contains("150=5")) {
                    OrderFlow.add("amend");
                }
                else {
                	if(!newList.isEmpty()) {
                		Map<String, String> innerMap = mp.get(newList.get(1));
                        String value = innerMap.get("value");
                		OrderFlow.add(value);
                	}
                	
                }
            }
            boolean condition = false;
            String found35 = "";
            for (String s : split1) {
                if (s.equals("35=AB")) {
                    condition = true;
                    found35 = "35=AB";
                    break;
                } else if (s.equals("35=AC")) {
                    condition = true;
                    found35 = "35=AC";
                    break;
                }
            }

            if (condition) {
                String repeatGroup = "";
                for (String val : split1) {
                    if (val.contains("447") || val.contains("448") || val.contains("452") || val.contains("453")) {
                        repeatGroup += val + "|";
                    }
                }
                if (repeatGroup.length()>0) {
                    repeatGroup = repeatGroup.substring(0, repeatGroup.length() - 1);
                    System.out.println(found35 + " Repeating groups are[" + repeatGroup + "]");
                } else {
                    System.out.println("No repeating groups found.");
                }
            }
        }
 
        
        for (String element : tg35) {
            System.out.println("tag35" + tg35);
        }
        for (String element : tg39) {
            System.out.println("tag39" + tg39);
        }for (String element : OrderFlow) {
            System.out.println("orderflow" + OrderFlow);
        }for (String element : rg) {
            System.out.println("repeating group" + rg);
        }
        for(String element : GTD) 
        {
        	if(element!="GTD"){
        			System.out.println("TIF IS"+element);
        			break;
        	}else {
        		System.out.println("TIF IS"+ element);
        		break;
        	}
        	
        }
 
    	
 
    }
}
Editor is loading...