@Override
    public void addCookie(final Cookie cookie) {
        if (cookie != null) {
            lock.writeLock().lock();
            try {
                // first remove any old cookie that is equivalent
                cookies.remove(cookie);
                if (!cookie.isExpired(Instant.now())) {
                    cookies.add(cookie);
                }
            } finally {
                lock.writeLock().unlock();
            }
        }
    }
Adds an {@link Cookie HTTP cookie}, replacing any existing equivalent cookies.
If the given cookie has already expired it will not be added, but existing
values will still be removed.

@param cookie the {@link Cookie cookie} to be added

@see #addCookies(Cookie[])
httpclient5/src/main/java/org/apache/hc/client5/http/cookie/BasicCookieStore.java