Package java.util

Examples of java.util.NavigableSet


        descendingDescendingSet = descendingSet.descendingSet();
        assertEquals(keySet, descendingDescendingSet);
    }

    public void test_DescendingSubMapKeySet_descendingIterator() {
        NavigableSet keySet, descendingSet;
        int value;
        Iterator iterator, descendingIterator;

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

        descendingSet = descendingSet
                .headSet(new Integer(105).toString(), true);
        descendingIterator = descendingSet.descendingIterator();
        for (value = 105; descendingIterator.hasNext(); value++) {
            assertEquals(new Integer(value).toString(), descendingIterator
                    .next());
        }

        descendingSet = keySet.descendingSet();
        descendingSet = descendingSet
                .tailSet(new Integer(105).toString(), true);
        descendingIterator = descendingSet.descendingIterator();
        for (value = 101; descendingIterator.hasNext(); value++) {
            assertEquals(new Integer(value).toString(), descendingIterator
                    .next());
        }

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

        descendingSet = descendingSet
                .headSet(new Integer(105).toString(), true);
        descendingIterator = descendingSet.descendingIterator();
        for (value = 105; descendingIterator.hasNext(); value++) {
            assertEquals(new Integer(value).toString(), descendingIterator
                    .next());
        }

        descendingSet = keySet.descendingSet();
        descendingSet = descendingSet
                .tailSet(new Integer(105).toString(), true);
        descendingIterator = descendingSet.descendingIterator();
        for (value = 101; descendingIterator.hasNext(); value++) {
            assertEquals(new Integer(value).toString(), descendingIterator
                    .next());
        }

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

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

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

        descendingSet = keySet.descendingSet();
        descendingIterator = descendingSet.descendingIterator();

        while (iterator.hasNext()) {
            assertEquals(iterator.next(), descendingIterator.next());
        }

        String startKey = new Integer(2).toString();
        keySet = tm.tailMap(startKey, true).navigableKeySet();
        iterator = keySet.iterator();
        descendingSet = keySet.descendingSet();
        descendingIterator = descendingSet.descendingIterator();

        while (iterator.hasNext()) {
            assertEquals(iterator.next(), descendingIterator.next());
        }
View Full Code Here


        }
    }

    public void test_DescendingSubMapEntrySet_tailSet() {
        Set entrySet, tailSet;
        NavigableSet descendingSubMapEntrySet;
        Iterator iterator, tailSetIterator;
        Entry entry;
        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();
                tailSet = descendingSubMapEntrySet.tailSet(entry);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                tailSet = descendingSubMapEntrySet.tailSet(entry, false);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value - 1, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                tailSet = descendingSubMapEntrySet.tailSet(entry, true);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }
            }
        }

        entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                tailSet = descendingSubMapEntrySet.tailSet(entry);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                tailSet = descendingSubMapEntrySet.tailSet(entry, false);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value - 1, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                tailSet = descendingSubMapEntrySet.tailSet(entry, true);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }
            }
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                tailSet = descendingSubMapEntrySet.tailSet(entry);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                tailSet = descendingSubMapEntrySet.tailSet(entry, false);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value - 1, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                tailSet = descendingSubMapEntrySet.tailSet(entry, true);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }
            }
        }

        entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                tailSet = descendingSubMapEntrySet.tailSet(entry);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                tailSet = descendingSubMapEntrySet.tailSet(entry, false);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value - 1, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                tailSet = descendingSubMapEntrySet.tailSet(entry, true);
                tailSetIterator = tailSet.iterator();
                for (value = (Integer) entry.getValue(); tailSetIterator
                        .hasNext(); value--) {
                    assertEquals(value, ((Entry) tailSetIterator.next())
                            .getValue());
                }
                try {
                    tailSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }
            }
        }

        String endKey = new Integer(2).toString();
        entrySet = tm.headMap(endKey, true).entrySet();// 0...2
        if (entrySet instanceof NavigableSet) {
            // [2...0]
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            iterator = descendingSubMapEntrySet.iterator();
            iterator.next();// 2
            entry = (Entry) iterator.next();// 199
            tailSet = descendingSubMapEntrySet.tailSet(entry);
            tailSetIterator = tailSet.iterator();
            assertEquals(199, ((Entry) tailSetIterator.next()).getValue());

            tailSet = descendingSubMapEntrySet.tailSet(entry, false);
            tailSetIterator = tailSet.iterator();
            assertEquals(198, ((Entry) tailSetIterator.next()).getValue());

            tailSet = descendingSubMapEntrySet.tailSet(entry, true);
            tailSetIterator = tailSet.iterator();
            assertEquals(199, ((Entry) tailSetIterator.next()).getValue());
        }
    }
