Package java.util

Examples of java.util.NavigableSet


        }
    }

    public void test_DescendingSubMapEntrySet_comparator() {
        Set entrySet;
        NavigableSet descendingSet;
        Comparator comparator;
        Entry[] entryArray;
        Integer value1, value2;

        entrySet = navigableMap_startExcluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            assertNull(((NavigableSet) entrySet).comparator());
            comparator = descendingSet.comparator();
            assertNotNull(comparator);

            entryArray = (Entry[]) descendingSet
                    .toArray(new Entry[descendingSet.size()]);
            for (int i = 1; i < entryArray.length; i++) {
                value1 = (Integer) entryArray[i - 1].getValue();
                value2 = (Integer) entryArray[i].getValue();
                assertTrue(value1 > value2);
                assertTrue(comparator.compare(value1, value2) < 0);
            }
        }

        entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            assertNull(((NavigableSet) entrySet).comparator());
            comparator = descendingSet.comparator();
            assertNotNull(comparator);

            entryArray = (Entry[]) descendingSet
                    .toArray(new Entry[descendingSet.size()]);
            for (int i = 1; i < entryArray.length; i++) {
                value1 = (Integer) entryArray[i - 1].getValue();
                value2 = (Integer) entryArray[i].getValue();
                assertTrue(value1 > value2);
                assertTrue(comparator.compare(value1, value2) < 0);
            }
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            assertNull(((NavigableSet) entrySet).comparator());
            comparator = descendingSet.comparator();
            assertNotNull(comparator);

            entryArray = (Entry[]) descendingSet
                    .toArray(new Entry[descendingSet.size()]);
            for (int i = 1; i < entryArray.length; i++) {
                value1 = (Integer) entryArray[i - 1].getValue();
                value2 = (Integer) entryArray[i].getValue();
                assertTrue(value1 > value2);
                assertTrue(comparator.compare(value1, value2) < 0);
            }
        }

        entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            assertNull(((NavigableSet) entrySet).comparator());
            comparator = descendingSet.comparator();
            assertNotNull(comparator);

            entryArray = (Entry[]) descendingSet
                    .toArray(new Entry[descendingSet.size()]);
            for (int i = 1; i < entryArray.length; i++) {
                value1 = (Integer) entryArray[i - 1].getValue();
                value2 = (Integer) entryArray[i].getValue();
                assertTrue(value1 > value2);
                assertTrue(comparator.compare(value1, value2) < 0);
            }
        }

        String endKey = new Integer(2).toString();
        entrySet = tm.headMap(endKey, true).entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            assertNotNull(descendingSet.comparator());
        }
    }
View Full Code Here


        }
    }

    public void test_DescendingSubMapEntrySet_descendingSet() {
        Set entrySet;
        NavigableSet ascendingSubMapEntrySet, descendingSet, descendingDescedingSet;
        Entry[] ascendingEntryArray, descendingDescendingArray;

        entrySet = navigableMap_startExcluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            descendingDescedingSet = descendingSet.descendingSet();
            ascendingEntryArray = (Entry[]) ascendingSubMapEntrySet
                    .toArray(new Entry[ascendingSubMapEntrySet.size()]);

            descendingDescendingArray = (Entry[]) descendingDescedingSet
                    .toArray(new Entry[descendingDescedingSet.size()]);

            assertEquals(ascendingEntryArray.length,
                    descendingDescendingArray.length);
            for (int i = 0; i < ascendingEntryArray.length; i++) {
                assertEquals(ascendingEntryArray[i],
                        descendingDescendingArray[i]);
            }
        }

        entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            descendingDescedingSet = descendingSet.descendingSet();
            ascendingEntryArray = (Entry[]) ascendingSubMapEntrySet
                    .toArray(new Entry[ascendingSubMapEntrySet.size()]);

            descendingDescendingArray = (Entry[]) descendingDescedingSet
                    .toArray(new Entry[descendingDescedingSet.size()]);

            assertEquals(ascendingEntryArray.length,
                    descendingDescendingArray.length);
            for (int i = 0; i < ascendingEntryArray.length; i++) {
                assertEquals(ascendingEntryArray[i],
                        descendingDescendingArray[i]);
            }
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            descendingDescedingSet = descendingSet.descendingSet();
            ascendingEntryArray = (Entry[]) ascendingSubMapEntrySet
                    .toArray(new Entry[ascendingSubMapEntrySet.size()]);

            descendingDescendingArray = (Entry[]) descendingDescedingSet
                    .toArray(new Entry[descendingDescedingSet.size()]);

            assertEquals(ascendingEntryArray.length,
                    descendingDescendingArray.length);
            for (int i = 0; i < ascendingEntryArray.length; i++) {
                assertEquals(ascendingEntryArray[i],
                        descendingDescendingArray[i]);
            }
        }

        entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            descendingDescedingSet = descendingSet.descendingSet();
            ascendingEntryArray = (Entry[]) ascendingSubMapEntrySet
                    .toArray(new Entry[ascendingSubMapEntrySet.size()]);

            descendingDescendingArray = (Entry[]) descendingDescedingSet
                    .toArray(new Entry[descendingDescedingSet.size()]);

            assertEquals(ascendingEntryArray.length,
View Full Code Here

    }

    public void test_DescendingSubMapEntrySet_first() {
        Set entrySet;
        NavigableSet ascendingSubMapEntrySet, descendingSet;
        Entry entry;

        entrySet = navigableMap_startExcluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            entry = (Entry) descendingSet.first();
            assertEquals(101, entry.getValue());
        }

        entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            entry = (Entry) descendingSet.first();
            assertEquals(101, entry.getValue());
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            entry = (Entry) descendingSet.first();
            assertEquals(100, entry.getValue());
        }

        entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            entry = (Entry) descendingSet.first();
            assertEquals(100, entry.getValue());
        }
    }
