BUG-7464: Apply copyright headers
[yangtools.git] / third-party / triemap / src / test / java / org / opendaylight / yangtools / triemap / TestMultiThreadMapIterator.java
index fc4128a552c3368844283b46f0eb0f09947c9f95..cc42c3d8734087cacd10f5e474879f94944e9244 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * (C) Copyright 2016 Pantheon Technologies, s.r.o. and others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.opendaylight.yangtools.triemap;
 
 import java.util.Collection;
@@ -9,7 +24,6 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
-
 import org.junit.Test;
 
 public class TestMultiThreadMapIterator {
@@ -17,7 +31,7 @@ public class TestMultiThreadMapIterator {
 
     @Test
     public void testMultiThreadMapIterator () {
-        final Map<Object, Object> bt = new TrieMap<Object, Object> ();
+        final Map<Object, Object> bt = new TrieMap<> ();
         for (int j = 0; j < 50 * 1000; j++) {
             final Object[] objects = getObjects (j);
             for (final Object o : objects) {
@@ -25,7 +39,7 @@ public class TestMultiThreadMapIterator {
             }
         }
 
-      System.out.println ("Size of initialized map is " + bt.size ());  
+      System.out.println ("Size of initialized map is " + bt.size ());
       int count = 0;
         {
             final ExecutorService es = Executors.newFixedThreadPool (NTHREADS);
@@ -34,10 +48,9 @@ public class TestMultiThreadMapIterator {
                 es.execute (new Runnable () {
                     @Override
                     public void run () {
-                        for (final Iterator<Map.Entry<Object, Object>> i = bt.entrySet ().iterator (); i.hasNext ();) {
-                            final Entry<Object, Object> e = i.next ();
+                        for (Entry<Object, Object> e : bt.entrySet ()) {
                             if (accepts (threadNo, NTHREADS, e.getKey ())) {
-                                String newValue = "TEST:" + threadNo; 
+                                String newValue = "TEST:" + threadNo;
                                 e.setValue (newValue);
                             }
                         }
@@ -55,13 +68,13 @@ public class TestMultiThreadMapIterator {
 
         count = 0;
         for (final Map.Entry<Object, Object> kv : bt.entrySet ()) {
-            Object value = kv.getValue (); 
+            Object value = kv.getValue ();
             TestHelper.assertTrue (value instanceof String);
             count++;
         }
         TestHelper.assertEquals (50000 + 2000 + 1000 + 100, count);
-        
-        final ConcurrentHashMap<Object, Object> removed = new ConcurrentHashMap<Object, Object> ();
+
+        final ConcurrentHashMap<Object, Object> removed = new ConcurrentHashMap<> ();
 
         {
             final ExecutorService es = Executors.newFixedThreadPool (NTHREADS);
@@ -112,11 +125,12 @@ public class TestMultiThreadMapIterator {
     }
 
     protected static boolean accepts (final int threadNo, final int nThreads, final Object key) {
-        int val = getKeyValue (key); 
-        if(val>=0)
+        int val = getKeyValue (key);
+        if(val>=0) {
             return val % nThreads == threadNo;
-        else
+        } else {
             return false;
+        }
     }
 
     private static int getKeyValue (final Object key) {
@@ -132,13 +146,14 @@ public class TestMultiThreadMapIterator {
         }
         else if (key instanceof Byte) {
             val = ((Byte) key).intValue () + 3;
-        } else 
+        } else {
             return -1;
+        }
         return val;
     }
 
     static Object[] getObjects (final int j) {
-        final Collection<Object> results = new LinkedList<Object> ();
+        final Collection<Object> results = new LinkedList<> ();
         results.add (Integer.valueOf (j));
         if (j < 2000) {
             results.add (Character.valueOf ((char) j));