Package java.util

Examples of java.util.NavigableSet


    public void test_DescendingSubMapEntrySet_pollLast_startIncluded_endExclued() {
        Set entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        Entry entry;
        if (entrySet instanceof NavigableSet) {
            NavigableSet descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            assertEquals(9, descendingSubMapEntrySet.size());
            for (int i = 108; i > 99; i--) {
                entry = (Entry) descendingSubMapEntrySet.pollLast();
                assertEquals(i, entry.getValue());
            }
            assertNull(descendingSubMapEntrySet.pollFirst());
        }
    }
View Full Code Here


    public void test_DescendingSubMapEntrySet_pollLast_startIncluded_endInclued() {
        Set entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        Entry entry;
        if (entrySet instanceof NavigableSet) {
            NavigableSet descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            assertEquals(10, descendingSubMapEntrySet.size());
            for (int i = 109; i > 99; i--) {
                entry = (Entry) descendingSubMapEntrySet.pollLast();
                assertEquals(i, entry.getValue());
            }
            assertNull(descendingSubMapEntrySet.pollFirst());
        }
    }
View Full Code Here

    }

    public void test_DescendingSubMapEntrySet_pollLast() {
        String key = new Integer(2).toString();
        Set entrySet = tm.headMap(key, true).entrySet();// [0...2]
        NavigableSet descendingEntrySet;
        Entry entry;

        if (entrySet instanceof NavigableSet) {
            // [2...0]
            descendingEntrySet = ((NavigableSet) entrySet).descendingSet();
            entry = (Entry) descendingEntrySet.pollLast();
            assertEquals(2, entry.getValue());
        }

        entrySet = tm.tailMap(key, true).entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingEntrySet = ((NavigableSet) entrySet).descendingSet();
            entry = (Entry) descendingEntrySet.pollLast();
            assertEquals(999, entry.getValue());
        }
    }
View Full Code Here

        }
    }

    public void test_DescendingSubMapEntrySet_descendingIterator() {
        Set entrySet;
        NavigableSet descendingSet;
        Iterator iterator;

        entrySet = navigableMap_startExcluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            iterator = descendingSet.iterator();
            for (int value = 108; value > 100; value--) {
                assertTrue(iterator.hasNext());
                assertEquals(value, ((Entry) iterator.next()).getValue());
            }
            assertFalse(iterator.hasNext());
            try {
                iterator.next();
                fail("should throw NoSuchElementException");
            } catch (NoSuchElementException e) {
                // Expected
            }
        }

        entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            iterator = descendingSet.iterator();
            for (int value = 109; value > 100; value--) {
                assertTrue(iterator.hasNext());
                assertEquals(value, ((Entry) iterator.next()).getValue());
            }
            assertFalse(iterator.hasNext());
            try {
                iterator.next();
                fail("should throw NoSuchElementException");
            } catch (NoSuchElementException e) {
                // Expected
            }
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            iterator = descendingSet.iterator();
            for (int value = 108; value > 99; value--) {
                assertTrue(iterator.hasNext());
                assertEquals(value, ((Entry) iterator.next()).getValue());
            }
            assertFalse(iterator.hasNext());
            try {
                iterator.next();
                fail("should throw NoSuchElementException");
            } catch (NoSuchElementException e) {
                // Expected
            }
        }

        entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            iterator = descendingSet.iterator();
            for (int value = 109; value > 99; value--) {
                assertTrue(iterator.hasNext());
                assertEquals(value, ((Entry) iterator.next()).getValue());
            }
            assertFalse(iterator.hasNext());
            try {
                iterator.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]
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            iterator = descendingSet.descendingIterator();
            assertEquals(0, ((Entry) iterator.next()).getValue());// 0...2
        }
    }