View Full Code Here

            assertEquals(iterator.next(), descendingIterator.next());
        }
    }

    public void test_DescendingSubMapKeySet_lower() {
        NavigableSet keySet, descendingKeySet;
        Iterator iterator;
        String key, lowerKey;
        int value, lowerValue;

        keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            lowerKey = (String) descendingKeySet.lower(key);
            if (value < 108) {
                lowerValue = Integer.valueOf(lowerKey);
                assertEquals(value + 1, lowerValue);
            } else {
                assertNull(lowerKey);
            }
        }

        key = new Integer(0).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertEquals(101, Integer.parseInt(lowerKey));

        key = new Integer(2).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertNull(lowerKey);

        keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            lowerKey = (String) descendingKeySet.lower(key);
            if (value < 109) {
                lowerValue = Integer.valueOf(lowerKey);
                assertEquals(value + 1, lowerValue);
            } else {
                assertNull(lowerKey);
            }
        }

        key = new Integer(0).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertEquals(101, Integer.parseInt(lowerKey));

        key = new Integer(2).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertNull(lowerKey);

        keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            lowerKey = (String) descendingKeySet.lower(key);
            if (value < 108) {
                lowerValue = Integer.valueOf(lowerKey);
                assertEquals(value + 1, lowerValue);
            } else {
                assertNull(lowerKey);
            }
        }

        key = new Integer(0).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertEquals(100, Integer.parseInt(lowerKey));

        key = new Integer(2).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertNull(lowerKey);

        keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            lowerKey = (String) descendingKeySet.lower(key);
            if (value < 109) {
                lowerValue = Integer.valueOf(lowerKey);
                assertEquals(value + 1, lowerValue);
            } else {
                assertNull(lowerKey);
            }
        }

        key = new Integer(0).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertEquals(100, Integer.parseInt(lowerKey));

        key = new Integer(2).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertNull(lowerKey);

        key = new Integer(2).toString();
        keySet = tm.headMap(key, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        iterator.next();
        iterator.next();
        key = (String) iterator.next();
        lowerKey = (String) descendingKeySet.lower(key);
        assertEquals(new Integer(199).toString(), lowerKey);
        try {
            descendingKeySet.lower(null);
            fail("should throw NPE");
        } catch (NullPointerException e) {
            // Expected
        }

        key = new Integer(0).toString();
        String endKey = key;

        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.lower(endKey));

        key = new Integer(0).toString();
        keySet = tm.headMap(endKey, false).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.lower(endKey));

        endKey = new Integer(999).toString();
        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.lower(endKey));
        assertEquals(new Integer(1).toString(), descendingKeySet.lower(key));

        endKey = new Integer(999).toString();
        keySet = tm.headMap(endKey, false).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.lower(endKey));
        assertEquals(new Integer(1).toString(), descendingKeySet.lower(key));

        // With Comparator
        keySet = ((NavigableMap) subMap_startExcluded_endExcluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            lowerKey = (String) descendingKeySet.lower(key);
            if (value < 108) {
                lowerValue = Integer.valueOf(lowerKey);
                assertEquals(value + 1, lowerValue);
            } else {
                assertNull(lowerKey);
            }
        }

        key = new Integer(0).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertEquals(101, Integer.parseInt(lowerKey));

        key = new Integer(2).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertNull(lowerKey);

        keySet = ((NavigableMap) subMap_startExcluded_endIncluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            lowerKey = (String) descendingKeySet.lower(key);
            if (value < 109) {
                lowerValue = Integer.valueOf(lowerKey);
                assertEquals(value + 1, lowerValue);
            } else {
                assertNull(lowerKey);
            }
        }

        key = new Integer(0).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertEquals(101, Integer.parseInt(lowerKey));

        key = new Integer(2).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertNull(lowerKey);

        keySet = ((NavigableMap) subMap_startIncluded_endExcluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            lowerKey = (String) descendingKeySet.lower(key);
            if (value < 108) {
                lowerValue = Integer.valueOf(lowerKey);
                assertEquals(value + 1, lowerValue);
            } else {
                assertNull(lowerKey);
            }
        }

        key = new Integer(0).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertEquals(100, Integer.parseInt(lowerKey));

        key = new Integer(2).toString();
        lowerKey = (String) descendingKeySet.lower(key);
        assertNull(lowerKey);

        keySet = ((NavigableMap) subMap_startIncluded_endIncluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            lowerKey = (String) descendingKeySet.lower(key);
View Full Code Here

            }
        }
    }

    public void test_DescendingSubMapKeySet_higher() {
        NavigableSet keySet, descendingKeySet;
        Iterator iterator;
        String key, higherKey;
        int value, higherValue;

        keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            higherKey = (String) descendingKeySet.higher(key);
            if (value > 101) {
                higherValue = Integer.valueOf(higherKey);
                assertEquals(value - 1, higherValue);
            } else {
                assertNull(higherKey);
            }
        }

        key = new Integer(99999).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals("108", higherKey);

        key = new Integer(-1).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(100).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(0).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(2).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals(108, Integer.parseInt(higherKey));

        keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            higherKey = (String) descendingKeySet.higher(key);
            if (value > 101) {
                higherValue = Integer.valueOf(higherKey);
                assertEquals(value - 1, higherValue);
            } else {
                assertNull(higherKey);
            }
        }

        key = new Integer(99999).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals("109", higherKey);

        key = new Integer(-1).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(100).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(2).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals(109, Integer.parseInt(higherKey));

        keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            higherKey = (String) descendingKeySet.higher(key);
            if (value > 100) {
                higherValue = Integer.valueOf(higherKey);
                assertEquals(value - 1, higherValue);
            } else {
                assertNull(higherKey);
            }
        }

        key = new Integer(99999).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals("108", higherKey);

        key = new Integer(-1).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(100).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(2).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals(108, Integer.parseInt(higherKey));

        keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            higherKey = (String) descendingKeySet.higher(key);
            if (value > 100) {
                higherValue = Integer.valueOf(higherKey);
                assertEquals(value - 1, higherValue);
            } else {
                assertNull(higherKey);
            }
        }

        key = new Integer(99999).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals("109", higherKey);

        key = new Integer(-1).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(100).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(2).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals(109, Integer.parseInt(higherKey));

        key = new Integer(2).toString();
        keySet = tm.headMap(key, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        key = (String) iterator.next();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals(new Integer(199).toString(), higherKey);
        try {
            descendingKeySet.higher(null);
            fail("should throw NPE");
        } catch (NullPointerException e) {
            // Expected
        }

        key = new Integer(0).toString();
        String endKey = key;

        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.higher(endKey));

        key = new Integer(0).toString();
        keySet = tm.headMap(endKey, false).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.higher(endKey));

        endKey = new Integer(999).toString();
        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertEquals(new Integer(998).toString(), descendingKeySet
                .higher(endKey));
        assertNull(descendingKeySet.higher(key));

        endKey = new Integer(999).toString();
        keySet = tm.headMap(endKey, false).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertEquals(new Integer(998).toString(), descendingKeySet
                .higher(endKey));
        assertNull(descendingKeySet.higher(key));

        // With Comparator
        keySet = ((NavigableMap) subMap_startExcluded_endExcluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            higherKey = (String) descendingKeySet.higher(key);
            if (value > 101) {
                higherValue = Integer.valueOf(higherKey);
                assertEquals(value - 1, higherValue);
            } else {
                assertNull(higherKey);
            }
        }

        key = new Integer(99999).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals("108", higherKey);

        key = new Integer(-1).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(100).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(0).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(2).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals(108, Integer.parseInt(higherKey));

        keySet = ((NavigableMap) subMap_startExcluded_endIncluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            higherKey = (String) descendingKeySet.higher(key);
            if (value > 101) {
                higherValue = Integer.valueOf(higherKey);
                assertEquals(value - 1, higherValue);
            } else {
                assertNull(higherKey);
            }
        }

        key = new Integer(99999).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals("109", higherKey);

        key = new Integer(-1).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(100).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(2).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals(109, Integer.parseInt(higherKey));

        keySet = ((NavigableMap) subMap_startIncluded_endExcluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            higherKey = (String) descendingKeySet.higher(key);
            if (value > 100) {
                higherValue = Integer.valueOf(higherKey);
                assertEquals(value - 1, higherValue);
            } else {
                assertNull(higherKey);
            }
        }

        key = new Integer(99999).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals("108", higherKey);

        key = new Integer(-1).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(100).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(2).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals(108, Integer.parseInt(higherKey));

        keySet = ((NavigableMap) subMap_startIncluded_endIncluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        while (iterator.hasNext()) {
            key = (String) iterator.next();
            value = Integer.valueOf(key);
            higherKey = (String) descendingKeySet.higher(key);
            if (value > 100) {
                higherValue = Integer.valueOf(higherKey);
                assertEquals(value - 1, higherValue);
            } else {
                assertNull(higherKey);
            }
        }

        key = new Integer(99999).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals("109", higherKey);

        key = new Integer(-1).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(100).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertNull(higherKey);

        key = new Integer(2).toString();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals(109, Integer.parseInt(higherKey));

        key = new Integer(2).toString();
        keySet = tm.headMap(key, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        iterator = descendingKeySet.iterator();
        key = (String) iterator.next();
        higherKey = (String) descendingKeySet.higher(key);
        assertEquals(new Integer(199).toString(), higherKey);
        try {
            descendingKeySet.higher(null);
            fail("should throw NPE");
        } catch (NullPointerException e) {
            // Expected
        }

        key = new Integer(0).toString();
        endKey = key;

        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.higher(endKey));

        key = new Integer(0).toString();
        keySet = tm.headMap(endKey, false).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.higher(endKey));

        endKey = new Integer(999).toString();
        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertEquals(new Integer(998).toString(), descendingKeySet
                .higher(endKey));
        assertNull(descendingKeySet.higher(key));

        endKey = new Integer(999).toString();
        keySet = tm.headMap(endKey, false).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertEquals(new Integer(998).toString(), descendingKeySet
                .higher(endKey));
        assertNull(descendingKeySet.higher(key));
    }
