pkt1583 / functionaljava

Automatically exported from code.google.com/p/functionaljava
0 stars 0 forks source link

TreeMap iterator goes in descending order - no simple way to iterate in ascending order #40

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
<code language="java">
    @Test public void testTreeMapIteratorOrder() {
        final Ord<Integer> ord = Ord.<Integer>comparableOrd();
        final Integer ONE = Integer.valueOf(1);
        final Integer ZERO = Integer.valueOf(0);
        final TreeMap<Integer,Integer> ints = TreeMap.<Integer,Integer>empty(ord).set(ONE, ONE).set(ZERO, ZERO);
        final int[] ary = new int[ints.size()];
        final Iterator<P2<Integer, Integer>> it = ints.iterator();
        ary[0] = it.next()._1().intValue();
        ary[1] = it.next()._1().intValue();
        assertEquals(Arrays.toString(new int[] {0, 1}), Arrays.toString(ary));
    }
</code>

What is the expected output? What do you see instead?

The values are returned in descending order whereas I expected them to be in 
ascending order.

What version of the product are you using?

The last release, 3.1 from May 2012.

Please provide any additional information below.

I think perhaps it would be helpful to provide both an ascending and descending 
iterator and clearly document which is which.

Original issue reported on code.google.com by dob...@gmail.com on 17 Oct 2013 at 5:13