Skip to content

Commit c3de3db

Browse files
Ahmed Tawilapivovarit
authored andcommitted
BAEL 1035 - Introduction to Eclipse Collections (eugenp#2395)
* Evaluation article: Different Types of Bean Injection in Spring * added tests & changed configuration to Java-based config * removed xml config files * rename unit tests * BAEL-972 - Apache Commons Text * remove code from evaluation article * remove code from evaluation article * BAEL-972 - Apache Commons Text - added another example * BAEL-972 - Apache Commons Text - just indentation * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java - fix problems * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * fix formatting * BAEL-1033 minor refactor * BAEL-1035 Introduction to Eclipse Collections * format * BAEL-1035 Introduction to Eclipse Collections
1 parent 146b633 commit c3de3db

14 files changed

Lines changed: 423 additions & 1 deletion

‎libraries/pom.xml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@
462462
<artifactId>pcollections</artifactId>
463463
<version>${pcollections.version}</version>
464464
</dependency>
465+
<dependency>
466+
<groupId>org.eclipse.collections</groupId>
467+
<artifactId>eclipse-collections</artifactId>
468+
<version>${eclipse-collections.version}</version>
469+
</dependency>
465470
</dependencies>
466471
<properties>
467472
<multiverse.version>0.7.0</multiverse.version>
@@ -503,5 +508,6 @@
503508
<bytebuddy.version>1.7.1</bytebuddy.version>
504509
<pcollections.version>2.1.2</pcollections.version>
505510
<rome.version>1.0</rome.version>
511+
<eclipse-collections.version>8.2.0</eclipse-collections.version>
506512
</properties>
507-
</project>
513+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.eclipsecollections;
2+
3+
import java.util.List;
4+
5+
import org.eclipse.collections.api.list.MutableList;
6+
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
7+
8+
public class ConvertContainerToAnother {
9+
10+
@SuppressWarnings("rawtypes")
11+
public static List convertToList() {
12+
UnifiedSet<String> cars = new UnifiedSet<>();
13+
14+
cars.add("Toyota");
15+
cars.add("Mercedes");
16+
cars.add("Volkswagen");
17+
18+
return cars.toList();
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.eclipsecollections;
2+
3+
public class Student {
4+
5+
private String firstName;
6+
private String lastName;
7+
8+
public Student(String firstName, String lastName) {
9+
this.firstName = firstName;
10+
this.lastName = lastName;
11+
}
12+
13+
public String getFirstName() {
14+
return this.firstName;
15+
}
16+
17+
public String getLastName() {
18+
return this.lastName;
19+
}
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung.eclipsecollections;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.eclipse.collections.api.list.MutableList;
6+
import org.eclipse.collections.impl.block.factory.Predicates;
7+
import org.eclipse.collections.impl.list.mutable.FastList;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
11+
public class AllSatisfyPatternTest {
12+
13+
MutableList<Integer> list;
14+
15+
@Before
16+
public void getList() {
17+
this.list = new FastList<>();
18+
list.add(1);
19+
list.add(8);
20+
list.add(5);
21+
list.add(41);
22+
list.add(31);
23+
list.add(17);
24+
list.add(23);
25+
list.add(38);
26+
}
27+
28+
@Test
29+
public void whenAnySatisfiesCondition_thenCorrect() {
30+
boolean result = list.allSatisfy(Predicates.greaterThan(0));
31+
32+
assertTrue(result);
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung.eclipsecollections;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.eclipse.collections.api.list.MutableList;
6+
import org.eclipse.collections.impl.block.factory.Predicates;
7+
import org.eclipse.collections.impl.list.mutable.FastList;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
11+
public class AnySatisfyPatternTest {
12+
13+
MutableList<Integer> list;
14+
15+
@Before
16+
public void getList() {
17+
this.list = new FastList<>();
18+
list.add(1);
19+
list.add(8);
20+
list.add(5);
21+
list.add(41);
22+
list.add(31);
23+
list.add(17);
24+
list.add(23);
25+
list.add(38);
26+
}
27+
28+
@Test
29+
public void whenAnySatisfiesCondition_thenCorrect() {
30+
boolean result = list.anySatisfy(Predicates.greaterThan(30));
31+
32+
assertTrue(result);
33+
}
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.eclipsecollections;
2+
3+
import org.eclipse.collections.api.list.MutableList;
4+
import org.eclipse.collections.impl.list.mutable.FastList;
5+
import static org.junit.Assert.assertEquals;
6+
import org.junit.Test;
7+
8+
public class CollectPatternTest {
9+
10+
@Test
11+
public void whenCollect_thenCorrect() {
12+
Student student1 = new Student("John", "Hopkins");
13+
Student student2 = new Student("George", "Adams");
14+
15+
MutableList<Student> students = FastList.newListWith(student1, student2);
16+
17+
MutableList<String> lastNames = students.collect(Student::getLastName);
18+
19+
assertEquals(lastNames.get(0), "Hopkins");
20+
assertEquals(lastNames.get(1), "Adams");
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.eclipsecollections;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.eclipse.collections.api.list.MutableList;
6+
import org.eclipse.collections.impl.block.factory.Predicates;
7+
import org.junit.Test;
8+
9+
public class ConvertContainerToAnotherTest {
10+
11+
@SuppressWarnings({ "unchecked", "rawtypes" })
12+
@Test
13+
public void whenConvertContainerToAnother_thenCorrect() {
14+
MutableList<String> cars = (MutableList) ConvertContainerToAnother.convertToList();
15+
16+
assertTrue(cars.anySatisfy(Predicates.equal("Toyota")));
17+
assertTrue(cars.anySatisfy(Predicates.equal("Mercedes")));
18+
assertTrue(cars.anySatisfy(Predicates.equal("Volkswagen")));
19+
}
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung.eclipsecollections;
2+
3+
import org.eclipse.collections.api.list.MutableList;
4+
import org.eclipse.collections.impl.block.factory.Predicates;
5+
import org.eclipse.collections.impl.list.mutable.FastList;
6+
import static org.junit.Assert.assertEquals;
7+
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
11+
public class DetectPatternTest {
12+
13+
MutableList<Integer> list;
14+
15+
@Before
16+
public void getList() {
17+
this.list = new FastList<>();
18+
list.add(1);
19+
list.add(8);
20+
list.add(5);
21+
list.add(41);
22+
list.add(31);
23+
list.add(17);
24+
list.add(23);
25+
list.add(38);
26+
}
27+
28+
@Test
29+
public void whenDetect_thenCorrect() {
30+
Integer result = list.detect(Predicates.greaterThan(30));
31+
32+
assertEquals((int) result, 41);
33+
}
34+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.eclipsecollections;
2+
3+
import org.eclipse.collections.api.block.procedure.Procedure;
4+
import org.eclipse.collections.api.tuple.Pair;
5+
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
6+
import org.eclipse.collections.impl.tuple.Tuples;
7+
import static org.junit.Assert.assertEquals;
8+
9+
import java.util.Map;
10+
11+
import org.junit.Test;
12+
13+
public class ForEachPatternTest {
14+
15+
@SuppressWarnings("unchecked")
16+
@Test
17+
public void whenInstantiateAndChangeValues_thenCorrect() {
18+
Pair<Integer, String> pair1 = Tuples.pair(1, "One");
19+
Pair<Integer, String> pair2 = Tuples.pair(2, "Two");
20+
Pair<Integer, String> pair3 = Tuples.pair(3, "Three");
21+
22+
UnifiedMap<Integer, String> map = UnifiedMap.newMapWith(pair1, pair2, pair3);
23+
24+
for (int i = 0; i < map.size(); i++) {
25+
map.put(i + 1, "New Value");
26+
}
27+
28+
for (int i = 0; i < map.size(); i++) {
29+
assertEquals("New Value", map.get(i + 1));
30+
}
31+
}
32+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.eclipsecollections;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.util.List;
6+
7+
import org.eclipse.collections.impl.factory.Lists;
8+
import org.junit.Test;
9+
10+
public class InjectIntoPatternTest {
11+
12+
@Test
13+
public void whenInjectInto_thenCorrect() {
14+
List<Integer> list = Lists.mutable.of(1, 2, 3, 4);
15+
int result = 5;
16+
for (int i = 0; i < list.size(); i++) {
17+
Integer v = list.get(i);
18+
result = result + v.intValue();
19+
}
20+
21+
assertEquals(15, result);
22+
}
23+
}

0 commit comments

Comments
 (0)