Coverage Report - joptsimple.OptionalArgumentOptionSpec
 
Classes in this File Line Coverage Branch Coverage Complexity
OptionalArgumentOptionSpec
100%
21/21
100%
10/10
1.8
 
 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.List;
 9  
 
 10  
 /**
 11  
  * <p>Specification of an option that accepts an optional argument.</p>
 12  
  *
 13  
  * @since 1.0
 14  
  * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
 15  
  * @version $Id: OptionalArgumentOptionSpec.java,v 1.5 2008/05/01 15:38:45 pholser Exp $
 16  
  */
 17  
 class OptionalArgumentOptionSpec extends ArgumentAcceptingOptionSpec {
 18  
     OptionalArgumentOptionSpec( String option ) {
 19  98
         super( option, false );
 20  98
     }
 21  
 
 22  
     OptionalArgumentOptionSpec( List options, String description ) {
 23  142
         super( options, false, description );
 24  142
     }
 25  
 
 26  
     protected void detectOptionArgument( OptionParser parser, ArgumentList arguments,
 27  
         OptionSet detectedOptions ) {
 28  
 
 29  88
         if ( arguments.hasMore() ) {
 30  76
             String nextArgument = arguments.peek();
 31  
 
 32  76
             if ( !parser.looksLikeAnOption( nextArgument ) )
 33  52
                 handleOptionArgument( parser, detectedOptions, arguments );
 34  24
             else if ( isArgumentOfNumberType() && canConvertArgument( nextArgument ) )
 35  8
                 addArguments( detectedOptions, arguments.next() );
 36  
             else
 37  16
                 detectedOptions.addAll( options() );
 38  76
         }
 39  
         else
 40  12
             detectedOptions.addAll( options() );
 41  88
     }
 42  
 
 43  
     private void handleOptionArgument( OptionParser parser, OptionSet detectedOptions,
 44  
         ArgumentList arguments ) {
 45  
 
 46  52
         if ( parser.posixlyCorrect() ) {
 47  6
             detectedOptions.addAll( options() );
 48  6
             parser.noMoreOptions();
 49  
         }
 50  
         else
 51  46
             addArguments( detectedOptions, arguments.next() );
 52  52
     }
 53  
 
 54  
     void accept( OptionSpecVisitor visitor ) {
 55  10
         visitor.visit( this );
 56  10
     }
 57  
 }