Exemplo n.º 1
0
 public String formatOpts(Collection pLongNames) {
   StringBuffer result = new StringBuffer();
   Map longnametoshortnamemap = CollectionUtils.inverseMap(mShortNameToLongNameMap);
   Iterator longnames = pLongNames.iterator();
   while (longnames.hasNext()) {
     String longname = (String) longnames.next();
     result.append("  -" + longname);
     String shortname = (String) longnametoshortnamemap.get(longname);
     if (shortname != null) {
       result.append(" (-" + shortname + ")");
     }
     String possibleValsString = "";
     if (mPossibleValues.keySet().contains(longname)) {
       possibleValsString = " " + mPossibleValues.get(longname);
     }
     result.append(possibleValsString);
     String defaultVal = (String) mDefaultValues.get(longname);
     if (defaultVal != null) {
       result.append(", default=" + defaultVal);
     }
     if (longnames.hasNext()) {
       result.append("\n");
     }
   }
   return result.toString();
 }
Exemplo n.º 2
0
  public void addDef(OptDef pDef) {

    mArgDefs.add(pDef);

    if (mShortNameToLongNameMap.containsKey(pDef.shortname)) {
      throw new RuntimeException("Duplicate short name: " + pDef.shortname);
    }

    mValidOptionNames.add(pDef.longname);

    if (pDef.shortname != null) {
      mValidOptionNames.add(pDef.shortname);
      mShortNameToLongNameMap.put(pDef.shortname, pDef.longname);
    } else {
      mOptionsWithoutShortName.add(pDef.longname);
    }

    if (pDef.hasvalue) {
      mNamesOfOptionsRequiringValue.add(pDef.longname);
    }

    if (pDef.defaultvalue != null) {
      // a little sanity check, if you permit...
      if (!(pDef.hasvalue)) {
        throw new RuntimeException(
            "Illegal situation: parameter "
                + pDef.longname
                + " has no value, "
                + "but still has default value "
                + pDef.defaultvalue);
      }
      mDefaultValues.put(pDef.longname, pDef.defaultvalue);
    }

    if (pDef.possiblevalues != null) {
      // for an "enum" type parameter
      mPossibleValues.putMultiple(pDef.longname, pDef.possiblevalues);
    }
  }
Exemplo n.º 3
0
 /**
  * Hmm, bit ugly to do this afterwards, but currently we must handle "dependent" default values
  * this way, by hand.
  */
 public void putDefaultValue(String pKey, String pVal) {
   mDefaultValues.put(pKey, pVal);
 }
Exemplo n.º 4
0
 /** Note: Gets of course long names only */
 public Set getNamesOfOptionsWithDefaultValue() {
   return mDefaultValues.keySet();
 }
Exemplo n.º 5
0
 public Set getShortOptionNames() {
   return mShortNameToLongNameMap.keySet();
 }
Exemplo n.º 6
0
 public String getDefaultValue(String pOptName) {
   return (String) mDefaultValues.get(pOptName);
 }