Skip to content

Commit f87160d

Browse files
authored
Merge pull request eugenp#7726 from rodrigolgraciano/BAEL-3173
BAEL-3173
2 parents 434bfc9 + e925b07 commit f87160d

File tree

2 files changed

+91
-3
lines changed

2 files changed

+91
-3
lines changed

libraries-primitive/pom.xml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
<version>1.0-SNAPSHOT</version>
1010
<name>libraries-primitive</name>
1111

12+
<properties>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
</properties>
16+
1217
<dependencies>
13-
<!-- https://mvnrepository.com/artifact/it.unimi.dsi/fastutil -->
14-
<dependency>
18+
<!-- https://mvnrepository.com/artifact/it.unimi.dsi/fastutil -->
19+
<dependency>
1520
<groupId>it.unimi.dsi</groupId>
1621
<artifactId>fastutil</artifactId>
1722
<version>8.2.2</version>
@@ -36,5 +41,18 @@
3641
<version>1.19</version>
3742
<scope>test</scope>
3843
</dependency>
44+
<!-- Eclipse Collections -->
45+
<dependency>
46+
<groupId>org.eclipse.collections</groupId>
47+
<artifactId>eclipse-collections-api</artifactId>
48+
<version>10.0.0</version>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.eclipse.collections</groupId>
53+
<artifactId>eclipse-collections</artifactId>
54+
<version>10.0.0</version>
55+
</dependency>
56+
3957
</dependencies>
40-
</project>
58+
</project>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.baeldung;
2+
3+
import org.eclipse.collections.api.list.primitive.ImmutableIntList;
4+
import org.eclipse.collections.api.list.primitive.MutableLongList;
5+
import org.eclipse.collections.api.map.primitive.MutableIntIntMap;
6+
import org.eclipse.collections.api.set.primitive.MutableIntSet;
7+
import org.eclipse.collections.impl.factory.primitive.*;
8+
import org.eclipse.collections.impl.list.Interval;
9+
import org.eclipse.collections.impl.list.primitive.IntInterval;
10+
import org.eclipse.collections.impl.map.mutable.primitive.IntIntHashMap;
11+
import org.junit.Test;
12+
13+
import java.util.stream.DoubleStream;
14+
15+
import static org.junit.Assert.assertEquals;
16+
17+
18+
public class PrimitiveCollectionsUnitTest {
19+
20+
@Test
21+
public void whenListOfLongHasOneTwoThree_thenSumIsSix() {
22+
MutableLongList longList = LongLists.mutable.of(1L, 2L, 3L);
23+
assertEquals(6, longList.sum());
24+
}
25+
26+
@Test
27+
public void whenListOfIntHasOneTwoThree_thenMaxIsThree() {
28+
ImmutableIntList intList = IntLists.immutable.of(1, 2, 3);
29+
assertEquals(3, intList.max());
30+
}
31+
32+
@Test
33+
public void whenConvertFromIterableToPrimitive_thenValuesAreEquals() {
34+
Iterable<Integer> iterable = Interval.oneTo(3);
35+
MutableIntSet intSet = IntSets.mutable.withAll(iterable);
36+
IntInterval intInterval = IntInterval.oneTo(3);
37+
assertEquals(intInterval.toSet(), intSet);
38+
}
39+
40+
@Test
41+
public void testOperationsOnIntIntMap() {
42+
MutableIntIntMap map = new IntIntHashMap();
43+
assertEquals(5, map.addToValue(0, 5));
44+
assertEquals(5, map.get(0));
45+
assertEquals(3, map.getIfAbsentPut(1, 3));
46+
}
47+
48+
@Test
49+
public void whenCreateDoubleStream_thenAverageIsThree() {
50+
DoubleStream doubleStream = DoubleLists
51+
.mutable.with(1.0, 2.0, 3.0, 4.0, 5.0)
52+
.primitiveStream();
53+
assertEquals(3, doubleStream.average().getAsDouble(), 0.001);
54+
}
55+
56+
@Test
57+
public void whenCreateMapFromStream_thenValuesMustMatch() {
58+
Iterable<Integer> integers = Interval.oneTo(3);
59+
MutableIntIntMap map =
60+
IntIntMaps.mutable.from(
61+
integers,
62+
key -> key,
63+
value -> value * value);
64+
MutableIntIntMap expected = IntIntMaps.mutable.empty()
65+
.withKeyValue(1, 1)
66+
.withKeyValue(2, 4)
67+
.withKeyValue(3, 9);
68+
assertEquals(expected, map);
69+
}
70+
}

0 commit comments

Comments
 (0)