bobobear / lambdaj

Automatically exported from code.google.com/p/lambdaj
Apache License 2.0
0 stars 0 forks source link

Group.subgroups() throws #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Instantiate new hierarchical 2-level Group with 
     Group<SomeClass> groupedObjects = Groups.group(someList,
       by(on(SomeClass.class).getString1()),
       by(on(SomeClass.class).getString2()));
2. Iterate over all subgroups
     for (Group<SomeClass> subgroup1 : groupedObjects.subgroups()) {
       //...
     }

What is the expected output? What do you see instead?
I expected to be able to iterate over all subgroups of groupedObjects;
instead, I got a ClassCastException: SomeClass cannot be cast to Group. 

What version of the product are you using? On what operating system?
Version 2.2, Microsoft Windows 7 Professional

Please provide any additional information below.
Apparently, the returned list does not contain objects of type Group, but
already of type SomeClass.

Original issue reported on code.google.com by stmit...@gmail.com on 21 Apr 2010 at 6:52

GoogleCodeExporter commented 9 years ago
I am not able to reproduce the problem, but probably I am missing something. 
Could
you please attach the whole test case, including the SomeClass class and how you
create the SomeClass objects that you put in the list to be grouped?

Original comment by mario.fu...@gmail.com on 21 Apr 2010 at 7:20

GoogleCodeExporter commented 9 years ago
I faced the same problem. Here the test method I've added to TypedGroupByTest 
class:

@Test
public void testGroupByAgeAndNameIterate() {
        List<Person> meAndMyFriends = asList(me, luca, biagio, celestino);

    Group<Person> group = group(meAndMyFriends, by(on(Person.class).getAge()), 
by(on(Person.class).getFirstName()));

    for(Group<Person> subgroup:group.subgroups()){
        assertNotNull(subgroup.findAll());
    }
}

Original comment by andrei.b...@gmail.com on 11 May 2010 at 4:51

Attachments:

GoogleCodeExporter commented 9 years ago
The previous test case produces the following exception:
java.lang.ClassCastException: ch.lambdaj.mock.Person cannot be cast to 
ch.lambdaj.group.Group
    at 
ch.lambdaj.group.TypedGroupByTest.testGroupByAgeAndNameIterate(TypedGroupByTest.
java:11
1)

Original comment by andrei.b...@gmail.com on 11 May 2010 at 4:55

GoogleCodeExporter commented 9 years ago
Fixed in release 2.3
Thank you to Andrey Belyaev for the fix

Original comment by mario.fu...@gmail.com on 21 May 2010 at 2:33