View Full Code Here

        }
    }

    public void test_DescendingSubMapEntrySet_subSet() {
        Set entrySet, subSet;
        NavigableSet descendingSubMapEntrySet;
        Entry startEntry, endEntry;
        Iterator subSetIterator;

        entrySet = navigableMap_startExcluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            Iterator iteratorStart = descendingSubMapEntrySet.iterator();
            while (iteratorStart.hasNext()) {
                startEntry = (Entry) iteratorStart.next();
                Iterator iteratorEnd = descendingSubMapEntrySet.iterator();
                while (iteratorEnd.hasNext()) {
                    endEntry = (Entry) iteratorEnd.next();
                    int startIndex = (Integer) startEntry.getValue();
                    int endIndex = (Integer) endEntry.getValue();
                    if (startIndex < endIndex) {
                        try {
                            descendingSubMapEntrySet.subSet(startEntry,
                                    endEntry);
                            fail("should throw IllegalArgumentException");
                        } catch (IllegalArgumentException e) {
                            // Expected
                        }

                        try {
                            descendingSubMapEntrySet.subSet(startEntry, false,
                                    endEntry, false);
                            fail("should throw IllegalArgumentException");
                        } catch (IllegalArgumentException e) {
                            // Expected
                        }

                        try {
                            descendingSubMapEntrySet.subSet(startEntry, false,
                                    endEntry, true);
                            fail("should throw IllegalArgumentException");
                        } catch (IllegalArgumentException e) {
                            // Expected
                        }

                        try {
                            descendingSubMapEntrySet.subSet(startEntry, true,
                                    endEntry, false);
                            fail("should throw IllegalArgumentException");
                        } catch (IllegalArgumentException e) {
                            // Expected
                        }

                        try {
                            descendingSubMapEntrySet.subSet(startEntry, true,
                                    endEntry, true);
                            fail("should throw IllegalArgumentException");
                        } catch (IllegalArgumentException e) {
                            // Expected
                        }
                    } else {
                        subSet = descendingSubMapEntrySet.subSet(startEntry,
                                endEntry);
                        subSetIterator = subSet.iterator();
                        for (int index = startIndex; subSetIterator.hasNext(); index--) {
                            assertEquals(index, ((Entry) subSetIterator.next())
                                    .getValue());
                        }

                        subSet = descendingSubMapEntrySet.subSet(startEntry,
                                false, endEntry, false);
                        subSetIterator = subSet.iterator();
                        for (int index = startIndex - 1; subSetIterator
                                .hasNext(); index--) {
                            assertEquals(index, ((Entry) subSetIterator.next())
                                    .getValue());
                        }

                        subSet = descendingSubMapEntrySet.subSet(startEntry,
                                false, endEntry, true);
                        subSetIterator = subSet.iterator();
                        for (int index = startIndex - 1; subSetIterator
                                .hasNext(); index--) {
                            assertEquals(index, ((Entry) subSetIterator.next())
                                    .getValue());
                        }

                        subSet = descendingSubMapEntrySet.subSet(startEntry,
                                true, endEntry, false);
                        subSetIterator = subSet.iterator();
                        for (int index = startIndex; subSetIterator.hasNext(); index--) {
                            assertEquals(index, ((Entry) subSetIterator.next())
                                    .getValue());
                        }

                        subSet = descendingSubMapEntrySet.subSet(startEntry,
                                true, endEntry, true);
                        subSetIterator = subSet.iterator();
                        for (int index = startIndex; subSetIterator.hasNext(); index--) {
                            assertEquals(index, ((Entry) subSetIterator.next())
                                    .getValue());
                        }
                    }
                }
            }
        }

        String endKey = new Integer(2).toString();
        entrySet = tm.headMap(endKey, true).entrySet();
        if (entrySet instanceof NavigableSet) {
            // [2...0]
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            Iterator iterator = descendingSubMapEntrySet.iterator();
            startEntry = (Entry) iterator.next();
            iterator.next();
            endEntry = (Entry) iterator.next();
            subSet = descendingSubMapEntrySet.subSet(startEntry, endEntry);
            assertEquals(2, subSet.size());

            subSet = descendingSubMapEntrySet.subSet(startEntry, false,
                    endEntry, false);
            assertEquals(1, subSet.size());
            subSetIterator = subSet.iterator();
            assertEquals(199, ((Entry) subSetIterator.next()).getValue());

            subSet = descendingSubMapEntrySet.subSet(startEntry, false,
                    endEntry, true);
            assertEquals(2, subSet.size());
            subSetIterator = subSet.iterator();
            assertEquals(199, ((Entry) subSetIterator.next()).getValue());
            assertEquals(198, ((Entry) subSetIterator.next()).getValue());

            subSet = descendingSubMapEntrySet.subSet(startEntry, true,
                    endEntry, false);
            assertEquals(2, subSet.size());
            subSetIterator = subSet.iterator();
            assertEquals(2, ((Entry) subSetIterator.next()).getValue());
            assertEquals(199, ((Entry) subSetIterator.next()).getValue());

            subSet = descendingSubMapEntrySet.subSet(startEntry, true,
                    endEntry, true);
            assertEquals(3, subSet.size());
            subSetIterator = subSet.iterator();
            assertEquals(2, ((Entry) subSetIterator.next()).getValue());
            assertEquals(199, ((Entry) subSetIterator.next()).getValue());
            assertEquals(198, ((Entry) subSetIterator.next()).getValue());
        }

        // With Comnparator
        entrySet = subMap_startExcluded_endExcluded_comparator.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            Iterator iteratorStart = descendingSubMapEntrySet.iterator();
            while (iteratorStart.hasNext()) {
                startEntry = (Entry) iteratorStart.next();
                Iterator iteratorEnd = descendingSubMapEntrySet.iterator();
                while (iteratorEnd.hasNext()) {
                    endEntry = (Entry) iteratorEnd.next();
                    int startIndex = (Integer) startEntry.getValue();
                    int endIndex = (Integer) endEntry.getValue();
                    if (startIndex < endIndex) {
                        try {
                            descendingSubMapEntrySet.subSet(startEntry,
                                    endEntry);
                            fail("should throw IllegalArgumentException");
                        } catch (IllegalArgumentException e) {
                            // Expected
                        }

                        try {
                            descendingSubMapEntrySet.subSet(startEntry, false,
                                    endEntry, false);
                            fail("should throw IllegalArgumentException");
                        } catch (IllegalArgumentException e) {
                            // Expected
                        }

                        try {
                            descendingSubMapEntrySet.subSet(startEntry, false,
                                    endEntry, true);
                            fail("should throw IllegalArgumentException");
                        } catch (IllegalArgumentException e) {
                            // Expected
                        }

                        try {
                            descendingSubMapEntrySet.subSet(startEntry, true,
                                    endEntry, false);
                            fail("should throw IllegalArgumentException");
                        } catch (IllegalArgumentException e) {
                            // Expected
                        }

                        try {
                            descendingSubMapEntrySet.subSet(startEntry, true,
                                    endEntry, true);
                            fail("should throw IllegalArgumentException");
                        } catch (IllegalArgumentException e) {
                            // Expected
                        }
                    } else {
                        subSet = descendingSubMapEntrySet.subSet(startEntry,
                                endEntry);
                        subSetIterator = subSet.iterator();
                        for (int index = startIndex; subSetIterator.hasNext(); index--) {
                            assertEquals(index, ((Entry) subSetIterator.next())
                                    .getValue());
                        }

                        subSet = descendingSubMapEntrySet.subSet(startEntry,
                                false, endEntry, false);
                        subSetIterator = subSet.iterator();
                        for (int index = startIndex - 1; subSetIterator
                                .hasNext(); index--) {
                            assertEquals(index, ((Entry) subSetIterator.next())
                                    .getValue());
                        }

                        subSet = descendingSubMapEntrySet.subSet(startEntry,
                                false, endEntry, true);
                        subSetIterator = subSet.iterator();
                        for (int index = startIndex - 1; subSetIterator
                                .hasNext(); index--) {
                            assertEquals(index, ((Entry) subSetIterator.next())
                                    .getValue());
                        }

                        subSet = descendingSubMapEntrySet.subSet(startEntry,
                                true, endEntry, false);
                        subSetIterator = subSet.iterator();
                        for (int index = startIndex; subSetIterator.hasNext(); index--) {
                            assertEquals(index, ((Entry) subSetIterator.next())
                                    .getValue());
                        }

                        subSet = descendingSubMapEntrySet.subSet(startEntry,
                                true, endEntry, true);
                        subSetIterator = subSet.iterator();
                        for (int index = startIndex; subSetIterator.hasNext(); index--) {
                            assertEquals(index, ((Entry) subSetIterator.next())
                                    .getValue());
View Full Code Here

    public void test_navigableKeySet() throws Exception {
        Integer testint9999 = new Integer(9999);
        Integer testint10000 = new Integer(10000);
        Integer testint100 = new Integer(100);
        Integer testint0 = new Integer(0);
        NavigableSet set = tm.navigableKeySet();
        assertFalse(set.contains(testint9999.toString()));
        tm.put(testint9999.toString(), testint9999);
        assertTrue(set.contains(testint9999.toString()));
        tm.remove(testint9999.toString());
        assertFalse(set.contains(testint9999.toString()));
        try {
            set.add(new Object());
            fail("should throw UnsupportedOperationException");
        } catch (UnsupportedOperationException e) {
            // expected
        }
        try {
            set.add(null);
            fail("should throw UnsupportedOperationException");
        } catch (UnsupportedOperationException e) {
            // expected
        }
        try {
            set.addAll(null);
            fail("should throw UnsupportedOperationException");
        } catch (NullPointerException e) {
            // expected
        }
        Collection collection = new LinkedList();
        set.addAll(collection);
        try {
            collection.add(new Object());
            set.addAll(collection);
            fail("should throw UnsupportedOperationException");
        } catch (UnsupportedOperationException e) {
            // expected
        }
        set.remove(testint100.toString());
        assertFalse(tm.containsKey(testint100.toString()));
        assertTrue(tm.containsKey(testint0.toString()));
        Iterator iter = set.iterator();
        iter.next();
        iter.remove();
        assertFalse(tm.containsKey(testint0.toString()));
        collection.add(new Integer(200).toString());
        set.retainAll(collection);
        assertEquals(1, tm.size());
        set.removeAll(collection);
        assertEquals(0, tm.size());
        tm.put(testint10000.toString(), testint10000);
        assertEquals(1, tm.size());
        set.clear();
        assertEquals(0, tm.size());
    }
View Full Code Here

        }
    }

    public void test_AscendingSubMapEntrySet_ceiling() {
        Set entrySet;
        NavigableSet ascendingSubMapEntrySet;
        Iterator iterator;

        Set entrySet_beyondBound;
        Iterator iterator_beyondBound;
        Entry beyondBoundEntry;

        Entry entry, lowerEntry;
        int value = 0;

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

            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) ascendingSubMapEntrySet.ceiling(entry);
                value = (Integer) entry.getValue();
                assertEquals(value, lowerEntry.getValue());
            }
            assertEquals(108, value);

        }

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

            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) ascendingSubMapEntrySet.ceiling(entry);
                value = (Integer) entry.getValue();
                assertEquals(value, lowerEntry.getValue());
            }
            assertEquals(109, value);
        }

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

            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) ascendingSubMapEntrySet.ceiling(entry);
                value = (Integer) entry.getValue();
                assertEquals(value, lowerEntry.getValue());
            }
            assertEquals(108, value);
        }

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

            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) ascendingSubMapEntrySet.ceiling(entry);
                value = (Integer) entry.getValue();
                assertEquals(value, lowerEntry.getValue());
            }
            assertEquals(109, value);
        }

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

            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) ascendingSubMapEntrySet.ceiling(entry);
                value = (Integer) entry.getValue();
                assertEquals(value, lowerEntry.getValue());
            }
            assertEquals(109, value);
        }

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

            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) ascendingSubMapEntrySet.ceiling(entry);
                value = (Integer) entry.getValue();
                assertEquals(value, lowerEntry.getValue());
            }
            assertEquals(108, value);
        }

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

            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) ascendingSubMapEntrySet.ceiling(entry);
                value = (Integer) entry.getValue();
                assertEquals(value, lowerEntry.getValue());
            }
            assertEquals(109, value);
        }

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

            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                lowerEntry = (Entry) ascendingSubMapEntrySet.ceiling(entry);
                value = (Integer) entry.getValue();
                assertEquals(value, lowerEntry.getValue());
            }
            assertEquals(108, value);
        }
