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()); }
@Override @SuppressWarnings("unchecked") public <T> List<T> getOptionValues(String name) { Option option = cli.getOption(name); if (option == null) { return null; } if (option instanceof TypedOption) { TypedOption<T> typed = (TypedOption<T>) option; if (typed.isParsedAsList()) { return createFromList(getRawValueForOption(option), typed); } else { return getRawValuesForOption(option).stream().map(s -> create(s, typed)) .collect(Collectors.toList()); } } else { return (List<T>) getRawValuesForOption(option); } }
/** * Gets the values of an argument with the matching index. * * @param index the index * @return the values, {@code null} if not set * @see #getArgumentValue(int) * @see #getRawValueForArgument(Argument) */ @Override @SuppressWarnings("unchecked") public <T> List<T> getArgumentValues(int index) { Argument argument = cli.getArgument(index); if (argument == null) { return null; } if (argument instanceof TypedArgument) { TypedArgument<T> typed = (TypedArgument<T>) argument; return getRawValuesForArgument(typed).stream().map(s -> create(s, typed)) .collect(Collectors.toList()); } else { return (List<T>) getRawValuesForArgument(argument); } }
@Override @SuppressWarnings("unchecked") public <T> List<T> getOptionValues(String name) { Option option = cli.getOption(name); if (option == null) { return null; } if (option instanceof TypedOption) { TypedOption<T> typed = (TypedOption<T>) option; if (typed.isParsedAsList()) { return createFromList(getRawValueForOption(option), typed); } else { return getRawValuesForOption(option).stream().map(s -> create(s, typed)) .collect(Collectors.toList()); } } else { return (List<T>) getRawValuesForOption(option); } }
@Override @SuppressWarnings("unchecked") public <T> T getArgumentValue(int index) { Argument arg = cli.getArgument(index); if (arg == null) { return null; } if (arg instanceof TypedArgument) { return create(getRawValueForArgument(arg), (TypedArgument<T>) arg); } else { return (T) getRawValueForArgument(arg); } }
private <T> T getValue(TypedOption<T> option) { if (isOptionAssigned(option)) { return create(getRawValueForOption(option), option); } else { if (option.getDefaultValue() != null) { return create(getRawValueForOption(option), option); } if (option.isFlag() || isBoolean(option)) { try { if (isSeenInCommandLine(option)) { return (T) Boolean.TRUE; } else { return (T) Boolean.FALSE; } } catch (InvalidValueException e) { throw new IllegalArgumentException(e); } } } return null; }
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()); }
/** * Gets the values of an argument with the matching index. * * @param index the index * @return the values, {@code null} if not set * @see #getArgumentValue(int) * @see #getRawValueForArgument(Argument) */ @Override @SuppressWarnings("unchecked") public <T> List<T> getArgumentValues(int index) { Argument argument = cli.getArgument(index); if (argument == null) { return null; } if (argument instanceof TypedArgument) { TypedArgument<T> typed = (TypedArgument<T>) argument; return getRawValuesForArgument(typed).stream().map(s -> create(s, typed)) .collect(Collectors.toList()); } else { return (List<T>) getRawValuesForArgument(argument); } }
@Override @SuppressWarnings("unchecked") public <T> T getArgumentValue(int index) { Argument arg = cli.getArgument(index); if (arg == null) { return null; } if (arg instanceof TypedArgument) { return create(getRawValueForArgument(arg), (TypedArgument<T>) arg); } else { return (T) getRawValueForArgument(arg); } }
private <T> T getValue(TypedOption<T> option) { if (isOptionAssigned(option)) { return create(getRawValueForOption(option), option); } else { if (option.getDefaultValue() != null) { return create(getRawValueForOption(option), option); } if (option.isFlag() || isBoolean(option)) { try { if (isSeenInCommandLine(option)) { return (T) Boolean.TRUE; } else { return (T) Boolean.FALSE; } } catch (InvalidValueException e) { throw new IllegalArgumentException(e); } } } return null; }