BAEL-1035 Introduction to Eclipse Collections (#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
This commit is contained in:
parent
a4132df3e5
commit
310e89e4f0
|
@ -515,4 +515,4 @@
|
||||||
<rome.version>1.0</rome.version>
|
<rome.version>1.0</rome.version>
|
||||||
<eclipse-collections.version>8.2.0</eclipse-collections.version>
|
<eclipse-collections.version>8.2.0</eclipse-collections.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
|
@ -1,15 +1,25 @@
|
||||||
package com.baeldung.eclipsecollections;
|
package com.baeldung.eclipsecollections;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Student {
|
public class Student {
|
||||||
|
|
||||||
private String firstName;
|
private String firstName;
|
||||||
private String lastName;
|
private String lastName;
|
||||||
|
private List<String> addresses;
|
||||||
|
|
||||||
public Student(String firstName, String lastName) {
|
public Student(String firstName, String lastName) {
|
||||||
this.firstName = firstName;
|
this.firstName = firstName;
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Student(String firstName, String lastName, List<String> addresses) {
|
||||||
|
super();
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.lastName = lastName;
|
||||||
|
this.addresses = addresses;
|
||||||
|
}
|
||||||
|
|
||||||
public String getFirstName() {
|
public String getFirstName() {
|
||||||
return this.firstName;
|
return this.firstName;
|
||||||
}
|
}
|
||||||
|
@ -17,4 +27,20 @@ public class Student {
|
||||||
public String getLastName() {
|
public String getLastName() {
|
||||||
return this.lastName;
|
return this.lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getAddresses() {
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddresses(List<String> addresses) {
|
||||||
|
this.addresses = addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ public class CollectPatternTest {
|
||||||
|
|
||||||
MutableList<String> lastNames = students.collect(Student::getLastName);
|
MutableList<String> lastNames = students.collect(Student::getLastName);
|
||||||
|
|
||||||
assertEquals(lastNames.get(0), "Hopkins");
|
assertEquals("Hopkins", lastNames.get(0));
|
||||||
assertEquals(lastNames.get(1), "Adams");
|
assertEquals("Adams", lastNames.get(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.baeldung.eclipsecollections;
|
||||||
|
|
||||||
|
import org.eclipse.collections.api.list.MutableList;
|
||||||
|
import org.eclipse.collections.impl.list.mutable.FastList;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class FlatCollectTest {
|
||||||
|
|
||||||
|
MutableList<String> addresses1;
|
||||||
|
MutableList<String> addresses2;
|
||||||
|
MutableList<String> addresses3;
|
||||||
|
MutableList<String> addresses4;
|
||||||
|
|
||||||
|
MutableList<Student> students;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
String address1 = "73 Pacific St., Forest Hills, NY 11375";
|
||||||
|
String address2 = "93 Bayport Ave., South Richmond Hill, NY 11419";
|
||||||
|
String address3 = "548 Market St, San Francisco, CA 94104";
|
||||||
|
String address4 = "8605 Santa Monica Blvd, West Hollywood, CA 90069";
|
||||||
|
|
||||||
|
this.addresses1 = FastList.newListWith(address1, address2);
|
||||||
|
this.addresses2 = FastList.newListWith(address3, address4);
|
||||||
|
Student student1 = new Student("John", "Hopkins", addresses1);
|
||||||
|
Student student2 = new Student("George", "Adams", addresses2);
|
||||||
|
this.addresses2 = FastList.newListWith(address3, address4);
|
||||||
|
this.students = FastList.newListWith(student1, student2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenFlatCollect_thenCorrect() {
|
||||||
|
MutableList<String> addresses = students.flatCollect(Student::getAddresses);
|
||||||
|
|
||||||
|
assertEquals("73 Pacific St., Forest Hills, NY 11375", addresses.get(0));
|
||||||
|
assertEquals("93 Bayport Ave., South Richmond Hill, NY 11419", addresses.get(1));
|
||||||
|
assertEquals("548 Market St, San Francisco, CA 94104", addresses.get(2));
|
||||||
|
assertEquals("8605 Santa Monica Blvd, West Hollywood, CA 90069", addresses.get(3));
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,7 +28,6 @@ public class PartitionPatternTest {
|
||||||
list.add(38);
|
list.add(38);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAnySatisfiesCondition_thenCorrect() {
|
public void whenAnySatisfiesCondition_thenCorrect() {
|
||||||
MutableList<Integer> numbers = list;
|
MutableList<Integer> numbers = list;
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.baeldung.eclipsecollections;
|
||||||
|
|
||||||
|
import org.eclipse.collections.api.list.MutableList;
|
||||||
|
import org.eclipse.collections.api.tuple.Pair;
|
||||||
|
import org.eclipse.collections.impl.factory.Lists;
|
||||||
|
import org.eclipse.collections.impl.tuple.Tuples;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ZipTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenZip_thenCorrect() {
|
||||||
|
MutableList<String> numbers = Lists.mutable.with("1", "2", "3", "Ignored");
|
||||||
|
MutableList<String> cars = Lists.mutable.with("Porsche", "Volvo", "Toyota");
|
||||||
|
MutableList<Pair<String, String>> pairs = numbers.zip(cars);
|
||||||
|
|
||||||
|
assertEquals(Tuples.pair("1", "Porsche"), pairs.get(0));
|
||||||
|
assertEquals(Tuples.pair("2", "Volvo"), pairs.get(1));
|
||||||
|
assertEquals(Tuples.pair("3", "Toyota"), pairs.get(2));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.baeldung.eclipsecollections;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.eclipse.collections.api.list.MutableList;
|
||||||
|
import org.eclipse.collections.api.tuple.Pair;
|
||||||
|
import org.eclipse.collections.impl.list.mutable.FastList;
|
||||||
|
import org.eclipse.collections.impl.tuple.Tuples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ZipWithIndexTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenZip_thenCorrect() {
|
||||||
|
MutableList<String> cars = FastList.newListWith("Porsche", "Volvo", "Toyota");
|
||||||
|
MutableList<Pair<String, Integer>> pairs = cars.zipWithIndex();
|
||||||
|
|
||||||
|
assertEquals(Tuples.pair("Porsche", 0), pairs.get(0));
|
||||||
|
assertEquals(Tuples.pair("Volvo", 1), pairs.get(1));
|
||||||
|
assertEquals(Tuples.pair("Toyota", 2), pairs.get(2));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue