Created
December 20, 2023 12:41
-
-
Save johannest/6e82fbbda22bc35feb9dc8a4034d488c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
public class parse { | |
public static void main(String[] args) { | |
String filePath = "/Users/johannestuikkala/Desktop/test.txt"; | |
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { | |
String line; | |
String component = ""; | |
while ((line = br.readLine()) != null) { | |
if (line.matches("^[A-Z].{4,}$")) { | |
String[] splitss = line.trim().split("\\s+"); | |
component = splitss[0]; | |
} | |
int coverage = -1; | |
int total = -1; | |
if (line.contains(" total ") && component != "") { | |
String[] splits = line.trim().split("\\s+\\s+"); | |
for (String split : splits) { | |
try { | |
int value = Integer.parseInt(split.trim().replaceAll("\\s+", "")); | |
if (coverage == -1) { | |
coverage = value; | |
} else { | |
total = value; | |
} | |
} catch (NumberFormatException e) { | |
// Ignore non-integer values | |
} | |
} | |
System.out.println(component + ";" + coverage + ";" + total); | |
component = ""; | |
} | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment