code: public long remove(K key) {
      AtomicLong atomic = map.get(key);
      if (atomic == null) {
        return 0L;
      }
  
      for (;;) {
        long oldValue = atomic.get();
        if (oldValue == 0L || atomic.compareAndSet(oldValue, 0L)) {
          // only remove after setting to zero, to avoid concurrent updates
          map.remove(key, atomic);
          // succeed even if the remove fails, since the value was already adjusted
          return oldValue;
        }
      }
    }
docs: Removes and returns the value associated with {@code key}. If {@code key} is not
  in the map, this method has no effect and returns zero.