Coverage Report - joptsimple.OptionException
 
Classes in this File Line Coverage Branch Coverage Complexity
OptionException
100%
15/15
100%
4/4
1.286
 
 1  
 /*
 2  
  Copyright 2004-2008 Paul R. Holser, Jr.  All rights reserved.
 3  
  Licensed under the Academic Free License version 3.0
 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  
  * <p>Thrown when a problem occurs during option parsing.</p>
 16  
  *
 17  
  * @since 1.0
 18  
  * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
 19  
  * @version $Id: OptionException.java,v 1.5 2008/05/22 14:22:33 pholser Exp $
 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  
      * <p>Gives the option being considered when the exception was created.</p>
 30  
      *
 31  
      * @since 2.1
 32  
      * @return the option being considered when the exception was created
 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  
 }