package ru.job4j.servlets;

import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Intellij IDEA.
 * User: Vitaly Zubov
 * Email: Zubov.VP@yandex.ru
 * Version: $Id$
 * Date: 04.12.2018
 */
@ThreadSafe
public class MemoryStore implements Store {
    @GuardedBy("users")
    private ConcurrentHashMap<Integer, User> users = new ConcurrentHashMap<>();
    private final static MemoryStore MEMORY_STORE = new MemoryStore();

    /**
     * Constructor.
     */
    private MemoryStore() {
    }

    /**
     * Constructor.
     *
     * @return - MemoryStore.
     */
    public static MemoryStore getInstance() {
        return MEMORY_STORE;
    }

    /**
     * Insert element in the users.
     *
     * @param user - user.
     * @return - result.
     */
    @Override
    public boolean add(User user) {
        user.setId(getId());
        this.users.put(user.getId(), user);
        return true;
    }

    /**
     * Update element in the users.
     *
     * @param user - user.
     * @return - result.
     */
    @Override
    public boolean update(User user) {
        User oldUser = this.users.get(user.getId());
        user.setCreateDate(oldUser.getCreateDate());
        this.users.replace(user.getId(), user);
        return true;
    }

    /**
     * Delete element from the users.
     *
     * @param id - id of the user.
     * @return - result.
     */
    @Override
    public boolean delete(int id) {
        this.users.remove(id);
        return true;
    }

    /**
     * Find all the users from the users.
     *
     * @return - List of the users.
     */
    @Override
    public List<User> findAll() {
        return new ArrayList<>(this.users.values());
    }

    /**
     * Find users with help id.
     *
     * @param id - id of user.
     * @return - user.
     */
    @Override
    public User findById(int id) {
        return this.users.get(id);
    }

    /**
     * Get id for user.
     *
     * @return - id.
     */
    private synchronized int getId() {
        return this.users.size() + 1;
    }
}

@@ -198,16 +198,66 @@
 HashMap;
+%0Aimport java.util.concurrent.atomic.AtomicInteger;
 %0A%0A/**%0A *
@@ -605,16 +605,69 @@
 Store();
+%0A    private AtomicInteger id = new AtomicInteger(1);
 %0A%0A    /*
@@ -1066,21 +1066,39 @@
 r.setId(
-getId
+this.id.getAndIncrement
 ());%0A   
@@ -2153,159 +2153,7 @@
    %7D
-%0A%0A    /**%0A     * Get id for user.%0A     *%0A     * @return - id.%0A     */%0A    private synchronized int getId() %7B%0A        return this.users.size() + 1;%0A    %7D
 %0A%7D%0A

Correct MemoryStore.