package ru.job4j.storestatistics;

import java.util.List;

/**.
 * Class Info creates statistics for two arrays of Users.
 * @author Mikhail Vlasov
 * @since 07.08.2018
 * @version 1
 */
public class Info {
    /**.
     * Previous list of Users.
     */
    private List<Store.User> previous;
    /**.
     * Current list of Users.
     */
    private List<Store.User> current;
    /**.
     * Statistics values.
     */
    private int deleted, changed, added;

    /**.
     * Constructor.
     * @param previous list of Users.
     * @param current list of Users.
     */
    public Info(List<Store.User> previous, List<Store.User> current) {
        this.previous = previous;
        this.current = current;
        deleted = 0;
        changed = 0;
        added = 0;
        statistics();
    }

    /**.
     * Compares two user lists and creates statistics.
     */
    private void statistics() {
            for (Store.User usrC : current) {
                if (!previous.contains(usrC)) {
                    added++;
                    continue;
                } else {
                    if (usrC.isWasChanged()) {
                        changed++;
                        continue;
                    }
                }

            }

            for (Store.User usrP : previous) {
                if (!current.contains(usrP)) {
                    deleted++;
                }
            }
    }

    /**.
     * Overrides toString().
     */
    @Override
    public String toString() {
        return "Info{"
                + "deleted="
                + deleted
                + ", changed="
                + changed
                + ", added="
                + added
                + '}';
    }
}

@@ -28,16 +28,42 @@
 stics;%0A%0A
+import java.util.HashMap;%0A
 import j
@@ -922,32 +922,90 @@
 tistics() %7B%0A    
+    HashMap%3CStore.User, String%3E usrMap = new HashMap%3C%3E();%0A
         for (Sto
@@ -1019,19 +1019,20 @@
  usr
-C : current
+P : previous
 ) %7B%0A
@@ -1047,43 +1047,41 @@
     
-    if (!previous.contains(usrC)) %7B
+usrMap.put(usrP, usrP.getName());
 %0A   
@@ -1081,32 +1081,35 @@
 ));%0A        
+%7D%0A%0A
         
     added++;
@@ -1100,95 +1100,171 @@
     
-    added++;%0A                    continue;%0A                %7D else %7B%0A                   
+for (Store.User usrC : current) %7B%0A            String s = usrMap.put(usrC, usrC.getName());%0A            if (s == null) %7B%0A                added++;%0A            %7D else
  if 
@@ -1303,24 +1303,16 @@
         
-        
 changed+
@@ -1330,242 +1330,79 @@
     
-            continue;%0A                    %7D%0A                %7D%0A%0A            %7D%0A%0A            for (Store.User usrP : previous) %7B%0A                if (!current.contains(usrP)) %7B%0A                    deleted++;%0A                %7D%0A            %7D
+%7D%0A        %7D%0A        deleted = previous.size() + added - current.size();
 %0A   

Task 45889