Esempio n. 1
0
 public Set<String> parse(Config cfg) {
   final Set<String> result = new LinkedHashSet<String>();
   while (cfg != null) {
     for (final Entry e : cfg.state.get().entryList) {
       if (e.subsection != null
           && e.name == null
           && StringUtils.equalsIgnoreCase(section, e.section)) result.add(e.subsection);
     }
     cfg = cfg.baseConfig;
   }
   return Collections.unmodifiableSet(result);
 }
Esempio n. 2
0
  /**
   * Parse an enumeration from the configuration.
   *
   * @param <T> type of the enumeration object.
   * @param all all possible values in the enumeration which should be recognized. Typically {@code
   *     EnumType.values()}.
   * @param section section the key is grouped within.
   * @param subsection subsection name, such a remote or branch name.
   * @param name name of the key to get.
   * @param defaultValue default value to return if no value was present.
   * @return the selected enumeration value, or {@code defaultValue}.
   */
  public <T extends Enum<?>> T getEnum(
      final T[] all,
      final String section,
      final String subsection,
      final String name,
      final T defaultValue) {
    String value = getString(section, subsection, name);
    if (value == null) return defaultValue;

    String n = value.replace(' ', '_');
    T trueState = null;
    T falseState = null;
    for (T e : all) {
      if (StringUtils.equalsIgnoreCase(e.name(), n)) return e;
      else if (StringUtils.equalsIgnoreCase(e.name(), "TRUE")) trueState = e;
      else if (StringUtils.equalsIgnoreCase(e.name(), "FALSE")) falseState = e;
    }

    // This is an odd little fallback. C Git sometimes allows boolean
    // values in a tri-state with other things. If we have both a true
    // and a false value in our enumeration, assume its one of those.
    //
    if (trueState != null && falseState != null) {
      try {
        return StringUtils.toBoolean(n) ? trueState : falseState;
      } catch (IllegalArgumentException err) {
        // Fall through and use our custom error below.
      }
    }

    if (subsection != null)
      throw new IllegalArgumentException(
          MessageFormat.format(JGitText.get().enumValueNotSupported3, section, name, value));
    else
      throw new IllegalArgumentException(
          MessageFormat.format(JGitText.get().enumValueNotSupported2, section, name, value));
  }
Esempio n. 3
0
 public Set<String> parse(Config cfg) {
   final Map<String, String> m = new LinkedHashMap<String, String>();
   while (cfg != null) {
     for (final Entry e : cfg.state.get().entryList) {
       if (e.name == null) continue;
       if (!StringUtils.equalsIgnoreCase(section, e.section)) continue;
       if ((subsection == null && e.subsection == null)
           || (subsection != null && subsection.equals(e.subsection))) {
         String lc = StringUtils.toLowerCase(e.name);
         if (!m.containsKey(lc)) m.put(lc, e.name);
       }
     }
     cfg = cfg.baseConfig;
   }
   return new CaseFoldingSet(m);
 }
Esempio n. 4
0
 private static boolean eqIgnoreCase(final String a, final String b) {
   if (a == null && b == null) return true;
   if (a == null || b == null) return false;
   return StringUtils.equalsIgnoreCase(a, b);
 }