View Full Code Here

                .higher(endKey));
        assertNull(descendingKeySet.higher(key));
    }

    public void test_DescendingSubMapKeySet_ceiling() {
        NavigableSet keySet, descendingKeySet;
        String[] keyArray;
        String key, ceilingKey;

        keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 108; i < keyArray.length; i++) {
            ceilingKey = (String) descendingKeySet.ceiling(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), ceilingKey);
        }

        key = new Integer(2).toString();
        ceilingKey = (String) descendingKeySet.ceiling(key);
        assertEquals(108, Integer.parseInt(ceilingKey));

        key = new Integer(0).toString();
        ceilingKey = (String) descendingKeySet.ceiling(key);
        assertNull(ceilingKey);

        key = new Integer(-1).toString();
        ceilingKey = (String) descendingKeySet.ceiling(key);
        assertNull(ceilingKey);

        key = new Integer(99999).toString();
        ceilingKey = (String) descendingKeySet.ceiling(key);
        assertEquals(108, Integer.parseInt(ceilingKey));

        keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 109; i < keyArray.length; i++) {
            ceilingKey = (String) descendingKeySet.ceiling(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), ceilingKey);
        }

        keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 108; i < keyArray.length; i++) {
            ceilingKey = (String) descendingKeySet.ceiling(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), ceilingKey);
        }

        keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 109; i < keyArray.length; i++) {
            ceilingKey = (String) descendingKeySet.ceiling(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), ceilingKey);
        }

        key = new Integer(2).toString();
        keySet = tm.headMap(key, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();
        assertEquals(key, descendingKeySet.ceiling(iterator.next()));
        try {
            descendingKeySet.ceiling(null);
            fail("should throw NPE");
        } catch (NullPointerException e) {
            // Expected
        }

        key = new Integer(0).toString();
        String endKey = key;

        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertEquals(key, descendingKeySet.ceiling(endKey));

        key = new Integer(0).toString();
        keySet = tm.headMap(endKey, false).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.ceiling(endKey));

        endKey = new Integer(999).toString();
        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertEquals(new Integer(999).toString(), descendingKeySet
                .ceiling(endKey));
        assertEquals(key, descendingKeySet.ceiling(key));

        endKey = new Integer(999).toString();
        keySet = tm.headMap(endKey, false).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertEquals(new Integer(998).toString(), descendingKeySet
                .ceiling(endKey));
        assertEquals(key, descendingKeySet.ceiling(key));

        // With Comparator
        keySet = ((NavigableMap) subMap_startExcluded_endExcluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 108; i < keyArray.length; i++) {
            ceilingKey = (String) descendingKeySet.ceiling(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), ceilingKey);
        }

        key = new Integer(2).toString();
        ceilingKey = (String) descendingKeySet.ceiling(key);
        assertEquals(108, Integer.parseInt(ceilingKey));

        key = new Integer(0).toString();
        ceilingKey = (String) descendingKeySet.ceiling(key);
        assertNull(ceilingKey);

        keySet = ((NavigableMap) subMap_startExcluded_endIncluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 109; i < keyArray.length; i++) {
            ceilingKey = (String) descendingKeySet.ceiling(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), ceilingKey);
        }

        keySet = ((NavigableMap) subMap_startIncluded_endExcluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 108; i < keyArray.length; i++) {
            ceilingKey = (String) descendingKeySet.ceiling(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), ceilingKey);
        }

        keySet = ((NavigableMap) subMap_startIncluded_endIncluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 109; i < keyArray.length; i++) {
            ceilingKey = (String) descendingKeySet.ceiling(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), ceilingKey);
