示例#1
0
 /**
  * Returns a copy of the given map as a {@link CharArrayMap}. If the given map is a {@link
  * CharArrayMap} the ignoreCase property will be preserved.
  *
  * @param map a map to copy
  * @return a copy of the given map as a {@link CharArrayMap}. If the given map is a {@link
  *     CharArrayMap} the ignoreCase property as well as the matchVersion will be of the given map
  *     will be preserved.
  */
 @SuppressWarnings("unchecked")
 public static <V> CharArrayMap<V> copy(final Map<?, ? extends V> map) {
   if (map == EMPTY_MAP) return emptyMap();
   if (map instanceof CharArrayMap) {
     CharArrayMap<V> m = (CharArrayMap<V>) map;
     // use fast path instead of iterating all values
     // this is even on very small sets ~10 times faster than iterating
     final char[][] keys = new char[m.keys.length][];
     System.arraycopy(m.keys, 0, keys, 0, keys.length);
     final V[] values = (V[]) new Object[m.values.length];
     System.arraycopy(m.values, 0, values, 0, values.length);
     m = new CharArrayMap<>(m);
     m.keys = keys;
     m.values = values;
     return m;
   }
   // In jdk-9b54 or later, a plain diamond causes compile error with "-source 1.7":
   return new CharArrayMap<V>(map, false);
 }