Skip to content

Instantly share code, notes, and snippets.

View SnuktheGreat's full-sized avatar

Snuk the Great SnuktheGreat

  • @timeseriesnl
  • Utrecht, The Netherlands
View GitHub Profile
@SnuktheGreat
SnuktheGreat / ParametrizedString.java
Last active February 25, 2016 16:41
ParameterizedString - Utility for replacing named markers in a String.
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@SnuktheGreat
SnuktheGreat / ಠ_ಠ.java
Created November 9, 2015 09:31
Pointless, but fun way to throw exceptions!
ಠ_ಠ(new IOException("Disk blew up."))
...
public <T extends Throwable> void ಠ_ಠ(T exception) throws T{
throw exception;
}
@SnuktheGreat
SnuktheGreat / GenericTypeErasureTest.java
Last active October 16, 2015 09:38
This test shows how generic type erasures work.
package com.impressiveinteractive.playground;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@SnuktheGreat
SnuktheGreat / UtilException
Created July 15, 2015 11:42
Type safe work-around of throwing typed exceptions from within Streams. It builds upon the accepted answer of this question on stack overflow: http://stackoverflow.com/questions/27644361/how-can-i-throw-checked-exceptions-from-inside-java-8-streams
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
public class UtilException<E extends Exception> {
private static final UtilException INSTANCE = new UtilException();
@SuppressWarnings("unchecked")
public static <E extends Exception> UtilException<E> create() throws E {
return INSTANCE;