code: public boolean replace(K key, V oldValue, V newValue) {
          Object curValue = get(key);
          if (!Objects.equals(curValue, oldValue) || (curValue == null && !containsKey(key))) {
              return false;
          }
          put(key, newValue);
          return true;
      }
docs: Replaces the entry for the specified key only if currently
  mapped to the specified value.