Skip to content

Commit 310e89e

Browse files
Ahmed Tawilapivovarit
authored andcommitted
BAEL-1035 Introduction to Eclipse Collections (eugenp#2421)
* 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 * BAEL-1035 Introduction to Eclipse Collections
1 parent a4132df commit 310e89e

7 files changed

Lines changed: 115 additions & 4 deletions

File tree

‎libraries/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,4 @@
515515
<rome.version>1.0</rome.version>
516516
<eclipse-collections.version>8.2.0</eclipse-collections.version>
517517
</properties>
518-
</project>
518+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
11
package com.baeldung.eclipsecollections;
22

3+
import java.util.List;
4+
35
public class Student {
46

57
private String firstName;
68
private String lastName;
9+
private List<String> addresses;
710

811
public Student(String firstName, String lastName) {
912
this.firstName = firstName;
1013
this.lastName = lastName;
1114
}
1215

16+
public Student(String firstName, String lastName, List<String> addresses) {
17+
super();
18+
this.firstName = firstName;
19+
this.lastName = lastName;
20+
this.addresses = addresses;
21+
}
22+
1323
public String getFirstName() {
1424
return this.firstName;
1525
}
1626

1727
public String getLastName() {
1828
return this.lastName;
1929
}
30+
31+
public List<String> getAddresses() {
32+
return addresses;
33+
}
34+
35+
public void setAddresses(List<String> addresses) {
36+
this.addresses = addresses;
37+
}
38+
39+
public void setFirstName(String firstName) {
40+
this.firstName = firstName;
41+
}
42+
43+
public void setLastName(String lastName) {
44+
this.lastName = lastName;
45+
}
2046
}

‎libraries/src/test/java/com/baeldung/eclipsecollections/CollectPatternTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void whenCollect_thenCorrect() {
1616

1717
MutableList<String> lastNames = students.collect(Student::getLastName);
1818

19-
assertEquals(lastNames.get(0), "Hopkins");
20-
assertEquals(lastNames.get(1), "Adams");
19+
assertEquals("Hopkins", lastNames.get(0));
20+
assertEquals("Adams", lastNames.get(1));
2121
}
2222
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.Before;
7+
import org.junit.Test;
8+
9+
public class FlatCollectTest {
10+
11+
MutableList<String> addresses1;
12+
MutableList<String> addresses2;
13+
MutableList<String> addresses3;
14+
MutableList<String> addresses4;
15+
16+
MutableList<Student> students;
17+
18+
@Before
19+
public void setup() {
20+
String address1 = "73 Pacific St., Forest Hills, NY 11375";
21+
String address2 = "93 Bayport Ave., South Richmond Hill, NY 11419";
22+
String address3 = "548 Market St, San Francisco, CA 94104";
23+
String address4 = "8605 Santa Monica Blvd, West Hollywood, CA 90069";
24+
25+
this.addresses1 = FastList.newListWith(address1, address2);
26+
this.addresses2 = FastList.newListWith(address3, address4);
27+
Student student1 = new Student("John", "Hopkins", addresses1);
28+
Student student2 = new Student("George", "Adams", addresses2);
29+
this.addresses2 = FastList.newListWith(address3, address4);
30+
this.students = FastList.newListWith(student1, student2);
31+
}
32+
33+
@Test
34+
public void whenFlatCollect_thenCorrect() {
35+
MutableList<String> addresses = students.flatCollect(Student::getAddresses);
36+
37+
assertEquals("73 Pacific St., Forest Hills, NY 11375", addresses.get(0));
38+
assertEquals("93 Bayport Ave., South Richmond Hill, NY 11419", addresses.get(1));
39+
assertEquals("548 Market St, San Francisco, CA 94104", addresses.get(2));
40+
assertEquals("8605 Santa Monica Blvd, West Hollywood, CA 90069", addresses.get(3));
41+
}
42+
}

‎libraries/src/test/java/com/baeldung/eclipsecollections/PartitionPatternTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public void getList() {
2828
list.add(38);
2929
}
3030

31-
@SuppressWarnings({ "unused" })
3231
@Test
3332
public void whenAnySatisfiesCondition_thenCorrect() {
3433
MutableList<Integer> numbers = list;
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.api.tuple.Pair;
5+
import org.eclipse.collections.impl.factory.Lists;
6+
import org.eclipse.collections.impl.tuple.Tuples;
7+
import static org.junit.Assert.assertEquals;
8+
import org.junit.Test;
9+
10+
public class ZipTest {
11+
12+
@Test
13+
public void whenZip_thenCorrect() {
14+
MutableList<String> numbers = Lists.mutable.with("1", "2", "3", "Ignored");
15+
MutableList<String> cars = Lists.mutable.with("Porsche", "Volvo", "Toyota");
16+
MutableList<Pair<String, String>> pairs = numbers.zip(cars);
17+
18+
assertEquals(Tuples.pair("1", "Porsche"), pairs.get(0));
19+
assertEquals(Tuples.pair("2", "Volvo"), pairs.get(1));
20+
assertEquals(Tuples.pair("3", "Toyota"), pairs.get(2));
21+
}
22+
}
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 static org.junit.Assert.assertEquals;
4+
5+
import org.eclipse.collections.api.list.MutableList;
6+
import org.eclipse.collections.api.tuple.Pair;
7+
import org.eclipse.collections.impl.list.mutable.FastList;
8+
import org.eclipse.collections.impl.tuple.Tuples;
9+
import org.junit.Test;
10+
11+
public class ZipWithIndexTest {
12+
13+
@Test
14+
public void whenZip_thenCorrect() {
15+
MutableList<String> cars = FastList.newListWith("Porsche", "Volvo", "Toyota");
16+
MutableList<Pair<String, Integer>> pairs = cars.zipWithIndex();
17+
18+
assertEquals(Tuples.pair("Porsche", 0), pairs.get(0));
19+
assertEquals(Tuples.pair("Volvo", 1), pairs.get(1));
20+
assertEquals(Tuples.pair("Toyota", 2), pairs.get(2));
21+
}
22+
}

0 commit comments

Comments
 (0)