1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package com.lexicalscope.jewel.cli.validation; |
16 | |
|
17 | |
import java.util.ArrayList; |
18 | |
import java.util.List; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import com.lexicalscope.jewel.cli.specification.OptionsSpecification; |
22 | |
import com.lexicalscope.jewel.cli.specification.ParsedOptionSpecification; |
23 | |
|
24 | |
|
25 | |
class OptionCollectionImpl implements OptionCollection |
26 | |
{ |
27 | |
private final OptionsSpecification<?> specification; |
28 | |
private final Map<ParsedOptionSpecification, List<String>> arguments; |
29 | |
private final List<String> unparsed; |
30 | |
|
31 | |
public OptionCollectionImpl( |
32 | |
final OptionsSpecification<?> specification, |
33 | |
final Map<ParsedOptionSpecification, |
34 | |
List<String>> arguments, |
35 | |
final List<String> unparsed) |
36 | 160 | { |
37 | 160 | this.specification = specification; |
38 | 160 | this.arguments = arguments; |
39 | 160 | this.unparsed = unparsed; |
40 | 160 | } |
41 | |
|
42 | |
@Override public List<String> getUnparsed() |
43 | |
{ |
44 | 56 | return new ArrayList<String>(unparsed); |
45 | |
} |
46 | |
|
47 | |
@Override public Argument getArgument(final ParsedOptionSpecification option) { |
48 | 274 | if (arguments.containsKey(option)) { |
49 | 162 | return new ArgumentImpl(option, arguments.get(option)); |
50 | |
} |
51 | 112 | return null; |
52 | |
} |
53 | |
|
54 | |
@Override public List<String> getValues(final String... options) |
55 | |
{ |
56 | 6 | for (final String option : options) |
57 | |
{ |
58 | 6 | final ParsedOptionSpecification optionSpecification = specification.getSpecification(option); |
59 | 6 | if (arguments.containsKey(optionSpecification)) |
60 | |
{ |
61 | 6 | return arguments.get(optionSpecification); |
62 | |
} |
63 | |
} |
64 | 0 | return null; |
65 | |
} |
66 | |
} |