-
Notifications
You must be signed in to change notification settings - Fork 35
Feat: allow args filtering #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AloisSeckar
merged 8 commits into
AloisSeckar:master
from
ab-schneider:feat/allow-args-filtering
Oct 27, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
881cc5b
refactor: move demos into a Map with jep key to enable future filtering
AlexShnaider 936ddd9
refactor(java12): align package name with naming convention
AlexShnaider 64fcc62
merge: add 4 new demos into updated demo list
AlexShnaider 7b47d4d
docs: fix Main method description
AlexShnaider bc2e3ac
refactor: fix full class name
AlexShnaider 64bdcf7
refactor: return to demo loading files for each java version instead …
AlexShnaider 2c7ac64
refactor: rename classes and folders per review feedback
AlexShnaider c6d12b8
merge: merge conflict add jep 377
AlexShnaider File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
158 changes: 158 additions & 0 deletions
158
src/main/java/org/javademos/commons/ArgsFilterUtil.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| package org.javademos.commons; | ||
|
|
||
| import org.javademos.init.JEPInfo.JEPData; | ||
|
|
||
| import java.util.*; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * Utility class for filtering and parsing command-line arguments | ||
| * that determine which JEP demos should be executed. | ||
| * <p> | ||
| * This class provides filtering logic based on various criteria | ||
| * such as JDK version, JEP number, and demo type (code or link-only). | ||
| * </p> | ||
| * | ||
| * <h3>Supported arguments and examples:</h3> | ||
| * <ul> | ||
| * <li><b>--skip-links</b> — Skip demos that only contain links to other JEPs.</li> | ||
| * <li><b>--code-only</b> — Run only demos that contain executable code.</li> | ||
| * <li><b>--jdk=17,25</b> — Run demos only from the specified JDK versions.</li> | ||
| * <li><b>--only=382,409</b> — Run only demos with the specified JEP numbers.</li> | ||
| * </ul> | ||
| * | ||
| * <h3>Multiple filters and examples:</h3> | ||
| * <p> | ||
| * Multiple filters can be combined. When multiple filters are specified, | ||
| * only demos that satisfy all active filters are executed. | ||
| * </p> | ||
| * | ||
| * <ul> | ||
| * <li><b>--jdk=24,25 --code-only</b></li> | ||
| * <li><b>--jdk=17,21 --skip-links</b></li> | ||
| * </ul> | ||
| * | ||
| * | ||
| * @author Alexander Schneider @ab-schneider | ||
| */ | ||
| public class ArgsFilterUtil { | ||
|
|
||
| private static final Set<Integer> jdkVersions = new HashSet<>(); | ||
| private static final Set<Integer> specificJeps = new HashSet<>(); | ||
| private static boolean skipLinks = false; | ||
| private static boolean codeOnly = false; | ||
|
|
||
| private static final String SKIP_LINKS = "--skip-links"; | ||
| private static final String CODE_ONLY = "--code-only"; | ||
| private static final String JDK = "--jdk="; | ||
| private static final String ONLY = "--only="; | ||
| private static final String DELIMITER = ","; | ||
|
|
||
| private ArgsFilterUtil() { | ||
| } | ||
|
|
||
| public static Map<Integer, JEPData> getFilteredJepData(String[] args, Map<Integer, JEPData> jepDataMap) { | ||
| parseArguments(args); | ||
| var filtered = filterJepData(jepDataMap); | ||
| printFilteredInfo(filtered); | ||
| return filtered; | ||
| } | ||
|
|
||
| private static void parseArguments(String[] args) { | ||
| for (String arg : args) { | ||
| if (SKIP_LINKS.equals(arg)) { | ||
| skipLinks = true; | ||
| } else if (CODE_ONLY.equals(arg)) { | ||
| codeOnly = true; | ||
| } else if (arg.startsWith(JDK)) { | ||
| String jdkValues = arg.substring(JDK.length()); | ||
| parseJdkVersions(jdkValues); | ||
| } else if (arg.startsWith(ONLY)) { | ||
| String jepValues = arg.substring(ONLY.length()); | ||
| parseSpecificJeps(jepValues); | ||
| } else { | ||
| throw new IllegalArgumentException("Unknown arg: " + arg); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void printFilteredInfo(Map<Integer, JEPData> filtered) { | ||
| System.out.println("\n=== FILTERED JEP INFORMATION ==="); | ||
|
|
||
| if (!skipLinks && !codeOnly && specificJeps.isEmpty() && jdkVersions.isEmpty()) { | ||
| System.out.println("No filters applied. Total JEPs found: " + filtered.size()); | ||
| } else { | ||
| if (skipLinks) { | ||
| var linkOnlyCount = filtered.values().stream() | ||
| .filter(jepData -> !jepData.link()) | ||
| .count(); | ||
| System.out.println("Skipped link demos. JEPs found: " + linkOnlyCount); | ||
| } | ||
|
|
||
| if (codeOnly) { | ||
| var codeOnlyCount = filtered.values().stream() | ||
| .filter(jepData -> !jepData.code()) | ||
| .count(); | ||
| System.out.println("Skipped no code demos. JEPs found: " + codeOnlyCount); | ||
| } | ||
|
|
||
| if (!jdkVersions.isEmpty()) { | ||
| System.out.println("JDK versions: " + jdkVersions); | ||
| } | ||
|
|
||
| if (!specificJeps.isEmpty()) { | ||
| System.out.println("Specific JEPs: " + specificJeps); | ||
| } | ||
| } | ||
|
|
||
| System.out.println("================================\n"); | ||
| } | ||
|
|
||
| private static void parseJdkVersions(String jdkValues) { | ||
| String[] versions = jdkValues.split(DELIMITER); | ||
| for (String version : versions) { | ||
| try { | ||
| jdkVersions.add(Integer.parseInt(version.trim())); | ||
| } catch (NumberFormatException e) { | ||
| throw new IllegalArgumentException("Invalid JDK version: " + version); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void parseSpecificJeps(String jepValues) { | ||
| String[] jeps = jepValues.split(DELIMITER); | ||
| for (String jep : jeps) { | ||
| try { | ||
| specificJeps.add(Integer.parseInt(jep.trim())); | ||
| } catch (NumberFormatException e) { | ||
| throw new IllegalArgumentException("Invalid JEP number: " + jep); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static Map<Integer, JEPData> filterJepData(Map<Integer, JEPData> jepDataMap) { | ||
| return jepDataMap.entrySet().stream() | ||
| .filter(entry -> matchesFilters(entry.getValue())) | ||
| .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
| } | ||
|
|
||
| private static boolean matchesFilters(JEPData jepData) { | ||
| if (skipLinks && jepData.link()) { | ||
| return false; | ||
| } | ||
|
|
||
| if (codeOnly && !jepData.code()) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!jdkVersions.isEmpty() && !jdkVersions.contains(jepData.jdk())) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!specificJeps.isEmpty() && !specificJeps.contains(jepData.jep())) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } |
This file contains hidden or 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
AloisSeckar marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.javademos.commons; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Interface for loading demos for a specific Java version. | ||
| */ | ||
| public interface IDemoLoader { | ||
|
|
||
| void loadDemos(Map<Integer, IDemo> demos); | ||
| } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.