Search in sources :

Example 1 with IntSet

use of org.eclipse.collections.api.set.primitive.IntSet in project eclipse-collections by eclipse.

the class PersonAndPetKataTest method getAgeStatisticsOfPets.

@Test
public void getAgeStatisticsOfPets() {
    IntList ages = this.people.asLazy().flatCollect(Person::getPets).collectInt(Pet::getAge).toList();
    IntSet uniqueAges = ages.toSet();
    IntSummaryStatistics stats = ages.summaryStatistics();
    Assert.assertEquals(IntHashSet.newSetWith(1, 2, 3, 4), uniqueAges);
    Assert.assertEquals(stats.getMin(), ages.min());
    Assert.assertEquals(stats.getMax(), ages.max());
    Assert.assertEquals(stats.getSum(), ages.sum());
    Assert.assertEquals(stats.getAverage(), ages.average(), 0.0);
    Assert.assertEquals(stats.getCount(), ages.size());
    Assert.assertTrue(ages.allSatisfy(IntPredicates.greaterThan(0)));
    Assert.assertTrue(ages.allSatisfy(i -> i > 0));
    Assert.assertFalse(ages.anySatisfy(IntPredicates.equal(0)));
    Assert.assertFalse(ages.anySatisfy(i -> i == 0));
    Assert.assertTrue(ages.noneSatisfy(IntPredicates.lessThan(0)));
    Assert.assertTrue(ages.noneSatisfy(i -> i < 0));
    Assert.assertEquals(2.0d, ages.median(), 0.0);
}
Also used : Arrays(java.util.Arrays) Multimap(org.eclipse.collections.api.multimap.Multimap) HashMap(java.util.HashMap) ObjectIntPair(org.eclipse.collections.api.tuple.primitive.ObjectIntPair) Verify(org.eclipse.collections.impl.test.Verify) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) Multimaps(org.eclipse.collections.impl.factory.Multimaps) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MutableSet(org.eclipse.collections.api.set.MutableSet) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet) RichIterable(org.eclipse.collections.api.RichIterable) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) Map(java.util.Map) PrimitiveTuples(org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples) ImmutableBag(org.eclipse.collections.api.bag.ImmutableBag) PartitionMutableList(org.eclipse.collections.api.partition.list.PartitionMutableList) StringIterate(org.eclipse.collections.impl.utility.StringIterate) ImmutableIntBag(org.eclipse.collections.api.bag.primitive.ImmutableIntBag) Before(org.junit.Before) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) MutableListMultimap(org.eclipse.collections.api.multimap.list.MutableListMultimap) IntList(org.eclipse.collections.api.list.primitive.IntList) Set(java.util.Set) Bags(org.eclipse.collections.impl.factory.Bags) IntPredicates(org.eclipse.collections.impl.block.factory.primitive.IntPredicates) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MutableBagMultimap(org.eclipse.collections.api.multimap.bag.MutableBagMultimap) IntSet(org.eclipse.collections.api.set.primitive.IntSet) AbstractMap(java.util.AbstractMap) List(java.util.List) Lists(org.eclipse.collections.impl.factory.Lists) Sets(org.eclipse.collections.impl.factory.Sets) PartitionIterable(org.eclipse.collections.api.partition.PartitionIterable) IntSummaryStatistics(java.util.IntSummaryStatistics) Comparator(java.util.Comparator) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) IntSet(org.eclipse.collections.api.set.primitive.IntSet) IntSummaryStatistics(java.util.IntSummaryStatistics) IntList(org.eclipse.collections.api.list.primitive.IntList) Test(org.junit.Test)

Aggregations

AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 IntSummaryStatistics (java.util.IntSummaryStatistics)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 RichIterable (org.eclipse.collections.api.RichIterable)1 ImmutableBag (org.eclipse.collections.api.bag.ImmutableBag)1 MutableBag (org.eclipse.collections.api.bag.MutableBag)1 ImmutableIntBag (org.eclipse.collections.api.bag.primitive.ImmutableIntBag)1 MutableList (org.eclipse.collections.api.list.MutableList)1 IntList (org.eclipse.collections.api.list.primitive.IntList)1 Multimap (org.eclipse.collections.api.multimap.Multimap)1 MutableBagMultimap (org.eclipse.collections.api.multimap.bag.MutableBagMultimap)1