Beispiel #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();
 }
Beispiel #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);
    }
  }
Beispiel #3
0
 public boolean isEnum(String pKey) {
   return mPossibleValues.containsKey(pKey);
 }
Beispiel #4
0
 public Set getOptions(String pKey) {
   return mPossibleValues.get(pKey);
 }