anirudha-wegilant / lambdaj

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

new variance and noVariance functions. #39

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
// you choose between variance(..) and hasVariance(..) 
// and  noVariance(..) and hasNoVariance(..) 

public class GroupsVarianceTest {

    private Person mario1 = new Person("Mario", "Fusco", true, "01/01/1999" );
    private Person peter = new Person("Peter", "Pan", true, "02/02/1999" );
    private Person mario2 = new Person("Mario", "Two", true, "04/04/1999");

    @Test
    public void oneGroupsRecognizedSuggestingNoVariance() {
        assertTrue(hasNoVariance(asList(mario1, mario2), by(on(Person.class).getFirstName())));
    }

    private boolean hasNoVariance(Iterable<?> iterable, GroupCondition<?>... conditions) {
        return variance(iterable, conditions) == 1;
    }

    private int variance(Iterable<?> iterable, GroupCondition<?>... conditions) {
        return group(iterable, conditions).subgroups().size();
    }

}

Original issue reported on code.google.com by PaulHamm...@gmail.com on 2 Sep 2010 at 1:15

GoogleCodeExporter commented 8 years ago

Original comment by mario.fu...@gmail.com on 30 Oct 2010 at 3:43