コード例 #1
0
 // Return a map with only keys in the set
 public StringDoubleMap restrict(Set<String> set) {
   StringDoubleMap newMap = new StringDoubleMap();
   newMap.mapType = mapType;
   if (mapType == MapType.SORTED_LIST) {
     newMap.allocate(getCapacity(num, false));
     for (int i = 0; i < keys.length; i++) {
       if (set.contains(keys[i])) {
         newMap.keys[newMap.num] = keys[i];
         newMap.values[newMap.num] = values[i];
         newMap.num++;
       }
     }
   } else if (mapType == MapType.HASH_TABLE) {
     for (int i = 0; i < keys.length; i++)
       if (keys[i] != null && set.contains(keys[i])) newMap.put(keys[i], values[i]);
   }
   newMap.locked = locked;
   return newMap;
 }