-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2019(misc): make tasks discoverable by annotation
- Loading branch information
1 parent
6408324
commit 0e17d78
Showing
23 changed files
with
248 additions
and
238 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,24 @@ | ||
package se.augustocesar.aoc2019; | ||
|
||
import se.augustocesar.aoc2019.day01.Day01; | ||
import se.augustocesar.aoc2019.day02.Day02; | ||
import se.augustocesar.aoc2019.day03.Day03; | ||
import se.augustocesar.aoc2019.day04.Day04; | ||
import se.augustocesar.aoc2019.day05.Day05; | ||
import se.augustocesar.aoc2019.day06.Day06; | ||
import se.augustocesar.aoc2019.day07.Day07; | ||
import se.augustocesar.aoc2019.day08.Day08; | ||
import se.augustocesar.aoc2019.day09.Day09; | ||
import se.augustocesar.aoc2019.day10.Day10; | ||
import se.augustocesar.aoc2019.day11.Day11; | ||
import se.augustocesar.aoc2019.day12.Day12; | ||
import se.augustocesar.aoc2019.day13.Day13; | ||
import se.augustocesar.aoc2019.day14.Day14; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
import se.augustocesar.aoc2019.task.Task; | ||
import se.augustocesar.aoc2019.task.TaskLoader; | ||
|
||
public class Main { | ||
|
||
protected static final Map<Integer, Supplier<Task>> availableDays = buildAvailableDaysMap(); | ||
|
||
public static void main(String[] args) { | ||
if (args.length < 1) { | ||
System.err.println("Invalid amount of args."); | ||
System.exit(1); | ||
throw new IllegalArgumentException("Invalid amount of args"); | ||
} | ||
|
||
int dayInt = Integer.parseInt(args[0]); | ||
final Optional<Task> day = getDay(dayInt); | ||
final int dayArg = Integer.parseInt(args[0]); | ||
final HashMap<Integer, Task> availableTasks = new TaskLoader("se.augustocesar.aoc2019") | ||
.registeredTasks(); | ||
|
||
if (day.isEmpty()) { | ||
System.err.println("Day not found."); | ||
System.exit(1); | ||
return; | ||
if (!availableTasks.containsKey(dayArg)) { | ||
throw new RuntimeException(String.format("Day %d not found", dayArg)); | ||
} | ||
|
||
day.get().run(); | ||
} | ||
|
||
private static HashMap<Integer, Supplier<Task>> buildAvailableDaysMap() { | ||
HashMap<Integer, Supplier<Task>> availableDays = new HashMap<>(); | ||
availableDays.put(1, Day01::new); | ||
availableDays.put(2, Day02::new); | ||
availableDays.put(3, Day03::new); | ||
availableDays.put(4, Day04::new); | ||
availableDays.put(5, Day05::new); | ||
availableDays.put(6, Day06::new); | ||
availableDays.put(7, Day07::new); | ||
availableDays.put(8, Day08::new); | ||
availableDays.put(9, Day09::new); | ||
availableDays.put(10, Day10::new); | ||
availableDays.put(11, Day11::new); | ||
availableDays.put(12, Day12::new); | ||
availableDays.put(13, Day13::new); | ||
availableDays.put(14, Day14::new); | ||
return availableDays; | ||
} | ||
|
||
public static Optional<Task> getDay(final int dayInt) { | ||
return Optional.ofNullable(availableDays.get(dayInt).get()); | ||
availableTasks.get(dayArg).run(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
53 changes: 26 additions & 27 deletions
53
2019/src/main/java/se/augustocesar/aoc2019/day01/Day01.java
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
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
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
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
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
Oops, something went wrong.