View Full Code Here

        }
    }

    public void test_AscendingSubMapEntrySet_floor() {
        Set entrySet;
        NavigableSet ascendingSubMapEntrySet;
        Iterator iterator;
        Entry entry, floorEntry;
        int value;

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

            iterator = ascendingSubMapEntrySet.iterator();
            for (int i = 101; i < 109; i++) {
                entry = (Entry) iterator.next();
                floorEntry = (Entry) ascendingSubMapEntrySet.floor(entry);
                assertEquals(entry.getValue(), floorEntry.getValue());
            }
            assertFalse(iterator.hasNext());
        }

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

            iterator = ascendingSubMapEntrySet.iterator();
            for (int i = 101; i < 110; i++) {
                entry = (Entry) iterator.next();
                floorEntry = (Entry) ascendingSubMapEntrySet.floor(entry);
                assertEquals(entry.getValue(), floorEntry.getValue());
            }
            assertFalse(iterator.hasNext());
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            try {
                ascendingSubMapEntrySet.floor(null);
                fail("should throw NullPointerException");
            } catch (NullPointerException e) {
                // Expected
            }

            iterator = ascendingSubMapEntrySet.iterator();
            for (int i = 100; i < 109; i++) {
                entry = (Entry) iterator.next();
                floorEntry = (Entry) ascendingSubMapEntrySet.floor(entry);
                assertEquals(entry.getValue(), floorEntry.getValue());
            }
            assertFalse(iterator.hasNext());
        }

        entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            try {
                ascendingSubMapEntrySet.floor(null);
                fail("should throw NullPointerException");
            } catch (NullPointerException e) {
                // Expected
            }

            iterator = ascendingSubMapEntrySet.iterator();
            for (int i = 100; i < 110; i++) {
                entry = (Entry) iterator.next();
                floorEntry = (Entry) ascendingSubMapEntrySet.floor(entry);
                assertEquals(entry.getValue(), floorEntry.getValue());
            }
            assertFalse(iterator.hasNext());
        }

        // With Comparator
        entrySet = subMap_startExcluded_endExcluded_comparator.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            try {
                ascendingSubMapEntrySet.floor(null);
                fail("should throw NullPointerException");
            } catch (NullPointerException e) {
                // Expected
            }

            iterator = ascendingSubMapEntrySet.iterator();
            for (int i = 101; i < 109; i++) {
                entry = (Entry) iterator.next();
                floorEntry = (Entry) ascendingSubMapEntrySet.floor(entry);
                assertEquals(entry.getValue(), floorEntry.getValue());
            }
            assertFalse(iterator.hasNext());
        }

        entrySet = subMap_startExcluded_endIncluded_comparator.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            try {
                ascendingSubMapEntrySet.floor(null);
                fail("should throw NullPointerException");
            } catch (NullPointerException e) {
                // Expected
            }

            iterator = ascendingSubMapEntrySet.iterator();
            for (int i = 101; i < 110; i++) {
                entry = (Entry) iterator.next();
                floorEntry = (Entry) ascendingSubMapEntrySet.floor(entry);
                assertEquals(entry.getValue(), floorEntry.getValue());
            }
            assertFalse(iterator.hasNext());
        }

        entrySet = subMap_startIncluded_endExcluded_comparator.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            try {
                ascendingSubMapEntrySet.floor(null);
                fail("should throw NullPointerException");
            } catch (NullPointerException e) {
                // Expected
            }

            iterator = ascendingSubMapEntrySet.iterator();
            for (int i = 100; i < 109; i++) {
                entry = (Entry) iterator.next();
                floorEntry = (Entry) ascendingSubMapEntrySet.floor(entry);
                assertEquals(entry.getValue(), floorEntry.getValue());
            }
            assertFalse(iterator.hasNext());
        }

        entrySet = subMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            try {
                ascendingSubMapEntrySet.floor(null);
                fail("should throw NullPointerException");
            } catch (NullPointerException e) {
                // Expected
            }

            iterator = ascendingSubMapEntrySet.iterator();
            for (int i = 100; i < 110; i++) {
                entry = (Entry) iterator.next();
                floorEntry = (Entry) ascendingSubMapEntrySet.floor(entry);
                assertEquals(entry.getValue(), floorEntry.getValue());
            }
            assertFalse(iterator.hasNext());
        }
    }
