Package java.util

Examples of java.util.NavigableSet


        assertNull(keySet.pollLast());
    }

    public void test_DescendingSubMapKeySet_pollFirst() {
        String endKey = new Integer(2).toString();
        NavigableSet keySet = tm.headMap(endKey, true).navigableKeySet();
        NavigableSet descendingKeySet = keySet.descendingSet();
        assertEquals(endKey, descendingKeySet.pollFirst());
    }
View Full Code Here


        NavigableSet descendingKeySet = keySet.descendingSet();
        assertEquals(endKey, descendingKeySet.pollFirst());
    }

    public void test_DescendingSubMapKeySet_pollLast_startExcluded_endExcluded() {
        NavigableSet keySet = navigableMap_startExcluded_endExcluded
                .navigableKeySet();
        NavigableSet descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();
        assertEquals(8, keySet.size());
        for (int value = 108; value > 100; value--) {
            assertEquals(new Integer(value).toString(), keySet.pollLast());
        }
        assertEquals(0, keySet.size());
View Full Code Here

        assertEquals(0, keySet.size());
        assertNull(keySet.pollLast());
    }

    public void test_DescendingSubMapKeySet_pollLast_startExcluded_endIncluded() {
        NavigableSet keySet = navigableMap_startExcluded_endIncluded
                .navigableKeySet();
        NavigableSet descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();
        assertEquals(9, keySet.size());
        for (int value = 109; value > 100; value--) {
            assertEquals(new Integer(value).toString(), keySet.pollLast());
        }
        assertEquals(0, keySet.size());
View Full Code Here

        assertEquals(0, keySet.size());
        assertNull(keySet.pollLast());
    }

    public void test_DescendingSubMapKeySet_pollLast_startIncluded_endExcluded() {
        NavigableSet keySet = navigableMap_startIncluded_endExcluded
                .navigableKeySet();
        NavigableSet descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();
        assertEquals(9, keySet.size());
        for (int value = 108; value > 99; value--) {
            assertEquals(new Integer(value).toString(), keySet.pollLast());
        }
        assertEquals(0, keySet.size());
View Full Code Here

        assertEquals(0, keySet.size());
        assertNull(keySet.pollLast());
    }

    public void test_DescendingSubMapKeySet_pollLast_startIncluded_endIncluded() {
        NavigableSet keySet = navigableMap_startIncluded_endIncluded
                .navigableKeySet();
        NavigableSet descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();
        assertEquals(10, keySet.size());
        for (int value = 109; value > 99; value--) {
            assertEquals(new Integer(value).toString(), keySet.pollLast());
        }
        assertEquals(0, keySet.size());
View Full Code Here

        assertNull(keySet.pollLast());
    }

    public void test_DescendingSubMapKeySet_pollLast() {
        String endKey = new Integer(2).toString();
        NavigableSet keySet = tm.headMap(endKey, true).navigableKeySet();
        NavigableSet descendingKeySet = keySet.descendingSet();
        assertEquals(new Integer(0).toString(), descendingKeySet.pollLast());
    }
