Skip to content

Instantly share code, notes, and snippets.

View nipafx's full-sized avatar

Nicolai Parlog nipafx

View GitHub Profile
@nipafx
nipafx / StephensAddress.java
Last active August 26, 2015 19:49
Null-Infested Address
public class Address {
private final String addressLine; // never null
private final String city; // never null
private final String postcode; // optional, thus may be null
// constructor ensures non-null fields really are non-null
// optional field can just be stored directly, as null means optional
public Address(String addressLine, String city, String postcode) {
this.addressLine = Preconditions.chckNotNull(addressLine);
@nipafx
nipafx / NicolaisExtendedAddress.java
Last active August 26, 2015 19:58
Null-free Extended Address
public class Address {
// look ma, no comments required
private final String addressLine;
private final String city;
private Optional<String> postcode;
// nobody has to look at these constructors to check which parameters are
// allowed to be null because of course none are!
@nipafx
nipafx / NicolaisBasicAddress.java
Last active August 26, 2015 20:03
Null-free Address
public class Address {
// look ma, no comments required
private final String addressLine;
private final String city;
private final Optional<String> postcode;
// nobody has to look at this constructor to check which parameters are
// allowed to be null because of course none are!
package org.codefx.lab.stream;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
/**
* Finds a certain customer in a collection of customers.
@nipafx
nipafx / MapGet.java
Created November 7, 2015 12:54
How nice would 'Map.getAsOptional' be?
package org.codefx.lab.optional;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class MapGet {
private final MapWithGetAsOptional<Integer, String> map = new HashMapWithGetAsOptional<>();
@nipafx
nipafx / blockchain
Created November 21, 2015 06:46
Blockchain GitHub Proof
Verifying that +nipa is my blockchain ID. https://onename.com/nipa
@nipafx
nipafx / keybase.md
Created November 21, 2015 07:08
Keybase GitHub Proof

Keybase proof

I hereby claim:

  • I am nicolaiparlog on github.
  • I am nipa (https://keybase.io/nipa) on keybase.
  • I have a public key whose fingerprint is 0781 2183 AB52 C901 733B 4D0E CA3B AD2E 9CCC D509

To claim this, I am signing this object:

@nipafx
nipafx / CallingDifferentSuperMethods.java
Last active January 18, 2016 07:34
It is not possible for a class to call a default implementation on an interface not mentioned in the 'implements' clause.
public class CallingDifferentSuperMethods {
private interface DefaultImplementing {
default boolean implemented() {
return true;
}
default boolean overridden() {
return true;
}
default boolean reabstracted() {
@nipafx
nipafx / JUG-KA-2016-03-16.md
Last active January 21, 2016 07:04
Abstract für JUG-KA-Treffen im März

Mit Project Jigsaw und Java 9 wird die Plattform modular. Das soll Sicherheit, Performance und Skalierbarkeit verbessern.

Aber nicht nur das JDK selbst, sondern auch Bibliotheken und Anwendungen steht der Weg in die Modularisierung offen. Mit dem Verlassen des fragilen Class Path soll der JAR Hell entkommen und die Wartbarkeit großer Anwendungen deutlich verbessert werden.

Die Vorträge zeigen die wichtigsten Features von Project Jigsaw anhand des Beispiels der Modularisierung einer bestehenden Anwendung:

  • Definition von Modulen und Modulgraphen
  • Laufzeitverhalten bei der Verletzung von Modularisierungsregeln
  • Integration von nicht-modularen 3rd-Party-Abhängigkeiten
@nipafx
nipafx / Factors.java
Last active February 2, 2016 07:11
Computing factors with Java 8 streams - see https://bit.ly/1VF85Fa 17:28
package org.codefx.lab.aliquot;
import com.google.common.collect.ImmutableSetMultimap;
import org.junit.Test;
import java.util.Collection;
import java.util.List;
import java.util.stream.IntStream;
import static java.lang.Math.sqrt;