View Full Code Here

    }

    public void test_AscendingSubMapEntrySet_pollLast_startExcluded_endIncluded() {
        Set entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            NavigableSet ascendingSubMapEntrySet = (NavigableSet) entrySet;
            for (int value = 109; value > 100; value--) {
                Entry entry = (Entry) ascendingSubMapEntrySet.pollLast();
                assertEquals(value, entry.getValue());
            }
            assertTrue(ascendingSubMapEntrySet.isEmpty());
            // should return null if the set is empty
            assertNull(ascendingSubMapEntrySet.pollLast());
        }
    }
View Full Code Here

    }

    public void test_AscendingSubMapEntrySet_pollLast_startIncluded_endExcluded() {
        Set entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            NavigableSet ascendingSubMapEntrySet = (NavigableSet) entrySet;
            for (int value = 108; value > 99; value--) {
                Entry entry = (Entry) ascendingSubMapEntrySet.pollLast();
                assertEquals(value, entry.getValue());
            }
            assertTrue(ascendingSubMapEntrySet.isEmpty());
            // should return null if the set is empty
            assertNull(ascendingSubMapEntrySet.pollLast());
        }
    }
View Full Code Here

    }

    public void test_AscendingSubMapEntrySet_pollLast_startIncluded_endIncluded() {
        Set entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            NavigableSet ascendingSubMapEntrySet = (NavigableSet) entrySet;
            for (int value = 109; value > 99; value--) {
                Entry entry = (Entry) ascendingSubMapEntrySet.pollLast();
                assertEquals(value, entry.getValue());
            }
            assertTrue(ascendingSubMapEntrySet.isEmpty());
            // should return null if the set is empty
            assertNull(ascendingSubMapEntrySet.pollLast());
        }
    }
