大小写无关的字符串为键的map

118 阅读1分钟

 

org.apache.calcite.util.NameMap

使用TreeMap的键比较器比较,使用floorKey和ceilingKey忽略大小写


  /** Returns a map containing all the entries in the map that match the given
   * name. If case-sensitive, that map will have 0 or 1 elements; if
   * case-insensitive, it may have 0 or more. */
  public NavigableMap<String, V> range(String name, boolean caseSensitive) {
    Object floorKey;
    Object ceilingKey;
    if (caseSensitive) {
      floorKey = name;
      ceilingKey = name;
    } else {
      floorKey = COMPARATOR.floorKey(name);
      ceilingKey = COMPARATOR.ceilingKey(name);
    }
    NavigableMap subMap = ((NavigableMap) map).subMap(floorKey, true, ceilingKey, true);
    return Collections.unmodifiableNavigableMap((NavigableMap<String, V>) subMap);
  }