Class PuzzleInput
java.lang.Object
com.expedient.adventofcodejade.common.PuzzleInput
-
Method Summary
Modifier and TypeMethodDescriptionallMatchesPerLine(Predicate<Character> test, Function<Character, T> conversion, Function<String, String> transform) Converts each line to a list of type T values, after iterating over each Character in the line and applying a provided filter function.Converts all starting lines with numbers separated by '|' characters into Pairs of Integers, then creates a List of Lists containing Integers based on the comma separated lists of numbers in the second half of the input, separated from the first section by a blank linestatic PuzzleInputConstructs a PuzzleInput from a given filesystem pathstatic PuzzleInputfromResource(String resourcePath) Constructs a PuzzleInput from the given resource pathgetGrid()Returns the input as a rectangular 2D array of Character.getLines()Get the lines from the fileGet the input as a single string, rather than as a list of linesgetTwoLists(Function<String, T> conversion, String delimiterRegex) Return two lists based on split lines from the inputbooleanisTest()static PuzzleInputsampleForDay(int year, int day, boolean partOne) Gets a PuzzleInput using the resource for a specific day (located in /src/main/resources).
-
Method Details
-
fromPath
Constructs a PuzzleInput from a given filesystem path- Parameters:
inputPath- path where the input is located- Returns:
- PuzzleInput object that contains the file's contents
- Throws:
IOException- when the file is not found
-
fromResource
Constructs a PuzzleInput from the given resource path- Parameters:
resourcePath- path of resource (contained in /src/main/resources)- Returns:
- PuzzleInput object that contains the resource's contents
- Throws:
IOException- when the given resource can't be loaded
-
sampleForDay
Gets a PuzzleInput using the resource for a specific day (located in /src/main/resources). Will first attempt to find sample input with the naming scheme [day]-[part] in case sample differs between parts 1 and 2, otherwise falls back to input with the naming scheme [day]- Parameters:
day- day for which the input is loadedpartOne- whether the sample is being fetched for part one- Returns:
- PuzzleInput object containing the given day's sample input
- Throws:
IOException- when the given day's input cannot be found in resources
-
isTest
public boolean isTest() -
getLines
-
getString
Get the input as a single string, rather than as a list of lines- Returns:
- String containing the entire input
-
getTwoLists
Return two lists based on split lines from the input- Type Parameters:
T- the type contained within the returned lists- Parameters:
conversion- function used to convert the string into a type of your choicedelimiterRegex- delimiter used to split the lines- Returns:
- two lists, composed of the elements that were split from each input
-
allMatchesPerLine
public <T> List<List<T>> allMatchesPerLine(Predicate<Character> test, Function<Character, T> conversion, Function<String, String> transform) Converts each line to a list of type T values, after iterating over each Character in the line and applying a provided filter function. Optionally can apply a transformation to the line string before running the filter.- Type Parameters:
T- The desired output type for the operation- Parameters:
test- Test to determine whether a given value will be included in the list for each lineconversion- Function to convert the Character value to type Ttransform- Function to apply to each line before processing it. If this is null, the transformation step is skipped- Returns:
- List of lists composed of values from each line matching the test function and converted to type T
-
getGrid
Returns the input as a rectangular 2D array of Character. Can't use generics because generic array creation is not possible. The input must not be empty and must be composed of equally sized rows.- Returns:
- 2D array of Character derived from input
- Throws:
IllegalArgumentException- if the array would be ragged / the rows are of differing lengths
-
day5Input
Converts all starting lines with numbers separated by '|' characters into Pairs of Integers, then creates a List of Lists containing Integers based on the comma separated lists of numbers in the second half of the input, separated from the first section by a blank line- Returns:
- A Pair containing the List of Pairs of Integers, as well as the List of Lists of Integers
-