Coverage Report - joptsimple.OptionSpec
 
Classes in this File Line Coverage Branch Coverage Complexity
OptionSpec
N/A
N/A
1
 
 1  
 /*
 2  
  The MIT License
 3  
 
 4  
  Copyright (c) 2004-2015 Paul R. Holser, Jr.
 5  
 
 6  
  Permission is hereby granted, free of charge, to any person obtaining
 7  
  a copy of this software and associated documentation files (the
 8  
  "Software"), to deal in the Software without restriction, including
 9  
  without limitation the rights to use, copy, modify, merge, publish,
 10  
  distribute, sublicense, and/or sell copies of the Software, and to
 11  
  permit persons to whom the Software is furnished to do so, subject to
 12  
  the following conditions:
 13  
 
 14  
  The above copyright notice and this permission notice shall be
 15  
  included in all copies or substantial portions of the Software.
 16  
 
 17  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 18  
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 19  
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 20  
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 21  
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 22  
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 23  
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 24  
 */
 25  
 
 26  
 package joptsimple;
 27  
 
 28  
 import java.util.List;
 29  
 
 30  
 /**
 31  
  * Describes options that an option parser recognizes.
 32  
  *
 33  
  * <p>Instances of this interface are returned by the "fluent interface" methods to allow retrieval of option arguments
 34  
  * in a type-safe manner.  Here's an example:</p>
 35  
  * 
 36  
  * <pre><code>
 37  
  *     OptionParser parser = new OptionParser();
 38  
  *     <strong>OptionSpec&lt;Integer&gt;</strong> count =
 39  
  *         parser.accepts( "count" ).withRequiredArg().ofType( Integer.class );
 40  
  *     OptionSet options = parser.parse( "--count", "2" );
 41  
  *     assert options.has( count );
 42  
  *     int countValue = options.valueOf( count );
 43  
  *     assert countValue == count.value( options );
 44  
  *     List&lt;Integer&gt; countValues = options.valuesOf( count );
 45  
  *     assert countValues.equals( count.values( options ) );
 46  
  * </code></pre>
 47  
  *
 48  
  * @param <V> represents the type of the arguments this option accepts
 49  
  * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
 50  
  */
 51  
 public interface OptionSpec<V> {
 52  
     /**
 53  
      * Gives any arguments associated with the given option in the given set of detected options.
 54  
      *
 55  
      * <p>Specifying a {@linkplain ArgumentAcceptingOptionSpec#defaultsTo(Object, Object[]) default argument value}
 56  
      * for this option will cause this method to return that default value even if this option was not detected on the
 57  
      * command line, or if this option can take an optional argument but did not have one on the command line.</p>
 58  
      *
 59  
      * @param detectedOptions the detected options to search in
 60  
      * @return the arguments associated with this option; an empty list if no such arguments are present, or if this
 61  
      * option was not detected
 62  
      * @throws OptionException if there is a problem converting this option's arguments to the desired type; for
 63  
      * example, if the type does not implement a correct conversion constructor or method
 64  
      * @throws NullPointerException if {@code detectedOptions} is {@code null}
 65  
      * @see OptionSet#valuesOf(OptionSpec)
 66  
      */
 67  
     List<V> values( OptionSet detectedOptions );
 68  
 
 69  
     /**
 70  
      * Gives the argument associated with the given option in the given set of detected options.
 71  
      *
 72  
      * <p>Specifying a {@linkplain ArgumentAcceptingOptionSpec#defaultsTo(Object, Object[]) default argument value}
 73  
      * for this option will cause this method to return that default value even if this option was not detected on the
 74  
      * command line, or if this option can take an optional argument but did not have one on the command line.</p>
 75  
      *
 76  
      * @param detectedOptions the detected options to search in
 77  
      * @return the argument of the this option; {@code null} if no argument is present, or that option was not detected
 78  
      * @throws OptionException if more than one argument was detected for the option
 79  
      * @throws NullPointerException if {@code detectedOptions} is {@code null}
 80  
      * @throws ClassCastException if the arguments of this option are not of the expected type
 81  
      * @see OptionSet#valueOf(OptionSpec)
 82  
      */
 83  
     V value( OptionSet detectedOptions );
 84  
 
 85  
     /**
 86  
      * @return the string representations of this option
 87  
      */
 88  
     List<String> options();
 89  
 
 90  
     /**
 91  
      * Tells whether this option is designated as a "help" option. The presence of a "help" option on a command line
 92  
      * means that missing "required" options will not cause parsing to fail.
 93  
      *
 94  
      * @return whether this option is designated as a "help" option
 95  
      */
 96  
     boolean isForHelp();
 97  
 }