Package java.util

Examples of java.util.NavigableSet


    }

    public void test_DescendingSubMapEntrySet_floor() {
        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.floor(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.floor(entryArray[i]);
                assertEquals(j - i, entry.getValue());
            }

            Object afterEnd = this.subMap_default_afterEnd_109.entrySet()
                    .iterator().next();
            Object x = descendingSet.floor(afterEnd);
            assertNull(x);

            Object beforeStart = this.subMap_default_beforeStart_100.entrySet()
                    .iterator().next();
            Object y = descendingSet.floor(beforeStart);
            assertNotNull(y);
            assertEquals(101, (((Entry) y).getValue()));
        }

        entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            try {
                descendingSet.floor(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.floor(entryArray[i]);
                assertEquals(j - i, entry.getValue());
            }
        }

        entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            try {
                descendingSet.floor(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.floor(entryArray[i]);
                assertEquals(j - i, entry.getValue());
            }
        }

        entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();
            try {
                descendingSet.floor(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.floor(entryArray[i]);
                assertEquals(j - i, entry.getValue());
            }
        }

        String endKey = new Integer(2).toString();
        entrySet = tm.headMap(endKey, true).entrySet();
        if (entrySet instanceof NavigableSet) {
            descendingSet = ((NavigableSet) entrySet).descendingSet();

            Iterator iterator = descendingSet.iterator();
            Entry floorEntry;
            while (iterator.hasNext()) {
                entry = (Entry) iterator.next();
                floorEntry = (Entry) descendingSet.floor(entry);
                assertEquals(entry, floorEntry);
            }
        }

        // With Comparator
        entrySet = subMap_startExcluded_endExcluded_comparator.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            try {
                descendingSet.floor(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.floor(entryArray[i]);
                assertEquals(j - i, entry.getValue());
            }
        }

        entrySet = subMap_startExcluded_endIncluded_comparator.entrySet();
        if (entrySet instanceof NavigableSet) {
            ascendingSubMapEntrySet = (NavigableSet) entrySet;
            descendingSet = ascendingSubMapEntrySet.descendingSet();
            try {
                descendingSet.floor(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.floor(entryArray[i]);
                assertEquals(j - i, entry.getValue());
            }
        }

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


            }
        }
    }

    public void test_DescendingSubMapKeySet_comparator() {
        NavigableSet keySet, descendingKeySet;
        Comparator comparator;
        String[] keyArray;
        Integer value1, value2;

        keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
        assertNull(keySet.comparator());
        descendingKeySet = keySet.descendingSet();
        comparator = descendingKeySet.comparator();
        assertNotNull(comparator);
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 1; i < keyArray.length; i++) {
            value1 = Integer.valueOf(keyArray[i - 1]);
            value2 = Integer.valueOf(keyArray[i]);
            assertTrue(value1 > value2);
            assertTrue(comparator.compare(value1, value2) < 0);
        }

        keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
        assertNull(keySet.comparator());
        descendingKeySet = keySet.descendingSet();
        comparator = descendingKeySet.comparator();
        assertNotNull(comparator);
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 1; i < keyArray.length; i++) {
            value1 = Integer.valueOf(keyArray[i - 1]);
            value2 = Integer.valueOf(keyArray[i]);
            assertTrue(value1 > value2);
            assertTrue(comparator.compare(value1, value2) < 0);
        }

        keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
        assertNull(keySet.comparator());
        descendingKeySet = keySet.descendingSet();
        comparator = descendingKeySet.comparator();
        assertNotNull(comparator);
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 1; i < keyArray.length; i++) {
            value1 = Integer.valueOf(keyArray[i - 1]);
            value2 = Integer.valueOf(keyArray[i]);
            assertTrue(value1 > value2);
            assertTrue(comparator.compare(value1, value2) < 0);
        }

        keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
        assertNull(keySet.comparator());
        descendingKeySet = keySet.descendingSet();
        comparator = descendingKeySet.comparator();
        assertNotNull(comparator);
        keyArray = (String[]) descendingKeySet
                .toArray(new String[descendingKeySet.size()]);
        for (int i = 1; i < keyArray.length; i++) {
            value1 = Integer.valueOf(keyArray[i - 1]);
            value2 = Integer.valueOf(keyArray[i]);
            assertTrue(value1 > value2);
            assertTrue(comparator.compare(value1, value2) < 0);
        }

        String endKey = new Integer(2).toString();
        keySet = tm.headMap(endKey, true).navigableKeySet();
        assertNull(keySet.comparator());
        descendingKeySet = keySet.descendingSet();
        assertNotNull(descendingKeySet.comparator());
    }
