< prev index next >

test/jdk/java/util/Spliterator/SpliteratorTraversingAndSplittingTest.java

Print this page

   1 /*
   2  * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @summary Spliterator traversing and splitting tests
  27  * @library /lib/testlibrary/bootlib

  28  * @build java.base/java.util.SpliteratorOfIntDataBuilder
  29  *        java.base/java.util.SpliteratorTestHelper
  30  * @run testng SpliteratorTraversingAndSplittingTest
  31  * @bug 8020016 8071477 8072784 8169838

  32  */
  33 


  34 import org.testng.annotations.DataProvider;
  35 import org.testng.annotations.Test;
  36 
  37 import java.nio.CharBuffer;
  38 import java.util.AbstractCollection;
  39 import java.util.AbstractList;
  40 import java.util.AbstractSet;
  41 import java.util.ArrayDeque;
  42 import java.util.ArrayList;
  43 import java.util.Arrays;
  44 import java.util.Collection;
  45 import java.util.Collections;
  46 import java.util.Comparator;
  47 import java.util.HashMap;
  48 import java.util.HashSet;
  49 import java.util.IdentityHashMap;
  50 import java.util.Iterator;
  51 import java.util.LinkedHashMap;
  52 import java.util.LinkedHashSet;
  53 import java.util.LinkedList;

 611 
 612             db.addMap(m -> {
 613                 // Create a Map ensuring that for large sizes
 614                 // buckets will contain 2 or more entries
 615                 HashMap<Integer, Integer> cm = new HashMap<>(1, m.size() + 1);
 616                 // Don't use putAll which inflates the table by
 617                 // m.size() * loadFactor, thus creating a very sparse
 618                 // map for 1000 entries defeating the purpose of this test,
 619                 // in addition it will cause the split until null test to fail
 620                 // because the number of valid splits is larger than the
 621                 // threshold
 622                 for (Map.Entry<Integer, Integer> e : m.entrySet())
 623                     cm.put(e.getKey(), e.getValue());
 624                 return cm;
 625             }, "new java.util.HashMap(1, size + 1)");
 626 
 627             db.addMap(LinkedHashMap::new);
 628 
 629             db.addMap(IdentityHashMap::new);
 630 
 631             db.addMap(WeakHashMap::new);
 632 
 633             db.addMap(m -> {
 634                 // Create a Map ensuring that for large sizes
 635                 // buckets will be consist of 2 or more entries
 636                 WeakHashMap<Integer, Integer> cm = new WeakHashMap<>(1, m.size() + 1);
 637                 for (Map.Entry<Integer, Integer> e : m.entrySet())
 638                     cm.put(e.getKey(), e.getValue());
 639                 return cm;
 640             }, "new java.util.WeakHashMap(1, size + 1)");



 641 
 642             // @@@  Descending maps etc
 643             db.addMap(TreeMap::new);
 644 
 645             db.addMap(ConcurrentHashMap::new);
 646 
 647             db.addMap(ConcurrentSkipListMap::new);
 648 
 649             if (size == 0) {
 650                 db.addMap(m -> Collections.<Integer, Integer>emptyMap());
 651             }
 652             else if (size == 1) {
 653                 db.addMap(m -> Collections.singletonMap(exp.get(0), exp.get(0)));
 654             }
 655         }
 656 
 657         return spliteratorDataProvider = data.toArray(new Object[0][]);
 658     }
 659 
 660     private static List<Integer> listIntRange(int upTo) {

   1 /*
   2  * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @summary Spliterator traversing and splitting tests
  27  * @library /lib/testlibrary/bootlib
  28  * @modules java.base/jdk.internal.misc
  29  * @build java.base/java.util.SpliteratorOfIntDataBuilder
  30  *        java.base/java.util.SpliteratorTestHelper
  31  * @run testng SpliteratorTraversingAndSplittingTest
  32  * @run testng/othervm --enable-preview SpliteratorTraversingAndSplittingTest
  33  * @bug 8020016 8071477 8072784 8169838 8336672
  34  */
  35 
  36 import jdk.internal.misc.PreviewFeatures;
  37 
  38 import org.testng.annotations.DataProvider;
  39 import org.testng.annotations.Test;
  40 
  41 import java.nio.CharBuffer;
  42 import java.util.AbstractCollection;
  43 import java.util.AbstractList;
  44 import java.util.AbstractSet;
  45 import java.util.ArrayDeque;
  46 import java.util.ArrayList;
  47 import java.util.Arrays;
  48 import java.util.Collection;
  49 import java.util.Collections;
  50 import java.util.Comparator;
  51 import java.util.HashMap;
  52 import java.util.HashSet;
  53 import java.util.IdentityHashMap;
  54 import java.util.Iterator;
  55 import java.util.LinkedHashMap;
  56 import java.util.LinkedHashSet;
  57 import java.util.LinkedList;

 615 
 616             db.addMap(m -> {
 617                 // Create a Map ensuring that for large sizes
 618                 // buckets will contain 2 or more entries
 619                 HashMap<Integer, Integer> cm = new HashMap<>(1, m.size() + 1);
 620                 // Don't use putAll which inflates the table by
 621                 // m.size() * loadFactor, thus creating a very sparse
 622                 // map for 1000 entries defeating the purpose of this test,
 623                 // in addition it will cause the split until null test to fail
 624                 // because the number of valid splits is larger than the
 625                 // threshold
 626                 for (Map.Entry<Integer, Integer> e : m.entrySet())
 627                     cm.put(e.getKey(), e.getValue());
 628                 return cm;
 629             }, "new java.util.HashMap(1, size + 1)");
 630 
 631             db.addMap(LinkedHashMap::new);
 632 
 633             db.addMap(IdentityHashMap::new);
 634 
 635             if (!PreviewFeatures.isEnabled()) {
 636                 // With --enable-preview, WeakHashmap is not tested with Integer, a value class
 637                 db.addMap(WeakHashMap::new);
 638 
 639                 db.addMap(m -> {
 640                     // Create a Map ensuring that for large sizes
 641                     // buckets will consist of 2 or more entries
 642                     WeakHashMap<Integer, Integer> cm = new WeakHashMap<>(1, m.size() + 1);
 643                     for (Map.Entry<Integer, Integer> e : m.entrySet())
 644                         cm.put(e.getKey(), e.getValue());
 645                     return cm;
 646                 }, "new java.util.WeakHashMap(1, size + 1)");
 647             }
 648 
 649             // @@@  Descending maps etc
 650             db.addMap(TreeMap::new);
 651 
 652             db.addMap(ConcurrentHashMap::new);
 653 
 654             db.addMap(ConcurrentSkipListMap::new);
 655 
 656             if (size == 0) {
 657                 db.addMap(m -> Collections.<Integer, Integer>emptyMap());
 658             }
 659             else if (size == 1) {
 660                 db.addMap(m -> Collections.singletonMap(exp.get(0), exp.get(0)));
 661             }
 662         }
 663 
 664         return spliteratorDataProvider = data.toArray(new Object[0][]);
 665     }
 666 
 667     private static List<Integer> listIntRange(int upTo) {
< prev index next >