示例#1
0
  /**
   * Entries of pArgDefs are as follows: [0] long name (String) [1] short name (String) [2] has
   * value? (Boolean) [3] default value, if any (Object) [4] possible (enum) values if any (String[]
   * or collection)
   *
   * <p>Of these, 0-2 are mandarory.
   */
  public ArgsDef(
      Object[][] pArgDefs, String[] pNonOptParamNames, Collection<String> pNamesOfOptsToInclude) {
    ArrayList<OptDef> argDefs = new ArrayList();
    for (Object[] raw : pArgDefs) {
      OptDef def = new OptDef(raw);
      argDefs.add(def);
    }

    if (pNonOptParamNames == null) {
      pNonOptParamNames = new String[0];
    }

    init(argDefs, Arrays.asList(pNonOptParamNames), pNamesOfOptsToInclude);

    //        mShortNameToLongNameMap = new LinkedHashMap();
    //        mNamesOfOptionsRequiringValue = new LinkedHashSet();
    //        mOptionsWithoutShortName = new LinkedHashSet();
    //        mValidOptionNames = new LinkedHashSet();
    //        mDefaultValues = new LinkedHashMap();
    //        mPossibleValues = new MultiMap();
    //        mNonOptParamNames = pNonOptParamNames;
    //
    //        for (int i=0; i<pArgDefs.length; i++) {
    //            Object[] argDef = pArgDefs[i];
    //            String longname = (String)argDef[0];
    //            if (pNamesOfOptsToInclude != null && !(pNamesOfOptsToInclude.contains(longname)))
    // {
    //            	continue;
    //            }
    //            String shortname = (String)argDef[1];
    //            boolean hasValue = ((Boolean)argDef[2]).booleanValue();
    //            if (mShortNameToLongNameMap.containsKey(shortname)) {
    //            	throw new RuntimeException("Duplicate short name: "+shortname);
    //            }
    //            String defaultValue = (argDef.length >= 4 && argDef[3] != null) ? ""+argDef[3] :
    // null;
    //
    //            Collection<String> possibleValues = null;
    //            if (argDef.length >= 5) {
    //            	if (argDef[4] instanceof String[]) {
    //            		possibleValues = Arrays.asList((String[])argDef[4]);
    //            	}
    //            	else if (argDef[4] instanceof Collection) {
    //            		possibleValues = (Collection)argDef[4];
    //            	}
    //            	else {
    //            		throw new RuntimeException("Unrecognized enum def: "+argDef[4]);
    //            	}
    //            }
    //
    //            mValidOptionNames.add(longname);
    //            if (shortname != null) {
    //                mValidOptionNames.add(shortname);
    //                mShortNameToLongNameMap.put(shortname, longname);
    //            }
    //            else {
    //                mOptionsWithoutShortName.add(longname);
    //            }
    //            if (hasValue) {
    //                mNamesOfOptionsRequiringValue.add(longname);
    //            }
    //            if (defaultValue != null) {
    //                // a little sanity check, if you permit...
    //                if (!hasValue) {
    //                    throw new RuntimeException("Illegal situation: parameter "+longname+" has
    // no value, but still has default value "+defaultValue);
    //                }
    //                mDefaultValues.put(longname, defaultValue);
    //            }
    //            if (possibleValues != null) {
    //                // for an "enum" type parameter
    //                mPossibleValues.putMultiple(longname, possibleValues);
    //            }
    //        }
  }
示例#2
0
 /** @param pNamesOfOptsToInclude to enable using only a subset of args in a def table. */
 public ArgsDef(
     List<OptDef> pArgDefs, String[] pNonOptParamNames, Collection<String> pNamesOfOptsToInclude) {
   init(pArgDefs, Arrays.asList(pNonOptParamNames), pNamesOfOptsToInclude);
 }