From e786ef2c555381c17b89a0ee724a6d0e863d8809 Mon Sep 17 00:00:00 2001 From: Eoghan Conlon Date: Sun, 1 Dec 2024 23:55:06 +0000 Subject: [PATCH] Initial Commit --- .gitignore | 33 ++++++++++++++++++++++++++++++ AoC_2024_java.iml | 11 ++++++++++ src/Input.java | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 .gitignore create mode 100644 AoC_2024_java.iml create mode 100644 src/Input.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..920e61a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ +.idea/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store + +### AoC ### +in/ \ No newline at end of file diff --git a/AoC_2024_java.iml b/AoC_2024_java.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/AoC_2024_java.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Input.java b/src/Input.java new file mode 100644 index 0000000..77207e7 --- /dev/null +++ b/src/Input.java @@ -0,0 +1,52 @@ +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.stream.Stream; + +/** + * @author Eoghan Conlon + * This class is a base class for my Advent of Code in Java, it will be extended by the full projects. + */ +public class Input { + + /// String arrays generated from the files + private ArrayList sample_input; + private ArrayList actual_input; + + /** + * + * @param filePath Path to the folder where the files for the elevent days are located + * @return Exit Code - (0 if successful, non-zreo if fail) + */ + protected int init(String filePath) throws IOException { + // Adding the sample txt file and input txt files to the file path + Path samplePath = Path.of(filePath + "/sample.txt"); + Path actualPath = Path.of(filePath + "/input.txt"); + + this.sample_input = new ArrayList<>(); + this.actual_input = new ArrayList<>(); + + // Opening the files + try(Stream lines = Files.lines(samplePath)){ + lines.forEach(s -> sample_input.add(s)); + } catch (IOException e) { + return 1; + } + + try(Stream lines = Files.lines(actualPath)){ + lines.forEach(s -> actual_input.add(s)); + } catch (IOException e) { + return 1; + } + return 0; + } + + protected ArrayList getSample_input(){ + return sample_input; + } + + protected ArrayList getInput(){ + return actual_input; + } +}