View Full Code Here

        }
    }

    public void test_AscendingSubMapEntrySet_headSet() {
        Set entrySet, headSet;
        NavigableSet ascendingSubMapEntrySet;
        Iterator iterator, headSetIterator;
        Entry entry;
        int value;

        entrySet = navigableMap_startExcluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                headSet = ascendingSubMapEntrySet.headSet(entry);
                headSetIterator = headSet.iterator();
                for (value = 101; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                headSet = ascendingSubMapEntrySet.headSet(entry, false);
                headSetIterator = headSet.iterator();
                for (value = 101; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                headSet = ascendingSubMapEntrySet.headSet(entry, true);
                headSetIterator = headSet.iterator();
                for (value = 101; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value - 1);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }
            }
        }

        entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                headSet = ascendingSubMapEntrySet.headSet(entry);
                headSetIterator = headSet.iterator();
                for (value = 101; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                headSet = ascendingSubMapEntrySet.headSet(entry, false);
                headSetIterator = headSet.iterator();
                for (value = 101; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                headSet = ascendingSubMapEntrySet.headSet(entry, true);
                headSetIterator = headSet.iterator();
                for (value = 101; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value - 1);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }
            }
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                headSet = ascendingSubMapEntrySet.headSet(entry);
                headSetIterator = headSet.iterator();
                for (value = 100; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                headSet = ascendingSubMapEntrySet.headSet(entry, false);
                headSetIterator = headSet.iterator();
                for (value = 100; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                headSet = ascendingSubMapEntrySet.headSet(entry, true);
                headSetIterator = headSet.iterator();
                for (value = 100; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value - 1);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }
            }
        }

        entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            iterator = ascendingSubMapEntrySet.iterator();
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                headSet = ascendingSubMapEntrySet.headSet(entry);
                headSetIterator = headSet.iterator();
                for (value = 100; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                headSet = ascendingSubMapEntrySet.headSet(entry, false);
                headSetIterator = headSet.iterator();
                for (value = 100; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                assertEquals(entry.getValue(), value);
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

                headSet = ascendingSubMapEntrySet.headSet(entry, true);
                headSetIterator = headSet.iterator();
                for (value = 100; headSetIterator.hasNext(); value++) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
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.