View Full Code Here

        NavigableSet descendingKeySet = keySet.descendingSet();
        assertEquals(new Integer(0).toString(), descendingKeySet.pollLast());
    }

    public void test_DescendingSubMapKeySet_headSet() {
        NavigableSet keySet, descendingKeySet;
        SortedSet headSet;
        String endKey, key;
        Iterator iterator;
        int index;

        keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        endKey = new Integer(99).toString();
        try {
            descendingKeySet.headSet(endKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        endKey = new Integer(100).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        endKey = new Integer(101).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(101, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(101, index);

        headSet = descendingKeySet.headSet(endKey, true);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        for (int i = 102; i < 109; i++) {
            endKey = new Integer(i).toString();
            headSet = descendingKeySet.headSet(endKey);
            iterator = headSet.iterator();
            int j;
            for (j = 108; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i, j);

            headSet = descendingKeySet.headSet(endKey, false);
            iterator = headSet.iterator();
            for (j = 108; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i, j);

            headSet = descendingKeySet.headSet(endKey, true);
            iterator = headSet.iterator();
            for (j = 108; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i - 1, j);
        }

        endKey = new Integer(109).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(108, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(108, index);

        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        endKey = new Integer(110).toString();
        try {
            descendingKeySet.headSet(endKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        endKey = new Integer(99).toString();
        try {
            descendingKeySet.headSet(endKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        endKey = new Integer(100).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        endKey = new Integer(101).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(101, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(101, index);

        headSet = descendingKeySet.headSet(endKey, true);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        for (int i = 102; i < 109; i++) {
            endKey = new Integer(i).toString();
            headSet = descendingKeySet.headSet(endKey);
            iterator = headSet.iterator();
            int j;
            for (j = 109; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i, j);

            headSet = descendingKeySet.headSet(endKey, false);
            iterator = headSet.iterator();
            for (j = 109; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i, j);

            headSet = descendingKeySet.headSet(endKey, true);
            iterator = headSet.iterator();
            for (j = 109; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i - 1, j);
        }

        endKey = new Integer(109).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(109, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(109, index);

        headSet = descendingKeySet.headSet(endKey, true);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(108, index);

        endKey = new Integer(110).toString();
        try {
            descendingKeySet.headSet(endKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        endKey = new Integer(99).toString();
        try {
            descendingKeySet.headSet(endKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        endKey = new Integer(100).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        headSet = descendingKeySet.headSet(endKey, true);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(99, index);

        endKey = new Integer(101).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(101, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(101, index);

        headSet = descendingKeySet.headSet(endKey, true);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        for (int i = 102; i < 109; i++) {
            endKey = new Integer(i).toString();
            headSet = descendingKeySet.headSet(endKey);
            iterator = headSet.iterator();
            int j;
            for (j = 108; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i, j);

            headSet = descendingKeySet.headSet(endKey, false);
            iterator = headSet.iterator();
            for (j = 108; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i, j);

            headSet = descendingKeySet.headSet(endKey, true);
            iterator = headSet.iterator();
            for (j = 108; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i - 1, j);
        }

        endKey = new Integer(109).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(108, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 108; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(108, index);

        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        endKey = new Integer(110).toString();
        try {
            descendingKeySet.headSet(endKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        endKey = new Integer(99).toString();
        try {
            descendingKeySet.headSet(endKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        endKey = new Integer(100).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        headSet = descendingKeySet.headSet(endKey, true);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(99, index);

        endKey = new Integer(101).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(101, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(101, index);

        headSet = descendingKeySet.headSet(endKey, true);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        for (int i = 102; i < 109; i++) {
            endKey = new Integer(i).toString();
            headSet = descendingKeySet.headSet(endKey);
            iterator = headSet.iterator();
            int j;
            for (j = 109; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i, j);

            headSet = descendingKeySet.headSet(endKey, false);
            iterator = headSet.iterator();
            for (j = 109; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i, j);

            headSet = descendingKeySet.headSet(endKey, true);
            iterator = headSet.iterator();
            for (j = 109; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(i - 1, j);
        }

        endKey = new Integer(109).toString();
        headSet = descendingKeySet.headSet(endKey);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(109, index);

        headSet = descendingKeySet.headSet(endKey, false);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(109, index);

        headSet = descendingKeySet.headSet(endKey, true);
        iterator = headSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(108, index);

        endKey = new Integer(110).toString();
        try {
            descendingKeySet.headSet(endKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.headSet(endKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        key = new Integer(2).toString();
        keySet = tm.headMap(key, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        iterator.next();
        endKey = (String) iterator.next();

        headSet = descendingKeySet.headSet(endKey);
        assertEquals(1, headSet.size());

        headSet = descendingKeySet.headSet(endKey, false);
        assertEquals(1, headSet.size());

        headSet = descendingKeySet.headSet(endKey, true);
        assertEquals(2, headSet.size());

        key = new Integer(2).toString();
        keySet = tm.tailMap(key, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        iterator.next();
        endKey = (String) iterator.next();
        headSet = descendingKeySet.headSet(endKey);
        assertEquals(1, headSet.size());
View Full Code Here

        iterator = headSet.iterator();
        assertEquals(999, Integer.parseInt((String) iterator.next()));
    }

    public void test_DescendingSubMapKeySet_tailSet() {
        NavigableSet keySet, descendingKeySet;
        SortedSet tailSet;
        String startKey, key;
        Iterator iterator;
        int index;

        keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        startKey = new Integer(99).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        try {
            descendingKeySet.tailSet(startKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        startKey = new Integer(100).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        tailSet = descendingKeySet.tailSet(startKey, false);
        assertEquals(0, tailSet.size());

        startKey = new Integer(101).toString();
        tailSet = descendingKeySet.tailSet(startKey);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        tailSet = descendingKeySet.tailSet(startKey, true);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        tailSet = descendingKeySet.tailSet(startKey, false);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(101, index);

        for (int i = 102; i < 109; i++) {
            startKey = new Integer(i).toString();

            tailSet = descendingKeySet.tailSet(startKey);
            iterator = tailSet.iterator();
            int j;
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(100, j);

            tailSet = descendingKeySet.tailSet(startKey, true);
            iterator = tailSet.iterator();
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(100, j);

            tailSet = descendingKeySet.tailSet(startKey, false);
            iterator = tailSet.iterator();
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j - 1).toString(), key);
            }
            assertEquals(101, j);
        }

        startKey = new Integer(109).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        tailSet = descendingKeySet.tailSet(startKey, false);
        iterator = tailSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index - 1).toString(), key);
        }
        assertEquals(101, index);

        startKey = new Integer(110).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        startKey = new Integer(99).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        try {
            descendingKeySet.tailSet(startKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        startKey = new Integer(100).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        tailSet = descendingKeySet.tailSet(startKey, false);
        assertEquals(0, tailSet.size());

        startKey = new Integer(101).toString();
        tailSet = descendingKeySet.tailSet(startKey);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        tailSet = descendingKeySet.tailSet(startKey, true);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        tailSet = descendingKeySet.tailSet(startKey, false);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(101, index);

        for (int i = 102; i < 109; i++) {
            startKey = new Integer(i).toString();

            tailSet = descendingKeySet.tailSet(startKey);
            iterator = tailSet.iterator();
            int j;
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(100, j);

            tailSet = descendingKeySet.tailSet(startKey, true);
            iterator = tailSet.iterator();
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(100, j);

            tailSet = descendingKeySet.tailSet(startKey, false);
            iterator = tailSet.iterator();
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j - 1).toString(), key);
            }
            assertEquals(101, j);
        }

        startKey = new Integer(109).toString();
        tailSet = descendingKeySet.tailSet(startKey);
        iterator = tailSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        tailSet = descendingKeySet.tailSet(startKey, true);
        iterator = tailSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(100, index);

        tailSet = descendingKeySet.tailSet(startKey, false);
        iterator = tailSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index - 1).toString(), key);
        }
        assertEquals(101, index);

        startKey = new Integer(110).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        startKey = new Integer(99).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        startKey = new Integer(100).toString();
        tailSet = descendingKeySet.tailSet(startKey);
        assertEquals(1, tailSet.size());
        iterator = tailSet.iterator();
        assertEquals(startKey, iterator.next());

        tailSet = descendingKeySet.tailSet(startKey, true);
        assertEquals(1, tailSet.size());
        iterator = tailSet.iterator();
        assertEquals(startKey, iterator.next());

        tailSet = descendingKeySet.tailSet(startKey, false);
        assertEquals(0, tailSet.size());

        startKey = new Integer(101).toString();
        tailSet = descendingKeySet.tailSet(startKey);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(99, index);

        tailSet = descendingKeySet.tailSet(startKey, true);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(99, index);

        tailSet = descendingKeySet.tailSet(startKey, false);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index - 1).toString(), key);
        }
        assertEquals(100, index);

        for (int i = 102; i < 109; i++) {
            startKey = new Integer(i).toString();

            tailSet = descendingKeySet.tailSet(startKey);
            iterator = tailSet.iterator();
            int j;
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(99, j);

            tailSet = descendingKeySet.tailSet(startKey, true);
            iterator = tailSet.iterator();
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(99, j);

            tailSet = descendingKeySet.tailSet(startKey, false);
            iterator = tailSet.iterator();
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j - 1).toString(), key);
            }
            assertEquals(100, j);
        }

        startKey = new Integer(109).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        tailSet = descendingKeySet.tailSet(startKey, false);
        iterator = tailSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index - 1).toString(), key);
        }
        assertEquals(100, index);

        startKey = new Integer(110).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        startKey = new Integer(99).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        startKey = new Integer(100).toString();
        tailSet = descendingKeySet.tailSet(startKey);
        assertEquals(1, tailSet.size());
        iterator = tailSet.iterator();
        assertEquals(startKey, iterator.next());

        tailSet = descendingKeySet.tailSet(startKey, true);
        assertEquals(1, tailSet.size());
        iterator = tailSet.iterator();
        assertEquals(startKey, iterator.next());

        tailSet = descendingKeySet.tailSet(startKey, false);
        assertEquals(0, tailSet.size());

        startKey = new Integer(101).toString();
        tailSet = descendingKeySet.tailSet(startKey);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(99, index);

        tailSet = descendingKeySet.tailSet(startKey, true);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(99, index);

        tailSet = descendingKeySet.tailSet(startKey, false);
        iterator = tailSet.iterator();
        for (index = 101; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index - 1).toString(), key);
        }
        assertEquals(100, index);

        for (int i = 102; i < 109; i++) {
            startKey = new Integer(i).toString();

            tailSet = descendingKeySet.tailSet(startKey);
            iterator = tailSet.iterator();
            int j;
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(99, j);

            tailSet = descendingKeySet.tailSet(startKey, true);
            iterator = tailSet.iterator();
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j).toString(), key);
            }
            assertEquals(99, j);

            tailSet = descendingKeySet.tailSet(startKey, false);
            iterator = tailSet.iterator();
            for (j = i; iterator.hasNext(); j--) {
                key = (String) iterator.next();
                assertEquals(new Integer(j - 1).toString(), key);
            }
            assertEquals(100, j);
        }

        startKey = new Integer(109).toString();
        tailSet = descendingKeySet.tailSet(startKey);
        iterator = tailSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(99, index);

        tailSet = descendingKeySet.tailSet(startKey, true);
        iterator = tailSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index).toString(), key);
        }
        assertEquals(99, index);

        tailSet = descendingKeySet.tailSet(startKey, false);
        iterator = tailSet.iterator();
        for (index = 109; iterator.hasNext(); index--) {
            key = (String) iterator.next();
            assertEquals(new Integer(index - 1).toString(), key);
        }
        assertEquals(100, index);

        startKey = new Integer(110).toString();
        try {
            descendingKeySet.tailSet(startKey);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, true);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
        try {
            descendingKeySet.tailSet(startKey, false);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        key = new Integer(2).toString();
        keySet = tm.headMap(key, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        iterator.next();
        startKey = (String) iterator.next();

        tailSet = descendingKeySet.tailSet(startKey);
View Full Code Here

        tailIterator = tailSet.iterator();
        assertEquals(new Integer(198).toString(), tailIterator.next());
    }

    public void test_DescendingSubMapKeySet_subSet() {
        NavigableSet keySet, descendingKeySet;
        SortedSet subSet;
        String startKey, endKey, key;
        Iterator startIterator, endIterator, subSetIterator;

        keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        startIterator = descendingKeySet.iterator();
        while (startIterator.hasNext()) {
            startKey = (String) startIterator.next();
            endIterator = descendingKeySet.iterator();
            while (endIterator.hasNext()) {
                endKey = (String) endIterator.next();
                int startIndex = Integer.valueOf(startKey);
                int endIndex = Integer.valueOf(endKey);
                if (startIndex < endIndex) {
                    try {
                        descendingKeySet.subSet(startKey, endKey);
                        fail("should throw IllegalArgumentException");
                    } catch (IllegalArgumentException e) {
                        // Expected
                    }

                    try {
                        descendingKeySet.subSet(startKey, false, endKey, false);
                        fail("shoudl throw IllegalArgumentException");
                    } catch (IllegalArgumentException e) {
                        // Expected
                    }

                    try {
                        descendingKeySet.subSet(startKey, false, endKey, true);
                        fail("shoudl throw IllegalArgumentException");
                    } catch (IllegalArgumentException e) {
                        // Expected
                    }

                    try {
                        descendingKeySet.subSet(startKey, true, endKey, false);
                        fail("shoudl throw IllegalArgumentException");
                    } catch (IllegalArgumentException e) {
                        // Expected
                    }

                    try {
                        descendingKeySet.subSet(startKey, true, endKey, true);
                        fail("shoudl throw IllegalArgumentException");
                    } catch (IllegalArgumentException e) {
                        // Expected
                    }
                } else {
                    subSet = descendingKeySet.subSet(startKey, endKey);
                    subSetIterator = subSet.iterator();
                    for (int index = startIndex; subSetIterator.hasNext(); index--) {
                        assertEquals(new Integer(index).toString(),
                                subSetIterator.next());
                    }

                    subSet = descendingKeySet.subSet(startKey, false, endKey,
                            false);
                    subSetIterator = subSet.iterator();
                    for (int index = startIndex - 1; subSetIterator.hasNext(); index--) {
                        assertEquals(new Integer(index).toString(),
                                subSetIterator.next());
                    }

                    subSet = descendingKeySet.subSet(startKey, false, endKey,
                            true);
                    subSetIterator = subSet.iterator();
                    for (int index = startIndex - 1; subSetIterator.hasNext(); index--) {
                        assertEquals(new Integer(index).toString(),
                                subSetIterator.next());
                    }

                    subSet = descendingKeySet.subSet(startKey, true, endKey,
                            false);
                    subSetIterator = subSet.iterator();
                    for (int index = startIndex; subSetIterator.hasNext(); index--) {
                        assertEquals(new Integer(index).toString(),
                                subSetIterator.next());
                    }

                    subSet = descendingKeySet.subSet(startKey, true, endKey,
                            true);
                    subSetIterator = subSet.iterator();
                    for (int index = startIndex; subSetIterator.hasNext(); index--) {
                        assertEquals(new Integer(index).toString(),
                                subSetIterator.next());
                    }
                }
            }
        }

        endKey = new Integer(2).toString();
        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();

        startKey = (String) iterator.next();
        iterator.next();
        endKey = (String) iterator.next();

        subSet = descendingKeySet.subSet(startKey, endKey);
        assertEquals(2, subSet.size());
        subSetIterator = subSet.iterator();
        assertEquals(startKey, subSetIterator.next());
        subSetIterator.next();
        try {
            subSetIterator.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected
        }

        subSet = descendingKeySet.subSet(startKey, false, endKey, false);
        assertEquals(1, subSet.size());
        subSetIterator = subSet.iterator();
        subSetIterator.next();
        try {
            subSetIterator.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected
        }

        subSet = descendingKeySet.subSet(startKey, false, endKey, true);
        assertEquals(2, subSet.size());
        subSetIterator = subSet.iterator();
        subSetIterator.next();
        assertEquals(endKey, subSetIterator.next());
        try {
            subSetIterator.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected
        }

        subSet = descendingKeySet.subSet(startKey, true, endKey, false);
        assertEquals(2, subSet.size());
        subSetIterator = subSet.iterator();
        assertEquals(startKey, subSetIterator.next());
        subSetIterator.next();
        try {
            subSetIterator.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected
        }

        subSet = descendingKeySet.subSet(startKey, true, endKey, true);
        assertEquals(3, subSet.size());
        subSetIterator = subSet.iterator();
        assertEquals(startKey, subSetIterator.next());
        subSetIterator.next();
        assertEquals(endKey, subSetIterator.next());
        try {
            subSetIterator.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected
        }

        // With Comparator
        keySet = ((NavigableMap) subMap_startExcluded_endExcluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        startIterator = descendingKeySet.iterator();
        while (startIterator.hasNext()) {
            startKey = (String) startIterator.next();
            endIterator = descendingKeySet.iterator();
            while (endIterator.hasNext()) {
View Full Code Here

            }
        }
    }

    public void test_DescendingSubMapKeySet_descendingSet() {
        NavigableSet keySet, descendingSet, descendingDescendingSet;
        int value;
        Iterator iterator;

        keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
        descendingSet = keySet.descendingSet();
        descendingDescendingSet = descendingSet.descendingSet();
        iterator = descendingDescendingSet.iterator();
        assertTrue(iterator.hasNext());
        for (value = 101; iterator.hasNext(); value++) {
            assertEquals(new Integer(value).toString(), iterator.next());
        }
        assertEquals(109, value);
        try {
            iterator.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected
        }

        keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
        descendingSet = keySet.descendingSet();
        descendingDescendingSet = descendingSet.descendingSet();
        iterator = descendingDescendingSet.iterator();
        assertTrue(iterator.hasNext());
        for (value = 101; iterator.hasNext(); value++) {
            assertEquals(new Integer(value).toString(), iterator.next());
        }
        assertEquals(110, value);
        try {
            iterator.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected
        }

        keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
        descendingSet = keySet.descendingSet();
        descendingDescendingSet = descendingSet.descendingSet();
        iterator = descendingDescendingSet.iterator();
        assertTrue(iterator.hasNext());
        for (value = 100; iterator.hasNext(); value++) {
            assertEquals(new Integer(value).toString(), iterator.next());
        }
        assertEquals(109, value);
        try {
            iterator.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected
        }

        keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
        descendingSet = keySet.descendingSet();
        descendingDescendingSet = descendingSet.descendingSet();
        iterator = descendingDescendingSet.iterator();
        assertTrue(iterator.hasNext());
        for (value = 100; iterator.hasNext(); value++) {
            assertEquals(new Integer(value).toString(), iterator.next());
        }
        assertEquals(110, value);
        try {
            iterator.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected
        }

        String endKey = new Integer(2).toString();
        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingSet = keySet.descendingSet();
        descendingDescendingSet = descendingSet.descendingSet();
        assertEquals(keySet, descendingDescendingSet);

        String startKey = new Integer(2).toString();
        keySet = tm.tailMap(startKey, true).navigableKeySet();
        descendingSet = keySet.descendingSet();
        descendingDescendingSet = descendingSet.descendingSet();
        assertEquals(keySet, descendingDescendingSet);
    }
View Full Code Here

TOP

Related Classes of java.util.NavigableSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.