test/jdk/java/util/concurrent/tck/ConcurrentSkipListMapTest.java
author dl
Fri, 01 Nov 2019 09:04:04 -0700
changeset 58892 35bac2745d04
parent 47304 3f5f9bc0bdc2
permissions -rw-r--r--
8231592: Clarify that ConcurrentHashMap compute methods mapping functions execute at most once Reviewed-by: martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     1
/*
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     3
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     6
 * published by the Free Software Foundation.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     7
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    12
 * accompanied this code).
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    13
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    17
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    20
 * questions.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    21
 */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    22
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    23
/*
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    24
 * This file is available under and governed by the GNU General Public
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    25
 * License version 2 only, as published by the Free Software Foundation.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    26
 * However, the following notice accompanied the original version of this
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    27
 * file:
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    28
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    29
 * Written by Doug Lea with assistance from members of JCP JSR-166
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    30
 * Expert Group and released to the public domain, as explained at
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    31
 * http://creativecommons.org/publicdomain/zero/1.0/
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    32
 */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    33
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    34
import java.util.ArrayList;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    35
import java.util.Arrays;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    36
import java.util.BitSet;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    37
import java.util.Collection;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    38
import java.util.Iterator;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    39
import java.util.Map;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    40
import java.util.NavigableMap;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    41
import java.util.NavigableSet;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    42
import java.util.NoSuchElementException;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    43
import java.util.Random;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    44
import java.util.Set;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    45
import java.util.concurrent.ConcurrentSkipListMap;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    46
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    47
import junit.framework.Test;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    48
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    49
public class ConcurrentSkipListMapTest extends JSR166TestCase {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    50
    public static void main(String[] args) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    51
        main(suite(), args);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    52
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    53
    public static Test suite() {
47304
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    54
        class Implementation implements MapImplementation {
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    55
            public Class<?> klazz() { return ConcurrentSkipListMap.class; }
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    56
            public Map emptyMap() { return new ConcurrentSkipListMap(); }
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    57
            public boolean isConcurrent() { return true; }
58892
35bac2745d04 8231592: Clarify that ConcurrentHashMap compute methods mapping functions execute at most once
dl
parents: 47304
diff changeset
    58
            public boolean remappingFunctionCalledAtMostOnce() { return false; };
47304
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    59
            public boolean permitsNullKeys() { return false; }
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    60
            public boolean permitsNullValues() { return false; }
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    61
            public boolean supportsSetValue() { return false; }
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    62
        }
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    63
        return newTestSuite(
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    64
            ConcurrentSkipListMapTest.class,
3f5f9bc0bdc2 8186171: HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
dl
parents: 47216
diff changeset
    65
            MapTest.testSuite(new Implementation()));
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    66
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    67
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    68
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    69
     * Returns a new map from Integers 1-5 to Strings "A"-"E".
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    70
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    71
    private static ConcurrentSkipListMap map5() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    72
        ConcurrentSkipListMap map = new ConcurrentSkipListMap();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    73
        assertTrue(map.isEmpty());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    74
        map.put(one, "A");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    75
        map.put(five, "E");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    76
        map.put(three, "C");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    77
        map.put(two, "B");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    78
        map.put(four, "D");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    79
        assertFalse(map.isEmpty());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    80
        assertEquals(5, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    81
        return map;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    82
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    83
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    84
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    85
     * clear removes all pairs
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    86
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    87
    public void testClear() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    88
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    89
        map.clear();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    90
        assertEquals(0, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    91
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    92
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    93
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    94
     * copy constructor creates map equal to source map
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    95
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    96
    public void testConstructFromSorted() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    97
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    98
        ConcurrentSkipListMap map2 = new ConcurrentSkipListMap(map);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    99
        assertEquals(map, map2);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   100
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   101
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   102
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   103
     * Maps with same contents are equal
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   104
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   105
    public void testEquals() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   106
        ConcurrentSkipListMap map1 = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   107
        ConcurrentSkipListMap map2 = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   108
        assertEquals(map1, map2);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   109
        assertEquals(map2, map1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   110
        map1.clear();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   111
        assertFalse(map1.equals(map2));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   112
        assertFalse(map2.equals(map1));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   113
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   114
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   115
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   116
     * containsKey returns true for contained key
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   117
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   118
    public void testContainsKey() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   119
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   120
        assertTrue(map.containsKey(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   121
        assertFalse(map.containsKey(zero));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   122
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   123
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   124
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   125
     * containsValue returns true for held values
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   126
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   127
    public void testContainsValue() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   128
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   129
        assertTrue(map.containsValue("A"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   130
        assertFalse(map.containsValue("Z"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   131
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   132
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   133
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   134
     * get returns the correct element at the given key,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   135
     * or null if not present
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   136
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   137
    public void testGet() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   138
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   139
        assertEquals("A", (String)map.get(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   140
        ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   141
        assertNull(empty.get(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   142
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   143
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   144
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   145
     * isEmpty is true of empty map and false for non-empty
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   146
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   147
    public void testIsEmpty() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   148
        ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   149
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   150
        assertTrue(empty.isEmpty());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   151
        assertFalse(map.isEmpty());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   152
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   153
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   154
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   155
     * firstKey returns first key
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   156
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   157
    public void testFirstKey() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   158
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   159
        assertEquals(one, map.firstKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   160
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   161
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   162
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   163
     * lastKey returns last key
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   164
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   165
    public void testLastKey() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   166
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   167
        assertEquals(five, map.lastKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   168
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   169
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   170
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   171
     * keySet.toArray returns contains all keys
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   172
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   173
    public void testKeySetToArray() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   174
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   175
        Set s = map.keySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   176
        Object[] ar = s.toArray();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   177
        assertTrue(s.containsAll(Arrays.asList(ar)));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   178
        assertEquals(5, ar.length);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   179
        ar[0] = m10;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   180
        assertFalse(s.containsAll(Arrays.asList(ar)));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   181
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   182
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   183
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   184
     * descendingkeySet.toArray returns contains all keys
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   185
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   186
    public void testDescendingKeySetToArray() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   187
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   188
        Set s = map.descendingKeySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   189
        Object[] ar = s.toArray();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   190
        assertEquals(5, ar.length);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   191
        assertTrue(s.containsAll(Arrays.asList(ar)));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   192
        ar[0] = m10;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   193
        assertFalse(s.containsAll(Arrays.asList(ar)));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   194
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   195
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   196
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   197
     * keySet returns a Set containing all the keys
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   198
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   199
    public void testKeySet() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   200
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   201
        Set s = map.keySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   202
        assertEquals(5, s.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   203
        assertTrue(s.contains(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   204
        assertTrue(s.contains(two));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   205
        assertTrue(s.contains(three));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   206
        assertTrue(s.contains(four));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   207
        assertTrue(s.contains(five));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   208
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   209
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   210
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   211
     * keySet is ordered
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   212
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   213
    public void testKeySetOrder() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   214
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   215
        Set s = map.keySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   216
        Iterator i = s.iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   217
        Integer last = (Integer)i.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   218
        assertEquals(last, one);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   219
        int count = 1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   220
        while (i.hasNext()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   221
            Integer k = (Integer)i.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   222
            assertTrue(last.compareTo(k) < 0);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   223
            last = k;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   224
            ++count;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   225
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   226
        assertEquals(5, count);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   227
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   228
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   229
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   230
     * descending iterator of key set is inverse ordered
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   231
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   232
    public void testKeySetDescendingIteratorOrder() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   233
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   234
        NavigableSet s = map.navigableKeySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   235
        Iterator i = s.descendingIterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   236
        Integer last = (Integer)i.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   237
        assertEquals(last, five);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   238
        int count = 1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   239
        while (i.hasNext()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   240
            Integer k = (Integer)i.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   241
            assertTrue(last.compareTo(k) > 0);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   242
            last = k;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   243
            ++count;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   244
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   245
        assertEquals(5, count);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   246
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   247
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   248
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   249
     * descendingKeySet is ordered
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   250
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   251
    public void testDescendingKeySetOrder() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   252
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   253
        Set s = map.descendingKeySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   254
        Iterator i = s.iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   255
        Integer last = (Integer)i.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   256
        assertEquals(last, five);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   257
        int count = 1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   258
        while (i.hasNext()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   259
            Integer k = (Integer)i.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   260
            assertTrue(last.compareTo(k) > 0);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   261
            last = k;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   262
            ++count;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   263
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   264
        assertEquals(5, count);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   265
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   266
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   267
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   268
     * descending iterator of descendingKeySet is ordered
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   269
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   270
    public void testDescendingKeySetDescendingIteratorOrder() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   271
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   272
        NavigableSet s = map.descendingKeySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   273
        Iterator i = s.descendingIterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   274
        Integer last = (Integer)i.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   275
        assertEquals(last, one);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   276
        int count = 1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   277
        while (i.hasNext()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   278
            Integer k = (Integer)i.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   279
            assertTrue(last.compareTo(k) < 0);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   280
            last = k;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   281
            ++count;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   282
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   283
        assertEquals(5, count);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   284
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   285
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   286
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   287
     * Values.toArray contains all values
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   288
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   289
    public void testValuesToArray() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   290
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   291
        Collection v = map.values();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   292
        Object[] ar = v.toArray();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   293
        ArrayList s = new ArrayList(Arrays.asList(ar));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   294
        assertEquals(5, ar.length);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   295
        assertTrue(s.contains("A"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   296
        assertTrue(s.contains("B"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   297
        assertTrue(s.contains("C"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   298
        assertTrue(s.contains("D"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   299
        assertTrue(s.contains("E"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   300
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   301
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   302
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   303
     * values collection contains all values
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   304
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   305
    public void testValues() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   306
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   307
        Collection s = map.values();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   308
        assertEquals(5, s.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   309
        assertTrue(s.contains("A"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   310
        assertTrue(s.contains("B"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   311
        assertTrue(s.contains("C"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   312
        assertTrue(s.contains("D"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   313
        assertTrue(s.contains("E"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   314
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   315
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   316
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   317
     * entrySet contains all pairs
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   318
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   319
    public void testEntrySet() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   320
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   321
        Set s = map.entrySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   322
        assertEquals(5, s.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   323
        Iterator it = s.iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   324
        while (it.hasNext()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   325
            Map.Entry e = (Map.Entry) it.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   326
            assertTrue(
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   327
                       (e.getKey().equals(one) && e.getValue().equals("A")) ||
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   328
                       (e.getKey().equals(two) && e.getValue().equals("B")) ||
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   329
                       (e.getKey().equals(three) && e.getValue().equals("C")) ||
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   330
                       (e.getKey().equals(four) && e.getValue().equals("D")) ||
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   331
                       (e.getKey().equals(five) && e.getValue().equals("E")));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   332
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   333
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   334
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   335
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   336
     * descendingEntrySet contains all pairs
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   337
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   338
    public void testDescendingEntrySet() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   339
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   340
        Set s = map.descendingMap().entrySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   341
        assertEquals(5, s.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   342
        Iterator it = s.iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   343
        while (it.hasNext()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   344
            Map.Entry e = (Map.Entry) it.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   345
            assertTrue(
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   346
                       (e.getKey().equals(one) && e.getValue().equals("A")) ||
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   347
                       (e.getKey().equals(two) && e.getValue().equals("B")) ||
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   348
                       (e.getKey().equals(three) && e.getValue().equals("C")) ||
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   349
                       (e.getKey().equals(four) && e.getValue().equals("D")) ||
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   350
                       (e.getKey().equals(five) && e.getValue().equals("E")));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   351
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   352
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   353
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   354
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   355
     * entrySet.toArray contains all entries
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   356
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   357
    public void testEntrySetToArray() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   358
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   359
        Set s = map.entrySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   360
        Object[] ar = s.toArray();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   361
        assertEquals(5, ar.length);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   362
        for (int i = 0; i < 5; ++i) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   363
            assertTrue(map.containsKey(((Map.Entry)(ar[i])).getKey()));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   364
            assertTrue(map.containsValue(((Map.Entry)(ar[i])).getValue()));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   365
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   366
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   367
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   368
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   369
     * descendingEntrySet.toArray contains all entries
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   370
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   371
    public void testDescendingEntrySetToArray() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   372
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   373
        Set s = map.descendingMap().entrySet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   374
        Object[] ar = s.toArray();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   375
        assertEquals(5, ar.length);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   376
        for (int i = 0; i < 5; ++i) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   377
            assertTrue(map.containsKey(((Map.Entry)(ar[i])).getKey()));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   378
            assertTrue(map.containsValue(((Map.Entry)(ar[i])).getValue()));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   379
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   380
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   381
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   382
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   383
     * putAll adds all key-value pairs from the given map
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   384
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   385
    public void testPutAll() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   386
        ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   387
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   388
        empty.putAll(map);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   389
        assertEquals(5, empty.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   390
        assertTrue(empty.containsKey(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   391
        assertTrue(empty.containsKey(two));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   392
        assertTrue(empty.containsKey(three));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   393
        assertTrue(empty.containsKey(four));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   394
        assertTrue(empty.containsKey(five));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   395
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   396
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   397
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   398
     * putIfAbsent works when the given key is not present
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   399
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   400
    public void testPutIfAbsent() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   401
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   402
        map.putIfAbsent(six, "Z");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   403
        assertTrue(map.containsKey(six));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   404
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   405
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   406
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   407
     * putIfAbsent does not add the pair if the key is already present
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   408
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   409
    public void testPutIfAbsent2() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   410
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   411
        assertEquals("A", map.putIfAbsent(one, "Z"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   412
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   413
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   414
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   415
     * replace fails when the given key is not present
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   416
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   417
    public void testReplace() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   418
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   419
        assertNull(map.replace(six, "Z"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   420
        assertFalse(map.containsKey(six));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   421
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   422
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   423
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   424
     * replace succeeds if the key is already present
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   425
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   426
    public void testReplace2() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   427
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   428
        assertNotNull(map.replace(one, "Z"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   429
        assertEquals("Z", map.get(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   430
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   431
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   432
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   433
     * replace value fails when the given key not mapped to expected value
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   434
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   435
    public void testReplaceValue() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   436
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   437
        assertEquals("A", map.get(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   438
        assertFalse(map.replace(one, "Z", "Z"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   439
        assertEquals("A", map.get(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   440
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   441
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   442
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   443
     * replace value succeeds when the given key mapped to expected value
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   444
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   445
    public void testReplaceValue2() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   446
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   447
        assertEquals("A", map.get(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   448
        assertTrue(map.replace(one, "A", "Z"));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   449
        assertEquals("Z", map.get(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   450
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   451
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   452
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   453
     * remove removes the correct key-value pair from the map
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   454
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   455
    public void testRemove() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   456
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   457
        map.remove(five);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   458
        assertEquals(4, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   459
        assertFalse(map.containsKey(five));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   460
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   461
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   462
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   463
     * remove(key,value) removes only if pair present
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   464
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   465
    public void testRemove2() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   466
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   467
        assertTrue(map.containsKey(five));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   468
        assertEquals("E", map.get(five));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   469
        map.remove(five, "E");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   470
        assertEquals(4, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   471
        assertFalse(map.containsKey(five));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   472
        map.remove(four, "A");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   473
        assertEquals(4, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   474
        assertTrue(map.containsKey(four));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   475
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   476
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   477
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   478
     * lowerEntry returns preceding entry.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   479
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   480
    public void testLowerEntry() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   481
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   482
        Map.Entry e1 = map.lowerEntry(three);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   483
        assertEquals(two, e1.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   484
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   485
        Map.Entry e2 = map.lowerEntry(six);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   486
        assertEquals(five, e2.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   487
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   488
        Map.Entry e3 = map.lowerEntry(one);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   489
        assertNull(e3);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   490
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   491
        Map.Entry e4 = map.lowerEntry(zero);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   492
        assertNull(e4);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   493
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   494
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   495
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   496
     * higherEntry returns next entry.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   497
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   498
    public void testHigherEntry() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   499
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   500
        Map.Entry e1 = map.higherEntry(three);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   501
        assertEquals(four, e1.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   502
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   503
        Map.Entry e2 = map.higherEntry(zero);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   504
        assertEquals(one, e2.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   505
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   506
        Map.Entry e3 = map.higherEntry(five);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   507
        assertNull(e3);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   508
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   509
        Map.Entry e4 = map.higherEntry(six);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   510
        assertNull(e4);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   511
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   512
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   513
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   514
     * floorEntry returns preceding entry.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   515
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   516
    public void testFloorEntry() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   517
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   518
        Map.Entry e1 = map.floorEntry(three);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   519
        assertEquals(three, e1.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   520
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   521
        Map.Entry e2 = map.floorEntry(six);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   522
        assertEquals(five, e2.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   523
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   524
        Map.Entry e3 = map.floorEntry(one);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   525
        assertEquals(one, e3.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   526
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   527
        Map.Entry e4 = map.floorEntry(zero);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   528
        assertNull(e4);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   529
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   530
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   531
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   532
     * ceilingEntry returns next entry.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   533
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   534
    public void testCeilingEntry() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   535
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   536
        Map.Entry e1 = map.ceilingEntry(three);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   537
        assertEquals(three, e1.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   538
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   539
        Map.Entry e2 = map.ceilingEntry(zero);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   540
        assertEquals(one, e2.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   541
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   542
        Map.Entry e3 = map.ceilingEntry(five);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   543
        assertEquals(five, e3.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   544
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   545
        Map.Entry e4 = map.ceilingEntry(six);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   546
        assertNull(e4);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   547
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   548
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   549
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   550
     * lowerEntry, higherEntry, ceilingEntry, and floorEntry return
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   551
     * immutable entries
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   552
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   553
    public void testEntryImmutability() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   554
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   555
        Map.Entry e = map.lowerEntry(three);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   556
        assertEquals(two, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   557
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   558
            e.setValue("X");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   559
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   560
        } catch (UnsupportedOperationException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   561
        e = map.higherEntry(zero);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   562
        assertEquals(one, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   563
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   564
            e.setValue("X");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   565
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   566
        } catch (UnsupportedOperationException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   567
        e = map.floorEntry(one);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   568
        assertEquals(one, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   569
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   570
            e.setValue("X");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   571
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   572
        } catch (UnsupportedOperationException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   573
        e = map.ceilingEntry(five);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   574
        assertEquals(five, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   575
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   576
            e.setValue("X");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   577
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   578
        } catch (UnsupportedOperationException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   579
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   580
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   581
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   582
     * lowerKey returns preceding element
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   583
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   584
    public void testLowerKey() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   585
        ConcurrentSkipListMap q = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   586
        Object e1 = q.lowerKey(three);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   587
        assertEquals(two, e1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   588
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   589
        Object e2 = q.lowerKey(six);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   590
        assertEquals(five, e2);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   591
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   592
        Object e3 = q.lowerKey(one);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   593
        assertNull(e3);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   594
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   595
        Object e4 = q.lowerKey(zero);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   596
        assertNull(e4);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   597
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   598
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   599
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   600
     * higherKey returns next element
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   601
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   602
    public void testHigherKey() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   603
        ConcurrentSkipListMap q = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   604
        Object e1 = q.higherKey(three);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   605
        assertEquals(four, e1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   606
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   607
        Object e2 = q.higherKey(zero);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   608
        assertEquals(one, e2);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   609
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   610
        Object e3 = q.higherKey(five);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   611
        assertNull(e3);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   612
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   613
        Object e4 = q.higherKey(six);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   614
        assertNull(e4);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   615
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   616
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   617
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   618
     * floorKey returns preceding element
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   619
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   620
    public void testFloorKey() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   621
        ConcurrentSkipListMap q = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   622
        Object e1 = q.floorKey(three);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   623
        assertEquals(three, e1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   624
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   625
        Object e2 = q.floorKey(six);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   626
        assertEquals(five, e2);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   627
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   628
        Object e3 = q.floorKey(one);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   629
        assertEquals(one, e3);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   630
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   631
        Object e4 = q.floorKey(zero);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   632
        assertNull(e4);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   633
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   634
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   635
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   636
     * ceilingKey returns next element
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   637
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   638
    public void testCeilingKey() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   639
        ConcurrentSkipListMap q = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   640
        Object e1 = q.ceilingKey(three);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   641
        assertEquals(three, e1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   642
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   643
        Object e2 = q.ceilingKey(zero);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   644
        assertEquals(one, e2);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   645
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   646
        Object e3 = q.ceilingKey(five);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   647
        assertEquals(five, e3);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   648
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   649
        Object e4 = q.ceilingKey(six);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   650
        assertNull(e4);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   651
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   652
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   653
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   654
     * pollFirstEntry returns entries in order
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   655
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   656
    public void testPollFirstEntry() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   657
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   658
        Map.Entry e = map.pollFirstEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   659
        assertEquals(one, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   660
        assertEquals("A", e.getValue());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   661
        e = map.pollFirstEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   662
        assertEquals(two, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   663
        map.put(one, "A");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   664
        e = map.pollFirstEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   665
        assertEquals(one, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   666
        assertEquals("A", e.getValue());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   667
        e = map.pollFirstEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   668
        assertEquals(three, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   669
        map.remove(four);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   670
        e = map.pollFirstEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   671
        assertEquals(five, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   672
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   673
            e.setValue("A");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   674
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   675
        } catch (UnsupportedOperationException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   676
        e = map.pollFirstEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   677
        assertNull(e);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   678
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   679
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   680
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   681
     * pollLastEntry returns entries in order
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   682
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   683
    public void testPollLastEntry() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   684
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   685
        Map.Entry e = map.pollLastEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   686
        assertEquals(five, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   687
        assertEquals("E", e.getValue());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   688
        e = map.pollLastEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   689
        assertEquals(four, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   690
        map.put(five, "E");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   691
        e = map.pollLastEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   692
        assertEquals(five, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   693
        assertEquals("E", e.getValue());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   694
        e = map.pollLastEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   695
        assertEquals(three, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   696
        map.remove(two);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   697
        e = map.pollLastEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   698
        assertEquals(one, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   699
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   700
            e.setValue("E");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   701
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   702
        } catch (UnsupportedOperationException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   703
        e = map.pollLastEntry();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   704
        assertNull(e);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   705
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   706
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   707
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   708
     * size returns the correct values
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   709
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   710
    public void testSize() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   711
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   712
        ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   713
        assertEquals(0, empty.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   714
        assertEquals(5, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   715
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   716
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   717
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   718
     * toString contains toString of elements
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   719
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   720
    public void testToString() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   721
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   722
        String s = map.toString();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   723
        for (int i = 1; i <= 5; ++i) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   724
            assertTrue(s.contains(String.valueOf(i)));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   725
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   726
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   727
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   728
    // Exception tests
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   729
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   730
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   731
     * get(null) of nonempty map throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   732
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   733
    public void testGet_NullPointerException() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   734
        ConcurrentSkipListMap c = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   735
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   736
            c.get(null);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   737
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   738
        } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   739
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   740
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   741
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   742
     * containsKey(null) of nonempty map throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   743
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   744
    public void testContainsKey_NullPointerException() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   745
        ConcurrentSkipListMap c = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   746
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   747
            c.containsKey(null);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   748
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   749
        } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   750
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   751
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   752
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   753
     * containsValue(null) throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   754
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   755
    public void testContainsValue_NullPointerException() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   756
        ConcurrentSkipListMap c = new ConcurrentSkipListMap();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   757
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   758
            c.containsValue(null);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   759
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   760
        } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   761
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   762
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   763
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   764
     * put(null,x) throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   765
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   766
    public void testPut1_NullPointerException() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   767
        ConcurrentSkipListMap c = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   768
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   769
            c.put(null, "whatever");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   770
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   771
        } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   772
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   773
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   774
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   775
     * putIfAbsent(null, x) throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   776
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   777
    public void testPutIfAbsent1_NullPointerException() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   778
        ConcurrentSkipListMap c = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   779
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   780
            c.putIfAbsent(null, "whatever");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   781
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   782
        } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   783
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   784
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   785
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   786
     * replace(null, x) throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   787
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   788
    public void testReplace_NullPointerException() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   789
        ConcurrentSkipListMap c = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   790
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   791
            c.replace(null, "whatever");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   792
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   793
        } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   794
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   795
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   796
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   797
     * replace(null, x, y) throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   798
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   799
    public void testReplaceValue_NullPointerException() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   800
        ConcurrentSkipListMap c = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   801
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   802
            c.replace(null, one, "whatever");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   803
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   804
        } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   805
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   806
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   807
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   808
     * remove(null) throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   809
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   810
    public void testRemove1_NullPointerException() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   811
        ConcurrentSkipListMap c = new ConcurrentSkipListMap();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   812
        c.put("sadsdf", "asdads");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   813
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   814
            c.remove(null);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   815
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   816
        } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   817
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   818
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   819
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   820
     * remove(null, x) throws NPE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   821
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   822
    public void testRemove2_NullPointerException() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   823
        ConcurrentSkipListMap c = new ConcurrentSkipListMap();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   824
        c.put("sadsdf", "asdads");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   825
        try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   826
            c.remove(null, "whatever");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   827
            shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   828
        } catch (NullPointerException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   829
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   830
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   831
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   832
     * remove(x, null) returns false
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   833
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   834
    public void testRemove3() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   835
        ConcurrentSkipListMap c = new ConcurrentSkipListMap();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   836
        c.put("sadsdf", "asdads");
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   837
        assertFalse(c.remove("sadsdf", null));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   838
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   839
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   840
    /**
46146
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   841
     * A cloned map equals original
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   842
     */
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   843
    public void testClone() {
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   844
        ConcurrentSkipListMap x = map5();
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   845
        ConcurrentSkipListMap y = x.clone();
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   846
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   847
        assertNotSame(x, y);
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   848
        assertEquals(x.size(), y.size());
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   849
        assertEquals(x.toString(), y.toString());
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   850
        assertEquals(x, y);
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   851
        assertEquals(y, x);
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   852
        y.clear();
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   853
        assertTrue(y.isEmpty());
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   854
        assertFalse(x.equals(y));
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   855
    }
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   856
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   857
    /**
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   858
     * A deserialized/reserialized map equals original
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   859
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   860
    public void testSerialization() throws Exception {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   861
        NavigableMap x = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   862
        NavigableMap y = serialClone(x);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   863
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   864
        assertNotSame(x, y);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   865
        assertEquals(x.size(), y.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   866
        assertEquals(x.toString(), y.toString());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   867
        assertEquals(x, y);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   868
        assertEquals(y, x);
46146
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   869
        y.clear();
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   870
        assertTrue(y.isEmpty());
b3e220a04d3f 8185099: Miscellaneous changes imported from jsr166 CVS 2017-08
dl
parents: 41131
diff changeset
   871
        assertFalse(x.equals(y));
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   872
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   873
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   874
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   875
     * subMap returns map with keys in requested range
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   876
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   877
    public void testSubMapContents() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   878
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   879
        NavigableMap sm = map.subMap(two, true, four, false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   880
        assertEquals(two, sm.firstKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   881
        assertEquals(three, sm.lastKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   882
        assertEquals(2, sm.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   883
        assertFalse(sm.containsKey(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   884
        assertTrue(sm.containsKey(two));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   885
        assertTrue(sm.containsKey(three));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   886
        assertFalse(sm.containsKey(four));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   887
        assertFalse(sm.containsKey(five));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   888
        Iterator i = sm.keySet().iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   889
        Object k;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   890
        k = (Integer)(i.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   891
        assertEquals(two, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   892
        k = (Integer)(i.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   893
        assertEquals(three, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   894
        assertFalse(i.hasNext());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   895
        Iterator r = sm.descendingKeySet().iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   896
        k = (Integer)(r.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   897
        assertEquals(three, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   898
        k = (Integer)(r.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   899
        assertEquals(two, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   900
        assertFalse(r.hasNext());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   901
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   902
        Iterator j = sm.keySet().iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   903
        j.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   904
        j.remove();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   905
        assertFalse(map.containsKey(two));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   906
        assertEquals(4, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   907
        assertEquals(1, sm.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   908
        assertEquals(three, sm.firstKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   909
        assertEquals(three, sm.lastKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   910
        assertEquals("C", sm.remove(three));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   911
        assertTrue(sm.isEmpty());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   912
        assertEquals(3, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   913
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   914
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   915
    public void testSubMapContents2() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   916
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   917
        NavigableMap sm = map.subMap(two, true, three, false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   918
        assertEquals(1, sm.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   919
        assertEquals(two, sm.firstKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   920
        assertEquals(two, sm.lastKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   921
        assertFalse(sm.containsKey(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   922
        assertTrue(sm.containsKey(two));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   923
        assertFalse(sm.containsKey(three));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   924
        assertFalse(sm.containsKey(four));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   925
        assertFalse(sm.containsKey(five));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   926
        Iterator i = sm.keySet().iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   927
        Object k;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   928
        k = (Integer)(i.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   929
        assertEquals(two, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   930
        assertFalse(i.hasNext());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   931
        Iterator r = sm.descendingKeySet().iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   932
        k = (Integer)(r.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   933
        assertEquals(two, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   934
        assertFalse(r.hasNext());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   935
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   936
        Iterator j = sm.keySet().iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   937
        j.next();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   938
        j.remove();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   939
        assertFalse(map.containsKey(two));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   940
        assertEquals(4, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   941
        assertEquals(0, sm.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   942
        assertTrue(sm.isEmpty());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   943
        assertSame(sm.remove(three), null);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   944
        assertEquals(4, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   945
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   946
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   947
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   948
     * headMap returns map with keys in requested range
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   949
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   950
    public void testHeadMapContents() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   951
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   952
        NavigableMap sm = map.headMap(four, false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   953
        assertTrue(sm.containsKey(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   954
        assertTrue(sm.containsKey(two));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   955
        assertTrue(sm.containsKey(three));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   956
        assertFalse(sm.containsKey(four));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   957
        assertFalse(sm.containsKey(five));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   958
        Iterator i = sm.keySet().iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   959
        Object k;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   960
        k = (Integer)(i.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   961
        assertEquals(one, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   962
        k = (Integer)(i.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   963
        assertEquals(two, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   964
        k = (Integer)(i.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   965
        assertEquals(three, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   966
        assertFalse(i.hasNext());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   967
        sm.clear();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   968
        assertTrue(sm.isEmpty());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   969
        assertEquals(2, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   970
        assertEquals(four, map.firstKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   971
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   972
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   973
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   974
     * tailMap returns map with keys in requested range
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   975
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   976
    public void testTailMapContents() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   977
        ConcurrentSkipListMap map = map5();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   978
        NavigableMap sm = map.tailMap(two, true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   979
        assertFalse(sm.containsKey(one));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   980
        assertTrue(sm.containsKey(two));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   981
        assertTrue(sm.containsKey(three));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   982
        assertTrue(sm.containsKey(four));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   983
        assertTrue(sm.containsKey(five));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   984
        Iterator i = sm.keySet().iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   985
        Object k;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   986
        k = (Integer)(i.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   987
        assertEquals(two, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   988
        k = (Integer)(i.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   989
        assertEquals(three, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   990
        k = (Integer)(i.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   991
        assertEquals(four, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   992
        k = (Integer)(i.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   993
        assertEquals(five, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   994
        assertFalse(i.hasNext());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   995
        Iterator r = sm.descendingKeySet().iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   996
        k = (Integer)(r.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   997
        assertEquals(five, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   998
        k = (Integer)(r.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   999
        assertEquals(four, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1000
        k = (Integer)(r.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1001
        assertEquals(three, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1002
        k = (Integer)(r.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1003
        assertEquals(two, k);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1004
        assertFalse(r.hasNext());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1005
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1006
        Iterator ei = sm.entrySet().iterator();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1007
        Map.Entry e;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1008
        e = (Map.Entry)(ei.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1009
        assertEquals(two, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1010
        assertEquals("B", e.getValue());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1011
        e = (Map.Entry)(ei.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1012
        assertEquals(three, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1013
        assertEquals("C", e.getValue());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1014
        e = (Map.Entry)(ei.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1015
        assertEquals(four, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1016
        assertEquals("D", e.getValue());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1017
        e = (Map.Entry)(ei.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1018
        assertEquals(five, e.getKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1019
        assertEquals("E", e.getValue());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1020
        assertFalse(i.hasNext());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1021
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1022
        NavigableMap ssm = sm.tailMap(four, true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1023
        assertEquals(four, ssm.firstKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1024
        assertEquals(five, ssm.lastKey());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1025
        assertEquals("D", ssm.remove(four));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1026
        assertEquals(1, ssm.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1027
        assertEquals(3, sm.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1028
        assertEquals(4, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1029
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1030
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1031
    Random rnd = new Random(666);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1032
    BitSet bs;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1033
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1034
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1035
     * Submaps of submaps subdivide correctly
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1036
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1037
    public void testRecursiveSubMaps() throws Exception {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1038
        int mapSize = expensiveTests ? 1000 : 100;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1039
        Class cl = ConcurrentSkipListMap.class;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1040
        NavigableMap<Integer, Integer> map = newMap(cl);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1041
        bs = new BitSet(mapSize);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1042
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1043
        populate(map, mapSize);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1044
        check(map,                 0, mapSize - 1, true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1045
        check(map.descendingMap(), 0, mapSize - 1, false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1046
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1047
        mutateMap(map, 0, mapSize - 1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1048
        check(map,                 0, mapSize - 1, true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1049
        check(map.descendingMap(), 0, mapSize - 1, false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1050
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1051
        bashSubMap(map.subMap(0, true, mapSize, false),
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1052
                   0, mapSize - 1, true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1053
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1054
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1055
    static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1056
        NavigableMap<Integer, Integer> result =
41131
87edc8451f8a 8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents: 35394
diff changeset
  1057
            (NavigableMap<Integer, Integer>) cl.getConstructor().newInstance();
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1058
        assertEquals(0, result.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1059
        assertFalse(result.keySet().iterator().hasNext());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1060
        return result;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1061
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1062
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1063
    void populate(NavigableMap<Integer, Integer> map, int limit) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1064
        for (int i = 0, n = 2 * limit / 3; i < n; i++) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1065
            int key = rnd.nextInt(limit);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1066
            put(map, key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1067
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1068
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1069
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1070
    void mutateMap(NavigableMap<Integer, Integer> map, int min, int max) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1071
        int size = map.size();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1072
        int rangeSize = max - min + 1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1073
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1074
        // Remove a bunch of entries directly
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1075
        for (int i = 0, n = rangeSize / 2; i < n; i++) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1076
            remove(map, min - 5 + rnd.nextInt(rangeSize + 10));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1077
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1078
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1079
        // Remove a bunch of entries with iterator
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1080
        for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1081
            if (rnd.nextBoolean()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1082
                bs.clear(it.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1083
                it.remove();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1084
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1085
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1086
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1087
        // Add entries till we're back to original size
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1088
        while (map.size() < size) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1089
            int key = min + rnd.nextInt(rangeSize);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1090
            assertTrue(key >= min && key <= max);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1091
            put(map, key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1092
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1093
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1094
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1095
    void mutateSubMap(NavigableMap<Integer, Integer> map, int min, int max) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1096
        int size = map.size();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1097
        int rangeSize = max - min + 1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1098
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1099
        // Remove a bunch of entries directly
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1100
        for (int i = 0, n = rangeSize / 2; i < n; i++) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1101
            remove(map, min - 5 + rnd.nextInt(rangeSize + 10));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1102
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1103
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1104
        // Remove a bunch of entries with iterator
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1105
        for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1106
            if (rnd.nextBoolean()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1107
                bs.clear(it.next());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1108
                it.remove();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1109
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1110
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1111
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1112
        // Add entries till we're back to original size
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1113
        while (map.size() < size) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1114
            int key = min - 5 + rnd.nextInt(rangeSize + 10);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1115
            if (key >= min && key <= max) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1116
                put(map, key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1117
            } else {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1118
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1119
                    map.put(key, 2 * key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1120
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1121
                } catch (IllegalArgumentException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1122
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1123
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1124
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1125
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1126
    void put(NavigableMap<Integer, Integer> map, int key) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1127
        if (map.put(key, 2 * key) == null)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1128
            bs.set(key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1129
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1130
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1131
    void remove(NavigableMap<Integer, Integer> map, int key) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1132
        if (map.remove(key) != null)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1133
            bs.clear(key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1134
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1135
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1136
    void bashSubMap(NavigableMap<Integer, Integer> map,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1137
                    int min, int max, boolean ascending) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1138
        check(map, min, max, ascending);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1139
        check(map.descendingMap(), min, max, !ascending);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1140
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1141
        mutateSubMap(map, min, max);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1142
        check(map, min, max, ascending);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1143
        check(map.descendingMap(), min, max, !ascending);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1144
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1145
        // Recurse
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1146
        if (max - min < 2)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1147
            return;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1148
        int midPoint = (min + max) / 2;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1149
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1150
        // headMap - pick direction and endpoint inclusion randomly
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1151
        boolean incl = rnd.nextBoolean();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1152
        NavigableMap<Integer,Integer> hm = map.headMap(midPoint, incl);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1153
        if (ascending) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1154
            if (rnd.nextBoolean())
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1155
                bashSubMap(hm, min, midPoint - (incl ? 0 : 1), true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1156
            else
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1157
                bashSubMap(hm.descendingMap(), min, midPoint - (incl ? 0 : 1),
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1158
                           false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1159
        } else {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1160
            if (rnd.nextBoolean())
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1161
                bashSubMap(hm, midPoint + (incl ? 0 : 1), max, false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1162
            else
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1163
                bashSubMap(hm.descendingMap(), midPoint + (incl ? 0 : 1), max,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1164
                           true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1165
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1166
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1167
        // tailMap - pick direction and endpoint inclusion randomly
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1168
        incl = rnd.nextBoolean();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1169
        NavigableMap<Integer,Integer> tm = map.tailMap(midPoint,incl);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1170
        if (ascending) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1171
            if (rnd.nextBoolean())
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1172
                bashSubMap(tm, midPoint + (incl ? 0 : 1), max, true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1173
            else
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1174
                bashSubMap(tm.descendingMap(), midPoint + (incl ? 0 : 1), max,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1175
                           false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1176
        } else {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1177
            if (rnd.nextBoolean()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1178
                bashSubMap(tm, min, midPoint - (incl ? 0 : 1), false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1179
            } else {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1180
                bashSubMap(tm.descendingMap(), min, midPoint - (incl ? 0 : 1),
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1181
                           true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1182
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1183
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1184
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1185
        // subMap - pick direction and endpoint inclusion randomly
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1186
        int rangeSize = max - min + 1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1187
        int[] endpoints = new int[2];
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1188
        endpoints[0] = min + rnd.nextInt(rangeSize);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1189
        endpoints[1] = min + rnd.nextInt(rangeSize);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1190
        Arrays.sort(endpoints);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1191
        boolean lowIncl = rnd.nextBoolean();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1192
        boolean highIncl = rnd.nextBoolean();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1193
        if (ascending) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1194
            NavigableMap<Integer,Integer> sm = map.subMap(
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1195
                endpoints[0], lowIncl, endpoints[1], highIncl);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1196
            if (rnd.nextBoolean())
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1197
                bashSubMap(sm, endpoints[0] + (lowIncl ? 0 : 1),
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1198
                           endpoints[1] - (highIncl ? 0 : 1), true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1199
            else
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1200
                bashSubMap(sm.descendingMap(), endpoints[0] + (lowIncl ? 0 : 1),
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1201
                           endpoints[1] - (highIncl ? 0 : 1), false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1202
        } else {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1203
            NavigableMap<Integer,Integer> sm = map.subMap(
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1204
                endpoints[1], highIncl, endpoints[0], lowIncl);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1205
            if (rnd.nextBoolean())
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1206
                bashSubMap(sm, endpoints[0] + (lowIncl ? 0 : 1),
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1207
                           endpoints[1] - (highIncl ? 0 : 1), false);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1208
            else
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1209
                bashSubMap(sm.descendingMap(), endpoints[0] + (lowIncl ? 0 : 1),
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1210
                           endpoints[1] - (highIncl ? 0 : 1), true);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1211
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1212
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1213
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1214
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1215
     * min and max are both inclusive.  If max < min, interval is empty.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1216
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1217
    void check(NavigableMap<Integer, Integer> map,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1218
                      final int min, final int max, final boolean ascending) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1219
        class ReferenceSet {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1220
            int lower(int key) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1221
                return ascending ? lowerAscending(key) : higherAscending(key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1222
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1223
            int floor(int key) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1224
                return ascending ? floorAscending(key) : ceilingAscending(key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1225
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1226
            int ceiling(int key) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1227
                return ascending ? ceilingAscending(key) : floorAscending(key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1228
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1229
            int higher(int key) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1230
                return ascending ? higherAscending(key) : lowerAscending(key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1231
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1232
            int first() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1233
                return ascending ? firstAscending() : lastAscending();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1234
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1235
            int last() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1236
                return ascending ? lastAscending() : firstAscending();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1237
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1238
            int lowerAscending(int key) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1239
                return floorAscending(key - 1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1240
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1241
            int floorAscending(int key) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1242
                if (key < min)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1243
                    return -1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1244
                else if (key > max)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1245
                    key = max;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1246
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1247
                // BitSet should support this! Test would run much faster
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1248
                while (key >= min) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1249
                    if (bs.get(key))
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1250
                        return key;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1251
                    key--;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1252
                }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1253
                return -1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1254
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1255
            int ceilingAscending(int key) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1256
                if (key < min)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1257
                    key = min;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1258
                else if (key > max)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1259
                    return -1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1260
                int result = bs.nextSetBit(key);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1261
                return result > max ? -1 : result;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1262
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1263
            int higherAscending(int key) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1264
                return ceilingAscending(key + 1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1265
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1266
            private int firstAscending() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1267
                int result = ceilingAscending(min);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1268
                return result > max ? -1 : result;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1269
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1270
            private int lastAscending() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1271
                int result = floorAscending(max);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1272
                return result < min ? -1 : result;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1273
            }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1274
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1275
        ReferenceSet rs = new ReferenceSet();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1276
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1277
        // Test contents using containsKey
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1278
        int size = 0;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1279
        for (int i = min; i <= max; i++) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1280
            boolean bsContainsI = bs.get(i);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1281
            assertEquals(bsContainsI, map.containsKey(i));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1282
            if (bsContainsI)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1283
                size++;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1284
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1285
        assertEquals(size, map.size());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1286
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1287
        // Test contents using contains keySet iterator
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1288
        int size2 = 0;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1289
        int previousKey = -1;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1290
        for (int key : map.keySet()) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1291
            assertTrue(bs.get(key));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1292
            size2++;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1293
            assertTrue(previousKey < 0 ||
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1294
                (ascending ? key - previousKey > 0 : key - previousKey < 0));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1295
            previousKey = key;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1296
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1297
        assertEquals(size2, size);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1298
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1299
        // Test navigation ops
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1300
        for (int key = min - 1; key <= max + 1; key++) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1301
            assertEq(map.lowerKey(key), rs.lower(key));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1302
            assertEq(map.floorKey(key), rs.floor(key));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1303
            assertEq(map.higherKey(key), rs.higher(key));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1304
            assertEq(map.ceilingKey(key), rs.ceiling(key));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1305
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1306
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1307
        // Test extrema
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1308
        if (map.size() != 0) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1309
            assertEq(map.firstKey(), rs.first());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1310
            assertEq(map.lastKey(), rs.last());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1311
        } else {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1312
            assertEq(rs.first(), -1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1313
            assertEq(rs.last(),  -1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1314
            try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1315
                map.firstKey();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1316
                shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1317
            } catch (NoSuchElementException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1318
            try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1319
                map.lastKey();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1320
                shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1321
            } catch (NoSuchElementException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1322
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1323
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1324
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1325
    static void assertEq(Integer i, int j) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1326
        if (i == null)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1327
            assertEquals(j, -1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1328
        else
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1329
            assertEquals((int) i, j);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1330
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1331
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1332
    static boolean eq(Integer i, int j) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1333
        return (i == null) ? j == -1 : i == j;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1334
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1335
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
  1336
}