public static <T> List<T> createFromList(String raw, TypedOption<T> option) { if (raw == null) { return Collections.emptyList(); } final String[] segments = raw.split(option.getListSeparator()); return Arrays.stream(segments).map(s -> create(s.trim(), option)).collect(Collectors.toList()); }
/** * Creates an instance of {@link TypedOption} by copying the state of another {@link TypedOption} * * @param option the copied option */ public TypedOption(TypedOption<T> option) { super(option); this.type = option.getType(); this.converter = option.getConverter(); this.parsedAsList = option.isParsedAsList(); this.listSeparator = option.getListSeparator(); }
@Test public void testOptionsParsedAsList() { CLI command = CLIConfigurator.define(CommandForParsedAsList.class); assertThat(command.getOptions()).hasSize(1); assertThat(((TypedOption) find(command.getOptions(), "option")) .getListSeparator()).isEqualTo(":"); assertThat(find(command.getOptions(), "option").isMultiValued()).isTrue(); assertThat(((TypedOption) find(command.getOptions(), "option")).getType()) .isEqualTo(String.class); }
public static <T> List<T> createFromList(String raw, TypedOption<T> option) { if (raw == null) { return Collections.emptyList(); } final String[] segments = raw.split(option.getListSeparator()); return Arrays.stream(segments).map(s -> create(s.trim(), option)).collect(Collectors.toList()); }
/** * Creates an instance of {@link TypedOption} by copying the state of another {@link TypedOption} * * @param option the copied option */ public TypedOption(TypedOption<T> option) { super(option); this.type = option.getType(); this.converter = option.getConverter(); this.parsedAsList = option.isParsedAsList(); this.listSeparator = option.getListSeparator(); }
@Test public void testOptionsParsedAsList() { CLI command = CLIConfigurator.define(CommandForParsedAsList.class); assertThat(command.getOptions()).hasSize(1); assertThat(((TypedOption) find(command.getOptions(), "option")) .getListSeparator()).isEqualTo(":"); assertThat(find(command.getOptions(), "option").isMultiValued()).isTrue(); assertThat(((TypedOption) find(command.getOptions(), "option")).getType()) .isEqualTo(String.class); }