Goldman Sachs Collections PRO

The Goldman Sachs Collections framework (AKA GS Collections) provides us with an alternative implementation for the JDK collections framework.

GS Collections provides us with capabilities similar to those we find in programming languages such as Scala, C# and Samlltalk. Using this framework together with lambda expressions allows us writing significantly shorter code. The following code sample is a simple demo for showing the power of this framework while using lambda expressions.

package com.lifemichael.samples;

import com.gs.collections.api.list.MutableList;
import com.gs.collections.impl.list.mutable.FastList;

public class JumpStartDemo {
    public static void main(String args[]) {
        MutableList<Student> students = FastList.newList();
        students.add(new Student("moshe", 12312, 99));
        students.add(new Student("david", 52423, 89));
        students.add(new Student("ron", 54332, 94));
        MutableList<Student> bestStudents = students.select(ob->ob.getAverage()>90);
        System.out.println(bestStudents);

    }
}

The following video clip overviews this code sample, shows its execution and explains each and every part of it.

We can easily filter a collection that already exists and get a new one that includes just those elements that pass the criteria we set. The following code sample shows that.

package com.lifemichael.samples;

import com.gs.collections.api.list.MutableList;
import com.gs.collections.api.partition.list.PartitionMutableList;
import com.gs.collections.impl.list.mutable.FastList;

public class FilteringPatternsDemo {
    public static void main(String args[]) {
        MutableList<Student> students = FastList.newList();
        students.add(new Student("moshe", 12312, 99));
        students.add(new Student("david", 52423, 89));
        students.add(new Student("ron", 54332, 94));
        students.add(new Student("jane",98798, 93));
        students.add(new Student("rami",42333,76));
        students.add(new Student("john",83423,92));
        students.add(new Student("tal",42323,54));

        //select pattern
        MutableList<Student> bestStudents = students.select(ob->ob.getAverage()>90);
        System.out.println(bestStudents);
        System.out.println();

        //reject pattern
        MutableList<Student> studentsWhoPass = students.reject(ob -> ob.getAverage() < 60);
        System.out.println(studentsWhoPass);
        System.out.println();

        //partition pattern
        PartitionMutableList<Student> partitions = students.partition(ob -> ob.getAverage() > 90);
        MutableList<Student> excellentStudents = partitions.getSelected();
        MutableList<Student> simpleStudents = partitions.getRejected();
        System.out.println(excellentStudents);
        System.out.println(simpleStudents);

    }
}

The following video clip overviews this code sample, shows its execution and explains each and every part of it.

We can easily create a new collection based on a collection that already exist by specifying the transformation we want to take place. The following code sample shows how to do it.

package com.lifemichael.samples;

import com.gs.collections.api.list.MutableList;
import com.gs.collections.impl.list.mutable.FastList;
import com.gs.collections.api.multimap.Multimap;

public class TransformingPatternsDemo {
    public static void main(String args[]) {
        MutableList<Student> students = FastList.newList();
        students.add(new Student("moshe", 12312, 99));
        students.add(new Student("david", 52423, 85));
        students.add(new Student("ron", 54332, 94));
        students.add(new Student("jane",98798, 94));
        students.add(new Student("rami",42333,76));
        students.add(new Student("john",83423,85));
        students.add(new Student("tal",42323,54));

        //collect pattern
        MutableList<String> names = students.collect(ob->ob.getName());
        System.out.println(names);
        System.out.println();

        //collect if pattern
        MutableList<String> namesOfBestStudents = students.collectIf(ob->ob.getAverage()>90,ob->ob.getName());
        System.out.println(namesOfBestStudents);
        System.out.println();

        //group by pattern
        Multimap<Double,Student> map = students.groupBy(ob->ob.getAverage());
        System.out.println(map);
        System.out.println();
    }
}

The following video clip overviews this code sample, explains each and every part of it and shows its exectuion.

You can find more video clips, code samples and training material for learning how to use this framework in my new Goldman Sachs Collections course. You can find its community free version at http://abelski.lifemichael.com.

Share:

The Visitor Design Pattern

The Visitor Design Pattern

The visitor design pattern allows us to add operations to objects that already exist without modifying their classes and without extending them.

What are Anti Patterns?

Anti Patterns

Unlike design patterns, anti patterns just seem to be a solution. However, they are not a solution and they cause additional costs.

Virtual Threads in Java Professional Seminar

Virtual Threads in Java

The use of virtual threads can assist us with improving the performance of our code. Learn how to use virtual threads effectively.

NoSQL Databases Courses, Seminars, Consulting, and Development

MongoDB Design Patterns Meetup

The use of MongoDB involves with various cases in which we can overcome performance issues by implementing specific design patterns.

image of woman and database

Record Classes in Java

Learn how to define record classes in Java, and when to use record classes in your code. Stay up to date with the new Java features.

Accessibility | Career | Conferences | Design Patterns | JavaScript | Meetups | PHP | Podcasts | Python | Self Learning

Teaching Methodologies | Fullstack | C++ | C# | CSS | Node.js | Angular | Java | Go | Android | Kotlin | Swift | Academy

Front End Development | Scala | Architectures | Cloud | Big Data | Internet of Things | Kids Learn Programming

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Skip to content Update cookies preferences