List of usage examples for com.google.common.collect Lists charactersOf
@Beta public static List<Character> charactersOf(CharSequence sequence)
From source file:se.softhouse.jargo.CommandLineParserInstance.java
/** * Batch of short-named optional arguments * For instance, "-fs" was used instead of "-f -s" */// w ww .j a v a2s . com private Argument<?> batchOfShortNamedArguments(ArgumentIterator arguments, ParsedArguments holder) throws ArgumentException { String currentArgument = arguments.current(); if (startsWithAndHasMore(currentArgument, "-")) { List<Character> givenCharacters = Lists.charactersOf(currentArgument.substring(1)); Set<Argument<?>> foundOptions = newLinkedHashSetWithExpectedSize(givenCharacters.size()); Argument<?> lastOption = null; for (Character optionName : givenCharacters) { lastOption = namedArguments.get("-" + optionName); if (lastOption == null || lastOption.parser().parameterArity() != NO_ARGUMENTS || !foundOptions.add(lastOption)) { // Abort as soon as an unexpected character is discovered break; } } // Only accept the argument if all characters could be matched and no duplicate // characters were found if (foundOptions.size() == givenCharacters.size()) { // The last option is handled with the return foundOptions.remove(lastOption); // A little ugly that this get method has side-effects but the alternative is to // return a list of arguments to parse and as this should be a rare case it's not // worth it, the result is the same at least for (Argument<?> option : foundOptions) { parseArgument(arguments, holder, option, null); } return lastOption; } } return null; }