| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
package joptsimple; |
| 7 | |
|
| 8 | |
import java.util.Collections; |
| 9 | |
import java.util.Iterator; |
| 10 | |
import java.util.List; |
| 11 | |
|
| 12 | |
import joptsimple.internal.Strings; |
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
public abstract class OptionException extends RuntimeException { |
| 22 | |
private final List options; |
| 23 | |
|
| 24 | 60 | protected OptionException( List options ) { |
| 25 | 60 | this.options = Collections.unmodifiableList( options ); |
| 26 | 60 | } |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public List options() { |
| 35 | 32 | return options; |
| 36 | |
} |
| 37 | |
|
| 38 | |
protected final String singleOptionMessage() { |
| 39 | 32 | return singleOptionMessage( (String) options.get( 0 ) ); |
| 40 | |
} |
| 41 | |
|
| 42 | |
protected final String singleOptionMessage( String option ) { |
| 43 | 60 | return Strings.SINGLE_QUOTE + option + Strings.SINGLE_QUOTE; |
| 44 | |
} |
| 45 | |
|
| 46 | |
protected final String multipleOptionMessage() { |
| 47 | 16 | StringBuffer buffer = new StringBuffer( "[" ); |
| 48 | 16 | for ( Iterator iter = options.iterator(); iter.hasNext(); ) { |
| 49 | 28 | buffer.append( singleOptionMessage( (String) iter.next() ) ); |
| 50 | 28 | if ( iter.hasNext() ) |
| 51 | 12 | buffer.append( ", " ); |
| 52 | |
} |
| 53 | 16 | buffer.append( ']' ); |
| 54 | |
|
| 55 | 16 | return buffer.toString(); |
| 56 | |
} |
| 57 | |
|
| 58 | |
static IllegalOptionClusterException illegalOptionCluster( String option ) { |
| 59 | 2 | return new IllegalOptionClusterException( option ); |
| 60 | |
} |
| 61 | |
|
| 62 | |
static UnrecognizedOptionException unrecognizedOption( String option ) { |
| 63 | 20 | return new UnrecognizedOptionException( option ); |
| 64 | |
} |
| 65 | |
} |