예제 #1
0
  /**
   * Obtain an integer value from the configuration.
   *
   * @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 an integer value from the configuration, or defaultValue.
   */
  public long getLong(
      final String section, String subsection, final String name, final long defaultValue) {
    final String str = getString(section, subsection, name);
    if (str == null) return defaultValue;

    String n = str.trim();
    if (n.length() == 0) return defaultValue;

    long mul = 1;
    switch (StringUtils.toLowerCase(n.charAt(n.length() - 1))) {
      case 'g':
        mul = GiB;
        break;
      case 'm':
        mul = MiB;
        break;
      case 'k':
        mul = KiB;
        break;
    }
    if (mul > 1) n = n.substring(0, n.length() - 1).trim();
    if (n.length() == 0) return defaultValue;

    try {
      return mul * Long.parseLong(n);
    } catch (NumberFormatException nfe) {
      throw new IllegalArgumentException(
          MessageFormat.format(JGitText.get().invalidIntegerValue, section, name, str));
    }
  }
예제 #2
0
    @Override
    public boolean contains(Object needle) {
      if (!(needle instanceof String)) return false;

      String n = (String) needle;
      return names.containsKey(n) || names.containsKey(StringUtils.toLowerCase(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.section != null) {
         String lc = StringUtils.toLowerCase(e.section);
         if (!m.containsKey(lc)) m.put(lc, e.section);
       }
     }
     cfg = cfg.baseConfig;
   }
   return new CaseFoldingSet(m);
 }
예제 #4
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);
 }
예제 #5
0
 private static final byte lc(final byte q) {
   return (byte) StringUtils.toLowerCase((char) (q & 0xff));
 }