View Full Code Here

            assertEquals(new Integer(j - i).toString(), ceilingKey);
        }
    }

    public void test_DescendingSubMapKeySet_floor() {
        NavigableSet keySet, descendingKeySet;
        String[] keyArray;
        String floorKey;

        keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 108; i < keyArray.length; i++) {
            floorKey = (String) descendingKeySet.floor(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), floorKey);
        }

        String key = new Integer(0).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertEquals(101, Integer.parseInt(floorKey));

        key = new Integer(2).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertNull(floorKey);

        keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 109; i < keyArray.length; i++) {
            floorKey = (String) descendingKeySet.floor(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), floorKey);
        }

        key = new Integer(0).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertEquals(101, Integer.parseInt(floorKey));

        key = new Integer(2).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertNull(floorKey);

        keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 108; i < keyArray.length; i++) {
            floorKey = (String) descendingKeySet.floor(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), floorKey);
        }

        key = new Integer(0).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertEquals(100, Integer.parseInt(floorKey));

        key = new Integer(2).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertNull(floorKey);

        keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 109; i < keyArray.length; i++) {
            floorKey = (String) descendingKeySet.floor(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), floorKey);
        }

        key = new Integer(0).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertEquals(100, Integer.parseInt(floorKey));

        key = new Integer(2).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertNull(floorKey);

        key = new Integer(2).toString();
        keySet = tm.headMap(key, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();
        assertEquals(key, descendingKeySet.floor(iterator.next()));
        try {
            descendingKeySet.floor(null);
            fail("should throw NPE");
        } catch (NullPointerException e) {
            // Expected
        }

        key = new Integer(0).toString();
        String endKey = key;

        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertEquals(key, descendingKeySet.floor(endKey));

        key = new Integer(0).toString();
        keySet = tm.headMap(endKey, false).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.floor(endKey));

        endKey = new Integer(999).toString();
        keySet = tm.headMap(endKey, true).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertEquals(new Integer(999).toString(), descendingKeySet
                .floor(endKey));
        assertEquals(key, descendingKeySet.floor(key));

        endKey = new Integer(999).toString();
        keySet = tm.headMap(endKey, false).navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        assertNull(descendingKeySet.floor(endKey));
        assertEquals(key, descendingKeySet.floor(key));

        // With Comparator
        keySet = ((NavigableMap) subMap_startExcluded_endExcluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 108; i < keyArray.length; i++) {
            floorKey = (String) descendingKeySet.floor(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), floorKey);
        }

        key = new Integer(0).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertEquals(101, Integer.parseInt(floorKey));

        key = new Integer(2).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertNull(floorKey);

        keySet = ((NavigableMap) subMap_startExcluded_endIncluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 109; i < keyArray.length; i++) {
            floorKey = (String) descendingKeySet.floor(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), floorKey);
        }

        key = new Integer(0).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertEquals(101, Integer.parseInt(floorKey));

        key = new Integer(2).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertNull(floorKey);

        keySet = ((NavigableMap) subMap_startIncluded_endExcluded_comparator)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 108; i < keyArray.length; i++) {
            floorKey = (String) descendingKeySet.floor(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), floorKey);
        }

        key = new Integer(0).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertEquals(100, Integer.parseInt(floorKey));

        key = new Integer(2).toString();
        floorKey = (String) descendingKeySet.floor(key);
        assertNull(floorKey);

        keySet = ((NavigableMap) subMap_startIncluded_endIncluded)
                .navigableKeySet();
        descendingKeySet = keySet.descendingSet();
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 0, j = 109; i < keyArray.length; i++) {
            floorKey = (String) descendingKeySet.floor(keyArray[i]);
            assertEquals(new Integer(j - i).toString(), floorKey);
View Full Code Here

        }
    }

    public void test_DescendingSubMapEntrySet_lower() {
        Set entrySet, subSet;
        NavigableSet descendingSubMapEntrySet;
        Iterator iterator;
        Entry entry, lowerEntry;
        int value;

        entrySet = navigableMap_startExcluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) descendingSubMapEntrySet.lower(entry);
                value = (Integer) entry.getValue();
                if (value < 108) {
                    assertEquals(value + 1, lowerEntry.getValue());
                } else {
                    assertNull(lowerEntry);
                }
            }

            // System.out.println(descendingSubMapEntrySet);
            // System.out.println(tm);
            Object afterEnd = this.subMap_default_afterEnd_109.entrySet()
                    .iterator().next();
            // System.out.println("o:" + afterEnd);
            Object x = descendingSubMapEntrySet.lower(afterEnd);
            // System.out.println("x:" + x);
            assertNull(x);
            Object beforeStart = this.subMap_default_beforeStart_100.entrySet()
                    .iterator().next();
            // System.out.println("before: " + beforeStart);
            Object y = descendingSubMapEntrySet.lower(beforeStart);
            // System.out.println("y: " + y);
            assertNotNull(y);
            assertEquals(101, (((Entry) y).getValue()));
        }

        entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) descendingSubMapEntrySet.lower(entry);
                value = (Integer) entry.getValue();
                if (value < 109) {
                    assertEquals(value + 1, lowerEntry.getValue());
                } else {
                    assertNull(lowerEntry);
                }
            }
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) descendingSubMapEntrySet.lower(entry);
                value = (Integer) entry.getValue();
                if (value < 108) {
                    assertEquals(value + 1, lowerEntry.getValue());
                } else {
                    assertNull(lowerEntry);
                }
            }
        }

        entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) descendingSubMapEntrySet.lower(entry);
                value = (Integer) entry.getValue();
                if (value < 109) {
                    assertEquals(value + 1, lowerEntry.getValue());
                } else {
                    assertNull(lowerEntry);
                }
            }
        }

        String endKey = new Integer(2).toString();
        entrySet = tm.headMap(endKey, true).entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            iterator.next();// 2
            iterator.next();// 199
            entry = (Entry) iterator.next();// 198
            lowerEntry = (Entry) descendingSubMapEntrySet.lower(entry);
            assertEquals(199, lowerEntry.getValue());
        }
    }
