org.apache.commons.cli.Option.getType()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中org.apache.commons.cli.Option.getType()方法的一些代码示例,展示了Option.getType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.getType()方法的具体详情如下:
包路径:org.apache.commons.cli.Option
类名称:Option
方法名:getType

Option.getType介绍

[英]Retrieve the type of this Option.
[中]检索此选项的类型。

代码示例

代码示例来源:origin: commons-cli/commons-cli

/**
 * Return a version of this <code>Option</code> converted to a particular type. 
 *
 * @param opt the name of the option
 * @return the value parsed into a particular object
 * @throws ParseException if there are problems turning the option value into the desired type
 * @see PatternOptionBuilder
 * @since 1.2
 */
public Object getParsedOptionValue(String opt) throws ParseException
{
  String res = getOptionValue(opt);
  Option option = resolveOption(opt);
  
  if (option == null || res == null)
  {
    return null;
  }
  
  return TypeHandler.createValue(res, option.getType());
}

代码示例来源:origin: commons-cli/commons-cli

@Test
public void testCompleteOption( ) {
  Option simple = OptionBuilder.withLongOpt( "simple option")
                 .hasArg( )
                 .isRequired( )
                 .hasArgs( )
                 .withType( Float.class )
                 .withDescription( "this is a simple option" )
                 .create( 's' );
  assertEquals( "s", simple.getOpt() );
  assertEquals( "simple option", simple.getLongOpt() );
  assertEquals( "this is a simple option", simple.getDescription() );
  assertEquals( simple.getType(), Float.class );
  assertTrue( simple.hasArg() );
  assertTrue( simple.isRequired() );
  assertTrue( simple.hasArgs() );
}

代码示例来源:origin: commons-cli/commons-cli

@Test
public void testTwoCompleteOptions( ) {
  Option simple = OptionBuilder.withLongOpt( "simple option")
                 .hasArg( )
                 .isRequired( )
                 .hasArgs( )
                 .withType( Float.class )
                 .withDescription( "this is a simple option" )
                 .create( 's' );
  assertEquals( "s", simple.getOpt() );
  assertEquals( "simple option", simple.getLongOpt() );
  assertEquals( "this is a simple option", simple.getDescription() );
  assertEquals( simple.getType(), Float.class );
  assertTrue( simple.hasArg() );
  assertTrue( simple.isRequired() );
  assertTrue( simple.hasArgs() );
  simple = OptionBuilder.withLongOpt( "dimple option")
             .hasArg( )
             .withDescription( "this is a dimple option" )
             .create( 'd' );
  assertEquals( "d", simple.getOpt() );
  assertEquals( "dimple option", simple.getLongOpt() );
  assertEquals( "this is a dimple option", simple.getDescription() );
  assertEquals( String.class, simple.getType() );
  assertTrue( simple.hasArg() );
  assertTrue( !simple.isRequired() );
  assertTrue( !simple.hasArgs() );
}

代码示例来源:origin: commons-cli/commons-cli

private static void checkOption(Option option, String opt, String description, String longOpt, int numArgs,
                String argName,  boolean required, boolean optionalArg,
                char valueSeparator, Class<?> cls)
{
  assertEquals(opt, option.getOpt());
  assertEquals(description, option.getDescription());
  assertEquals(longOpt, option.getLongOpt());
  assertEquals(numArgs, option.getArgs());
  assertEquals(argName, option.getArgName());
  assertEquals(required, option.isRequired());
  assertEquals(optionalArg, option.hasOptionalArg());
  assertEquals(valueSeparator, option.getValueSeparator());
  assertEquals(cls,  option.getType());
}

代码示例来源:origin: cytoscape.corelibs/commons-cli-1-x-cytocape-custom

/**
 * Return the <code>Object</code> type of this <code>Option</code>.
 *
 * @param opt the name of the option
 * @return the type of this <code>Option</code>
 */
public Object getOptionObject(String opt) {
  String res = getOptionValue(opt);
  if (!options.containsKey(opt)) {
    return null;
  }
  Object type = ((Option) options.get(opt)).getType();
  return (res == null) ? null : TypeHandler.createValue(res, type);
}

代码示例来源:origin: org.cytoscape/cy-commons-cli

/**
 * Return the <code>Object</code> type of this <code>Option</code>.
 *
 * @param opt the name of the option
 * @return the type of this <code>Option</code>
 */
public Object getOptionObject(String opt) {
  String res = getOptionValue(opt);
  if (!options.containsKey(opt)) {
    return null;
  }
  Object type = options.get(opt).getType();
  return (res == null) ? null : TypeHandler.createValue(res, type);
}

代码示例来源:origin: leonchen83/redis-rdb-cli

public <T> List<T> getOptions(String opt) throws ParseException {
  String[] res = line.getOptionValues(opt);
  Option option = resolveOption(opt);
  if (option == null || res == null) {
    return new ArrayList<>();
  }
  
  Class<?> clazz = (Class<?>) option.getType();
  List<T> list = new ArrayList<>();
  for (int i = 0; i < res.length; i++) {
    T val = getOption(res[i], clazz);
    list.add(val);
  }
  return list;
}

代码示例来源:origin: sdedit/sdedit

/**
 * Return a version of this <code>Option</code> converted to a particular type. 
 *
 * @param opt the name of the option
 * @return the value parsed into a particluar object
 * @throws ParseException if there are problems turning the option value into the desired type
 * @see PatternOptionBuilder
 */
public Object getParsedOptionValue(String opt)
throws ParseException
{
  String res = getOptionValue(opt);
  Option option = resolveOption(opt);
  if (option == null)
  {
    return null;
  }
  Object type = option.getType();
  return (res == null)        ? null : TypeHandler.createValue(res, type);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Return a version of this <code>Option</code> converted to a particular type. 
 *
 * @param opt the name of the option
 * @return the value parsed into a particular object
 * @throws ParseException if there are problems turning the option value into the desired type
 * @see PatternOptionBuilder
 * @since 1.2
 */
public Object getParsedOptionValue(String opt) throws ParseException
{
  String res = getOptionValue(opt);
  Option option = resolveOption(opt);
  
  if (option == null || res == null)
  {
    return null;
  }
  
  return TypeHandler.createValue(res, option.getType());
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.cli

/**
 * Return a version of this <code>Option</code> converted to a particular type. 
 *
 * @param opt the name of the option
 * @return the value parsed into a particluar object
 * @throws ParseException if there are problems turning the option value into the desired type
 * @see PatternOptionBuilder
 */
public Object getParsedOptionValue(String opt)
throws ParseException
{
  String res = getOptionValue(opt);
  Option option = resolveOption(opt);
  if (option == null)
  {
    return null;
  }
  Object type = option.getType();
  return (res == null)        ? null : TypeHandler.createValue(res, type);
}

代码示例来源:origin: eu.fbk.utils/utils-core

if (values != null) {
  for (final String value : values) {
    if (option.getType() instanceof Type) {
      Type.validate(value, (Type) option.getType());

代码示例来源:origin: com.marklogic/mlcp

public CommandlineOption(Option opt)
    throws IllegalArgumentException {
  super(opt.getOpt(), opt.hasArg(), opt.getDescription());
  this.setLongOpt(opt.getLongOpt());
  this.setRequired(opt.isRequired());
  this.setArgName(opt.getArgName());
  this.setArgs(opt.getArgs());
  this.setOptionalArg(opt.hasOptionalArg());
  this.setType(opt.getType());
  this.setValueSeparator(opt.getValueSeparator());
}

相关文章