View Full Code Here

        }
    }

    public void test_DescendingSubMapEntrySet_last() {
        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.last();
            assertEquals(108, entry.getValue());
        }

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

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

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

    public void test_DescendingSubMapEntrySet_pollFirst_startExcluded_endExcluded() {
        Set entrySet = navigableMap_startExcluded_endExcluded.entrySet();
        Entry entry;
        if (entrySet instanceof NavigableSet) {
            NavigableSet descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            assertEquals(8, descendingSubMapEntrySet.size());
            for (int i = 101; i < 109; i++) {
                entry = (Entry) descendingSubMapEntrySet.pollFirst();
                assertEquals(i, entry.getValue());
            }
            assertNull(descendingSubMapEntrySet.pollFirst());
        }
    }
View Full Code Here

    public void test_DescendingSubMapEntrySet_pollFirst_startExcluded_endIncluded() {
        Set entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        Entry entry;
        if (entrySet instanceof NavigableSet) {
            NavigableSet descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            assertEquals(9, descendingSubMapEntrySet.size());
            for (int i = 101; i < 110; i++) {
                entry = (Entry) descendingSubMapEntrySet.pollFirst();
                assertEquals(i, entry.getValue());
            }
            assertNull(descendingSubMapEntrySet.pollFirst());
        }
    }
View Full Code Here

    public void test_DescendingSubMapEntrySet_pollFirst_startIncluded_endExcluded() {
        Set entrySet = navigableMap_startIncluded_endExcluded.entrySet();
        Entry entry;
        if (entrySet instanceof NavigableSet) {
            NavigableSet descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            assertEquals(9, descendingSubMapEntrySet.size());
            for (int i = 100; i < 109; i++) {
                entry = (Entry) descendingSubMapEntrySet.pollFirst();
                assertEquals(i, entry.getValue());
            }
            assertNull(descendingSubMapEntrySet.pollFirst());
        }
    }
View Full Code Here

    public void test_DescendingSubMapEntrySet_pollFirst_startIncluded_endIncluded() {
        Set entrySet = navigableMap_startIncluded_endIncluded.entrySet();
        Entry entry;
        if (entrySet instanceof NavigableSet) {
            NavigableSet descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            assertEquals(10, descendingSubMapEntrySet.size());
            for (int i = 100; i < 110; i++) {
                entry = (Entry) descendingSubMapEntrySet.pollFirst();
                assertEquals(i, entry.getValue());
            }
            assertNull(descendingSubMapEntrySet.pollFirst());
        }
    }
View Full Code Here

    }

    public void test_DescendingSubMapEntrySet_pollFirst() {
        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.pollFirst();
            assertEquals(0, entry.getValue());
        }

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

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

    public void test_DescendingSubMapEntrySet_pollLast_startExcluded_endInclued() {
        Set entrySet = navigableMap_startExcluded_endIncluded.entrySet();
        Entry entry;
        if (entrySet instanceof NavigableSet) {
            NavigableSet descendingSubMapEntrySet = ((NavigableSet) entrySet)
                    .descendingSet();
            assertEquals(9, descendingSubMapEntrySet.size());
            for (int i = 109; i > 100; i--) {
                entry = (Entry) descendingSubMapEntrySet.pollLast();
                assertEquals(i, entry.getValue());
            }
            assertNull(descendingSubMapEntrySet.pollFirst());
        }
    }
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.