View Full Code Here

        }
    }

    public void test_DescendingSubMapEntrySet_higher() {
        Set entrySet, subSet;
        NavigableSet descendingSubMapEntrySet;
        Iterator iterator;
        Entry entry, higherEntry;
        int value;

        entrySet = navigableMap_startExcluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                higherEntry = (Entry) descendingSubMapEntrySet.higher(entry);
                value = (Integer) entry.getValue();
                if (value > 101) {
                    assertEquals(value - 1, higherEntry.getValue());
                } else {
                    assertNull(higherEntry);
                }
            }

            Object afterEnd = this.subMap_default_afterEnd_109.entrySet()
                    .iterator().next();
            Object x = descendingSubMapEntrySet.higher(afterEnd);
            assertNotNull(x);
            assertEquals(108, ((Entry) x).getValue());
            Object beforeStart = this.subMap_default_beforeStart_100.entrySet()
                    .iterator().next();
            Object y = descendingSubMapEntrySet.higher(beforeStart);
            assertNull(y);
        }

        entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                higherEntry = (Entry) descendingSubMapEntrySet.higher(entry);
                value = (Integer) entry.getValue();
                if (value > 101) {
                    assertEquals(value - 1, higherEntry.getValue());
                } else {
                    assertNull(higherEntry);
                }
            }
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                higherEntry = (Entry) descendingSubMapEntrySet.higher(entry);
                value = (Integer) entry.getValue();
                if (value > 100) {
                    assertEquals(value - 1, higherEntry.getValue());
                } else {
                    assertNull(higherEntry);
                }
            }
        }

        entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                higherEntry = (Entry) descendingSubMapEntrySet.higher(entry);
                value = (Integer) entry.getValue();
                if (value > 100) {
                    assertEquals(value - 1, higherEntry.getValue());
                } else {
                    assertNull(higherEntry);
                }
            }
        }

        String endKey = new Integer(2).toString();
        entrySet = tm.headMap(endKey, true).entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            iterator.next();// 2
            iterator.next();// 199
            entry = (Entry) iterator.next();// 198
            higherEntry = (Entry) descendingSubMapEntrySet.higher(entry);
            assertEquals(197, higherEntry.getValue());
        }

        // With Comparator
        entrySet = subMap_startExcluded_endExcluded_comparator.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                higherEntry = (Entry) descendingSubMapEntrySet.higher(entry);
                value = (Integer) entry.getValue();
                if (value > 101) {
                    assertEquals(value - 1, higherEntry.getValue());
                } else {
                    assertNull(higherEntry);
                }
            }

            Object afterEnd = this.subMap_default_afterEnd_109.entrySet()
                    .iterator().next();
            Object x = descendingSubMapEntrySet.higher(afterEnd);
            assertNotNull(x);
            assertEquals(108, ((Entry) x).getValue());
            Object beforeStart = this.subMap_default_beforeStart_100.entrySet()
                    .iterator().next();
            Object y = descendingSubMapEntrySet.higher(beforeStart);
            assertNull(y);
        }
    }
