Untitled

 avatar
unknown
java
2 years ago
3.1 kB
4
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);
        String input1 = sc.nextLine();
        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");
        }};
        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] + " ");  
    }  
    //System.out.println();
    Map<String, String> matchMap = new HashMap<>();
    
    for (String s : split1) {
    if (s.contains("35=") || s.contains("150=") || s.contains("39=")) {
        matchMap.put(s, mp.get(s));
    }
    if(s.contains("35=8")) {
        cond=true;
    }
}
String searchValue = "35=";
List<String> newArr = new ArrayList<>();
//System.out.print(matchMap);
if(cond==false)
{
    boolean found=false;
    for (String key : matchMap.keySet()) {
        if (key.contains(searchValue)) {
            list1.add(mp.get(key));
            found=true;
            break;
        } 
    }
    if(!found) {
        System.out.println("The Tag containing the value is not present ");
    }
}
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{
    list1.add(mp.get(newList.get(1)));
}
for (String element : list1) {
    System.out.println(element);
	}
	}
        }

    
    }
  }
Editor is loading...