package ru.job4j;

import com.sun.org.apache.bcel.internal.classfile.SourceFile;

import java.util.HashSet;

/**.
 * Task 5.7.3.
 * Create code for compare words
 *
 * @author Anton Vasilyuk on 15.10.2017
 * @version 1.0.
 */

public class CompareWords {

    /**.
     * @timeStart is time for start operation
     */
    private long timeStart;

    /**.
     * @timeEnd is time for end operation
     */
    private long timeEnd;

    /**.
     * @timeWork is total time
     */
    private long timeWork;

    /**.
     * @lengthOne is long for first word
     */
    private int lengthOne;

    /**.
     * @lengthOne is long for second word
     */
    private int lengthTwo;

    /**.
     * @hashOne is number for comparison with the second
     */
    private int hashOne;

    /**.
     * @hashTwo is number for comparison with the first
     */
    private int hashTwo;

    /**.
     * @oneCollection is one Collection
     */
    private HashSet<Character> oneColletcion;

    /**.
     * @twoCollection is two collection
     */
    private HashSet<Character> twoColletcion;


    /**.
     * Constructor for this class
     */
    public CompareWords() {
        hashOne = 0;
        hashTwo = 0;
        oneColletcion = new HashSet<>();
        twoColletcion = new HashSet<>();
    }

    /**.
     * Method for comparison words whithout collections
     * @param one is first word
     * @param two is second word
     * @return boolean
     */
    public boolean compareWordsOne(String one, String two) {
        lengthOne = one.length();
        lengthTwo = two.length();
        boolean result = false;

        if (lengthOne != lengthTwo) {return false;}
        timeStart = System.currentTimeMillis();
        char[] oneArray = one.toCharArray();
        char[] twoArray = two.toCharArray();
        for(int i = 0; i < lengthOne; i++) {
            hashOne = hashOne + (int)oneArray[i];
            hashTwo = hashTwo + (int)twoArray[i];
        }
        if (hashOne == hashTwo) {
            result = true;
        }
        timeEnd = System.currentTimeMillis();
        timeWork = timeEnd - timeStart;
        System.out.printf("%d milisec", timeWork);
        return result;
    }

    /**.
     * Method for comparison words with collection
     * @param one is first word
     * @param two is second word
     * @return boolean
     */
    public boolean compareWordsTwo(String one, String two) {
        lengthOne = one.length();
        lengthTwo = two.length();
        boolean result = false;

        timeStart = System.currentTimeMillis();
        char[] oneArray = one.toCharArray();
        char[] twoArray = two.toCharArray();
        for(int i = 0; i < lengthOne; i++) {
            oneColletcion.add((Character) oneArray[i]);
        }
        for(int i = 0; i < lengthTwo; i++) {
            twoColletcion.add((Character) twoArray[i]);
        }
        if (lengthOne > lengthTwo) {
            result = oneColletcion.containsAll(twoColletcion);
        } else {
            result = twoColletcion.containsAll(oneColletcion);
        }
        timeEnd = System.currentTimeMillis();
        timeWork = timeEnd - timeStart;
        System.out.printf("%d milisec%n", timeWork);
        return result;
    }
}

@@ -92,23 +92,17 @@
 va.util.
-HashSet
+*
 ;%0A%0A/**.%0A
@@ -930,38 +930,35 @@
  */%0A    private 
-HashSe
+Lis
 t%3CCharacter%3E one
@@ -1039,22 +1039,19 @@
 private 
-HashSe
+Lis
 t%3CCharac
@@ -1071,16 +1071,36 @@
 tcion;%0A%0A
+    Character temp;%0A
 %0A    /**
@@ -1233,38 +1233,41 @@
 olletcion = new 
-HashSe
+LinkedLis
 t%3C%3E();%0A        t
@@ -1289,14 +1289,17 @@
 new 
-HashSe
+LinkedLis
 t%3C%3E(
@@ -2945,137 +2945,622 @@
     
-result = oneColletcion.containsAll(twoColletcion);%0A        %7D else %7B%0A            result = twoColletcion.containsAll(oneColletcion)
+Iterator%3CCharacter%3E iterOne = oneColletcion.iterator();%0A            for(int i = 0; i %3C lengthOne; i++) %7B%0A                temp = iterOne.next();%0A                if(twoColletcion.contains(temp)) %7BtwoColletcion.remove(temp);%7D%0A            %7D%0A            if (twoColletcion.isEmpty()) result = true;%0A        %7D else %7B%0A            Iterator%3CCharacter%3E iterTwo = twoColletcion.iterator();%0A            for(int i = 0; i %3C lengthTwo; i++) %7B%0A                temp = iterTwo.next();%0A                if(oneColletcion.contains(temp)) %7BoneColletcion.remove(temp);%7D%0A            %7D%0A            if (oneColletcion.isEmpty()) result = true;
 ;%0A  

add file for chapter_004_5.7.3