View Full Code Here

        }
    }

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

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

                headSet = descendingSubMapEntrySet.headSet(entry, true);
                headSetIterator = headSet.iterator();
                for (value = 108; headSetIterator.hasNext(); value--) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                try {
                    headSetIterator.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();
                headSet = descendingSubMapEntrySet.headSet(entry);
                headSetIterator = headSet.iterator();
                for (value = 109; headSetIterator.hasNext(); value--) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

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

                headSet = descendingSubMapEntrySet.headSet(entry, true);
                headSetIterator = headSet.iterator();
                for (value = 109; headSetIterator.hasNext(); value--) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                try {
                    headSetIterator.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();
                headSet = descendingSubMapEntrySet.headSet(entry);
                headSetIterator = headSet.iterator();
                for (value = 108; headSetIterator.hasNext(); value--) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

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

                headSet = descendingSubMapEntrySet.headSet(entry, true);
                headSetIterator = headSet.iterator();
                for (value = 108; headSetIterator.hasNext(); value--) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                try {
                    headSetIterator.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();
                headSet = descendingSubMapEntrySet.headSet(entry);
                headSetIterator = headSet.iterator();
                for (value = 109; headSetIterator.hasNext(); value--) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                try {
                    headSetIterator.next();
                    fail("should throw NoSuchElementException");
                } catch (NoSuchElementException e) {
                    // Expected
                }

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

                headSet = descendingSubMapEntrySet.headSet(entry, true);
                headSetIterator = headSet.iterator();
                for (value = 109; headSetIterator.hasNext(); value--) {
                    assertEquals(value, ((Entry) headSetIterator.next())
                            .getValue());
                }
                try {
                    headSetIterator.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
            iterator.next();// 199
            entry = (Entry) iterator.next();// 198
            headSet = descendingSubMapEntrySet.headSet(entry);
            assertEquals(2, headSet.size());// 2 199
            headSetIterator = headSet.iterator();
            assertEquals(2, ((Entry) headSetIterator.next()).getValue());
            assertEquals(199, ((Entry) headSetIterator.next()).getValue());

            headSet = descendingSubMapEntrySet.headSet(entry, true);
            assertEquals(3, headSet.size());// 2 199
            headSetIterator = headSet.iterator();
            assertEquals(2, ((Entry) headSetIterator.next()).getValue());
            assertEquals(199, ((Entry) headSetIterator.next()).getValue());
            assertEquals(198, ((Entry) headSetIterator.next()).getValue());
View Full Code Here

        descendingKeySet = keySet.descendingSet();
        assertNotNull(descendingKeySet.comparator());
    }

    public void test_AscendingSubMapKeySet_first() {
        NavigableSet keySet;
        String firstKey1 = new Integer(100).toString();
        String firstKey2 = new Integer(101).toString();

        keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
        assertEquals(firstKey2, keySet.first());

        keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
        assertEquals(firstKey2, keySet.first());

        keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
        assertEquals(firstKey1, keySet.first());

        keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
        assertEquals(firstKey1, keySet.first());
    }
View Full Code Here

        keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
        assertEquals(firstKey1, keySet.first());
    }

    public void test_DescendingSubMapKeySet_pollFirst_startExcluded_endExcluded() {
        NavigableSet keySet = navigableMap_startExcluded_endExcluded
                .navigableKeySet();
        NavigableSet descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();
        assertEquals(8, keySet.size());
        for (int value = 101; value < 109; value++) {
            assertEquals(new Integer(value).toString(), keySet.pollFirst());
        }
        assertEquals(0, keySet.size());
View Full Code Here

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

    public void test_DescendingSubMapKeySet_pollFirst_startExcluded_endIncluded() {
        NavigableSet keySet = navigableMap_startExcluded_endIncluded
                .navigableKeySet();
        NavigableSet descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();
        assertEquals(9, keySet.size());
        for (int value = 101; value < 110; value++) {
            assertEquals(new Integer(value).toString(), keySet.pollFirst());
        }
        assertEquals(0, keySet.size());
View Full Code Here

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

    public void test_DescendingSubMapKeySet_pollFirst_startIncluded_endExcluded() {
        NavigableSet keySet = navigableMap_startIncluded_endExcluded
                .navigableKeySet();
        NavigableSet descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();
        assertEquals(9, keySet.size());
        for (int value = 100; value < 109; value++) {
            assertEquals(new Integer(value).toString(), keySet.pollFirst());
        }
        assertEquals(0, keySet.size());
View Full Code Here

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

    public void test_DescendingSubMapKeySet_pollFirst_startIncluded_endIncluded() {
        NavigableSet keySet = navigableMap_startIncluded_endIncluded
                .navigableKeySet();
        NavigableSet descendingKeySet = keySet.descendingSet();
        Iterator iterator = descendingKeySet.iterator();
        assertEquals(10, keySet.size());
        for (int value = 100; value < 110; value++) {
            assertEquals(new Integer(value).toString(), keySet.pollFirst());
        }
        assertEquals(0, keySet.size());
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.