jdk/test/java/util/Collections/UnmodifiableMapEntrySet.java
author amlu
Fri, 18 Nov 2016 14:39:03 +0800
changeset 42166 5582c83b1156
parent 18794 17d9c2ec5e47
permissions -rw-r--r--
8169836: ProblemList update for java/lang/management/MemoryMXBean/PendingAllGC.sh Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18794
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
     1
/*
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
     4
 *
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
     7
 * published by the Free Software Foundation.
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
     8
 *
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    13
 * accompanied this code).
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    14
 *
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    18
 *
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    21
 * questions.
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    22
 */
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    23
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    24
/**
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    25
 * @test
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    26
 * @run testng UnmodifiableMapEntrySet
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    27
 * @summary Unit tests for wrapping classes should delegate to default methods
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    28
 */
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    29
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    30
import java.util.ArrayList;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    31
import java.util.Collections;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    32
import java.util.HashMap;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    33
import java.util.List;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    34
import java.util.Map;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    35
import java.util.Spliterator;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    36
import java.util.TreeMap;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    37
import java.util.function.Consumer;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    38
import java.util.function.Function;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    39
import java.util.function.Supplier;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    40
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    41
import org.testng.annotations.Test;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    42
import org.testng.annotations.DataProvider;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    43
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    44
import static org.testng.Assert.assertEquals;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    45
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    46
@Test(groups = "unit")
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    47
public class UnmodifiableMapEntrySet {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    48
    static Object[][] collections;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    49
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    50
    static <M extends Map<Integer, Integer>> M fillMap(int size, M m) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    51
        for (int i = 0; i < size; i++) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    52
            m.put(i, i);
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    53
        }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    54
        return m;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    55
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    56
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    57
    @DataProvider(name="maps")
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    58
    static Object[][] mapCases() {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    59
        if (collections != null) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    60
            return collections;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    61
        }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    62
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    63
        List<Object[]> cases = new ArrayList<>();
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    64
        for (int size : new int[] {1, 2, 16}) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    65
            cases.add(new Object[] {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    66
                    String.format("new HashMap(%d)", size),
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    67
                    (Supplier<Map<Integer, Integer>>)
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    68
                    () -> Collections.unmodifiableMap(fillMap(size, new HashMap<>())) });
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    69
            cases.add(new Object[] {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    70
                    String.format("new TreeMap(%d)", size),
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    71
                    (Supplier<Map<Integer, Integer>>)
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    72
                    () -> Collections.unmodifiableSortedMap(fillMap(size, new TreeMap<>())) });
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    73
        }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    74
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    75
        return cases.toArray(new Object[0][]);
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    76
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    77
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    78
    static class EntryConsumer implements Consumer<Map.Entry<Integer, Integer>> {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    79
        int updates;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    80
        @Override
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    81
        public void accept(Map.Entry<Integer, Integer> me) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    82
            try {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    83
                me.setValue(Integer.MAX_VALUE);
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    84
                updates++;
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    85
            } catch (UnsupportedOperationException e) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    86
            }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    87
        }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    88
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    89
        void assertNoUpdates() {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    90
            assertEquals(updates, 0, "Updates to entries");
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    91
        }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    92
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    93
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    94
    void testWithEntryConsumer(Consumer<EntryConsumer> c) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    95
        EntryConsumer ec = new EntryConsumer();
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    96
        c.accept(ec);
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    97
        ec.assertNoUpdates();
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    98
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
    99
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   100
    @Test(dataProvider = "maps")
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   101
    public void testForEach(String d, Supplier<Map<Integer, Integer>> ms) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   102
        testWithEntryConsumer(
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   103
                ec -> ms.get().entrySet().forEach(ec));
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   104
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   105
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   106
    @Test(dataProvider = "maps")
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   107
    public void testIteratorForEachRemaining(String d, Supplier<Map<Integer, Integer>> ms) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   108
        testWithEntryConsumer(
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   109
                ec -> ms.get().entrySet().iterator().forEachRemaining(ec));
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   110
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   111
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   112
    @Test(dataProvider = "maps")
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   113
    public void testIteratorNext(String d, Supplier<Map<Integer, Integer>> ms) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   114
        testWithEntryConsumer(ec -> {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   115
            for (Map.Entry<Integer, Integer> me : ms.get().entrySet()) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   116
                ec.accept(me);
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   117
            }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   118
        });
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   119
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   120
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   121
    @Test(dataProvider = "maps")
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   122
    public void testSpliteratorForEachRemaining(String d, Supplier<Map<Integer, Integer>> ms) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   123
        testSpliterator(
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   124
                ms.get().entrySet()::spliterator,
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   125
                // Higher order function returning a consumer that
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   126
                // traverses all spliterator elements using an EntryConsumer
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   127
                s -> ec -> s.forEachRemaining(ec));
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   128
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   129
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   130
    @Test(dataProvider = "maps")
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   131
    public void testSpliteratorTryAdvance(String d, Supplier<Map<Integer, Integer>> ms) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   132
        testSpliterator(
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   133
                ms.get().entrySet()::spliterator,
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   134
                // Higher order function returning a consumer that
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   135
                // traverses all spliterator elements using an EntryConsumer
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   136
                s -> ec -> { while (s.tryAdvance(ec)); });
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   137
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   138
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   139
    void testSpliterator(Supplier<Spliterator<Map.Entry<Integer, Integer>>> ss,
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   140
                         // Higher order function that given a spliterator returns a
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   141
                         // consumer for that spliterator which traverses elements
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   142
                         // using an EntryConsumer
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   143
                         Function<Spliterator<Map.Entry<Integer, Integer>>, Consumer<EntryConsumer>> sc) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   144
        testWithEntryConsumer(sc.apply(ss.get()));
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   145
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   146
        Spliterator<Map.Entry<Integer, Integer>> s = ss.get();
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   147
        Spliterator<Map.Entry<Integer, Integer>> split = s.trySplit();
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   148
        if (split != null) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   149
            testWithEntryConsumer(sc.apply(split));
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   150
            testWithEntryConsumer(sc.apply(s));
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   151
        }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   152
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   153
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   154
    @Test(dataProvider = "maps")
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   155
    public void testStreamForEach(String d, Supplier<Map<Integer, Integer>> ms) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   156
        testWithEntryConsumer(ec -> ms.get().entrySet().stream().forEach(ec));
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   157
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   158
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   159
    @Test(dataProvider = "maps")
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   160
    public void testParallelStreamForEach(String d, Supplier<Map<Integer, Integer>> ms) {
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   161
        testWithEntryConsumer(ec -> ms.get().entrySet().parallelStream().forEach(ec));
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   162
    }
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   163
}
17d9c2ec5e47 8017447: Unmodifiable map entry becomes modifiable if taken from a stream of map entries
psandoz
parents:
diff changeset
   164