Java Stream Custom Collector – Howto

Sometimes the commonly available Collectors are not what we need.
Here is one example for a Singleton Custom Collector:

public static <T> Collector<T, ?, T> singleton() {
    return Collectors.collectingAndThen(
            Collectors.toList(), list -> {
                if (list.size() != 1) {
                    // or log and return nil
                    throw new CustomException();
                }
                return list.get(0);
            }
    );
}

//and use it:
        myObjectToStream.stream()
        .filter(elem -> elem.getExampleAttribute() == 0).collect(singleton());

Howto generate a new SSH key pair

ssh-keygen -t ed25519 -C "email@example.com"

Note that in this example we use an ed25519 key.

The -c is providing a comment to divide the key amongst others.

I alwas use the suggested path and just klick enter 😉

Multiple Webapps with Docker Compose

  • Learn how to setup a custom network for your containers: container A talks to container B
  • Learn how to run multiple webapps inside Docker containers on different ports with Docker Compose

Download complete source code here

  • Create the network with $docker network create skynet
  • Run with $docker-compose up
  • Stop with $<Ctrl + C>
  • Clean up from time to time (beware, network will be deleted as well) with $docker system prune -a -f
  • access via http://localhost:8080/sample
  • access via http://localhost:8081/sample