package ru.sbulygin;

import java.util.*;

/**
 * Class CollectionsTest.
 *
 * @author ru.sbulygin.
 * @since 09.04.2017.
 * @version 1.0.
 */
public class CollectionsTest {

    public long add(Collection<String> collection, String line, int amount) {

        long startTime = System.currentTimeMillis();

        for (int index = 0; index < amount; index++) {
            collection.add(line);
        }
        long finishTime = System.currentTimeMillis();
        return finishTime - startTime;
    }

    public long delete(Collection<String> collection, int amount) {

        long startTime = System.currentTimeMillis();

        Iterator<String> iterator = collection.iterator();

        for (int index = 0; index < amount; index++) {

            if (iterator.hasNext()) {
                iterator.next();
                iterator.remove();
            }
        }
        long finishTime = System.currentTimeMillis();
        return finishTime - startTime;
    }

public static void main(String[] args) {

    CollectionsTest test = new CollectionsTest();
    LinkedList<String> linkedList = new LinkedList<>();
    ArrayList<String> arrayList = new ArrayList<>();
    TreeSet<String> treeSet = new TreeSet<>();

    System.out.println("Time adding elements: ");
    System.out.println(String.format("LinkedList: %s ms", test.add(linkedList, "element", 7_000_000)));
    System.out.println(String.format("arrayList: %s ms", test.add(arrayList, "element", 7_000_000)));
    System.out.println(String.format("treeSet: %s ms", test.add(treeSet, "element", 7_000_000)));
    linkedList.clear();
    arrayList.clear();
    treeSet.clear();

    test.add(linkedList, "element", 180_000);
    test.add(arrayList, "element", 180_000);
    test.add(treeSet, "element", 180_000);
    System.out.println();
    System.out.println("Time of delete elements: ");
    System.out.println(String.format("LinkedList: %s ms", test.delete(linkedList, 120_000)));
    System.out.println(String.format("arrayList: %s ms", test.delete(arrayList, 120_000)));
    System.out.println(String.format("treeSet: %s ms", test.delete(treeSet, 120_000)));



}

}

@@ -15,16 +15,17 @@
 lygin;%0A%0A
+%0A
 import j
@@ -165,24 +165,296 @@
 ionsTest %7B%0A%0A
+    /**%0A     * The method of adding items to the collection for test.%0A     * @param collection testing collection.%0A     * @param line element for testing collection.%0A     * @param amount the number of elements for testing collection.%0A     * @return the test time.%0A     */%0A
     public l
@@ -773,16 +773,237 @@
 %0A    %7D%0A%0A
+    /**%0A     * The method of delete items to the collection for test.%0A     * @param collection testing collection.%0A     * @param amount the number of elements for testing collection.%0A     * @return the test time.%0A     */%0A
     publ
@@ -1463,16 +1463,152 @@
 %0A    %7D%0A%0A
+    /**%0A     * Method to test collections when adding and removing elements.%0A     * @param args the command-line arguments.%0A     */%0A    
 public s
@@ -1645,16 +1645,20 @@
  %7B%0A%0A    
+   
+ 
 Collecti
@@ -1691,24 +1691,28 @@
 ionsTest();%0A
+    
     LinkedLi
@@ -1759,16 +1759,20 @@
 ();%0A    
+  
+  
 ArrayLis
@@ -1808,24 +1808,28 @@
 ayList%3C%3E();%0A
+    
     TreeSet%3C
@@ -1864,24 +1864,28 @@
 t%3C%3E();%0A%0A    
+ 
+   
 System.out.p
@@ -1910,32 +1910,36 @@
 g elements: %22);%0A
+    
     System.out.p
@@ -2018,32 +2018,36 @@
 , 7_000_000)));%0A
+    
     System.out.p
@@ -2128,32 +2128,36 @@
 000_000)));%0A    
+  
+  
 System.out.print
@@ -2230,24 +2230,29 @@
 000_000)));%0A
+%0A    
     linkedLi
@@ -2267,16 +2267,20 @@
 ();%0A    
+ 
+   
 arrayLis
@@ -2294,16 +2294,20 @@
 ();%0A    
+   
+ 
 treeSet.
@@ -2312,24 +2312,28 @@
 t.clear();%0A%0A
+    
     test.add
@@ -2362,32 +2362,36 @@
 , 180_000);%0A    
+  
+  
 test.add(arrayLi
@@ -2411,24 +2411,28 @@
 , 180_000);%0A
+    
     test.add
@@ -2458,24 +2458,29 @@
 , 180_000);%0A
+%0A
+    
     System.o
@@ -2489,24 +2489,28 @@
 .println();%0A
+    
     System.o
@@ -2546,24 +2546,28 @@
 ements: %22);%0A
+    
     System.o
@@ -2644,32 +2644,36 @@
 120_000)));%0A    
+  
+  
 System.out.print
@@ -2740,24 +2740,28 @@
 120_000)));%0A
+    
     System.o
@@ -2836,16 +2836,17 @@
 000)));%0A
-%0A%0A%0A
+    
 %7D%0A%0A%7D%0A

add JavaDoc & registration code #1