Question about Group.getHeads()

24 views
Skip to first unread message

Mats Sigge

unread,
Mar 29, 2012, 5:24:40 AM3/29/12
to lam...@googlegroups.com
Hi! I just started looking at LambdaJ and I'm playing with group(). And either I don't understand the getHeads() method, or there is a bug in it. If I run the test below, I get the output [], [bar] (on two lines), but I would have expected [foo], [foo, bar] (or [bar, foo] since it's a set). Is this the way it's intended to work? If so, could someone explain why? Or is it just a bug?

Other than that, kudo for a great library.

Regards,

Mats Sigge

My code:

import java.util.Arrays;
import java.util.List;

import ch.lambdaj.group.Group;

import static ch.lambdaj.Lambda.*;

public class LambdaJGroupTest {
    public static class Data {
        String foo;
        String bar;

        Data(String foo, String bar) {
            this.foo = foo;
            this.bar = bar;
        }

        public String getFoo() {
            return foo;
        }

        public String getBar() {
            return bar;
        }
    }

    public static void main(String[] args) {
        List<Data> list = Arrays.asList(
                new Data("foo1", "bar1"),
                new Data("foo1", "bar2"),
                new Data("foo2", "bar1"),
                new Data("foo2", "bar2")
        );
        Group<Data> group = group(list, by(on(Data.class).getFoo()), by(on(Data.class).getBar()));
        System.out.println(group.findGroup("foo1").getHeads());
        System.out.println(group.findGroup("foo1").findGroup("bar1").getHeads());
    }
}

Reply all
Reply to author
Forward
0 new messages