View Full Code Here

        }
    }

    public void test_DescendingSubMapEntrySet_ceiling() {
        Set entrySet;
        NavigableSet ascendingSubMapEntrySet, descendingSet;
        Entry entry;
        Entry[] entryArray;

        entrySet = navigableMap_startExcluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            try {
                descendingSet.ceiling(null);
                fail("should throw NPE");
            } catch (NullPointerException e) {
                // Expected
            }

            entryArray = (Entry[]) descendingSet
                    .toArray(new Entry[descendingSet.size()]);
            for (int i = 0, j = 108; i < entryArray.length; i++) {
                entry = (Entry) descendingSet.ceiling(entryArray[i]);
                assertEquals(j - i, entry.getValue());
            }

            // System.out.println(descendingSet);
            // System.out.println(tm);
            Object afterEnd = this.subMap_default_afterEnd_109.entrySet()
                    .iterator().next();
            // System.out.println("o:" + afterEnd);//110
            Object x = descendingSet.ceiling(afterEnd);
            assertNotNull(x);
            // System.out.println("x:" + x);
            assertEquals(108, ((Entry) x).getValue());
            Object beforeStart = this.subMap_default_beforeStart_100.entrySet()
                    .iterator().next();
            // System.out.println("before: " + beforeStart);//0
            Object y = descendingSet.ceiling(beforeStart);
            assertNull(y);
        }

        entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            try {
                descendingSet.ceiling(null);
                fail("should throw NPE");
            } catch (NullPointerException e) {
                // Expected
            }

            entryArray = (Entry[]) descendingSet
                    .toArray(new Entry[descendingSet.size()]);
            for (int i = 0, j = 109; i < entryArray.length; i++) {
                entry = (Entry) descendingSet.ceiling(entryArray[i]);
                assertEquals(j - i, entry.getValue());
            }
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            try {
                descendingSet.ceiling(null);
                fail("should throw NPE");
            } catch (NullPointerException e) {
                // Expected
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.