Skip to content

Instantly share code, notes, and snippets.

View nschlimm's full-sized avatar
🏠
Working from home

Niklas Schlimm nschlimm

🏠
Working from home
  • TIMOCOM GmbH
  • Cologne, Germany
View GitHub Profile
@nschlimm
nschlimm / gist:2134350
Created March 20, 2012 11:36
PoolSizeCalculator
/**
* A class that calculates the optimal thread pool boundaries. It takes the desired target utilization and the desired
* work queue memory consumption as input and retuns thread count and work queue capacity.
*
* @author Niklas Schlimm
*
*/
public abstract class PoolSizeCalculator {
/**
@nschlimm
nschlimm / gist:2234464
Created March 29, 2012 07:13
ThreadLocalUtil
public class ThreadLocalUtil {
private final static ThreadLocal<ThreadVariables> THREAD_VARIABLES = new ThreadLocal<ThreadVariables>() {
/**
* @see java.lang.ThreadLocal#initialValue()
*/
@Override
protected ThreadVariables initialValue() {
return new ThreadVariables();
@nschlimm
nschlimm / TypeInference.java
Last active February 5, 2019 08:23
Type Inference on Method chaining
public class SomePojo<T> {
private String someProperty;
private String anotherProperty;
private SomePojo(Builder<T> builder) {
this.someProperty = builder.someProperty;
this.anotherProperty = builder.anotherProperty;
}
// shopping basket with state pattern
public static class ShoppingBasket {
private String orderNo;
private List<String> articleNumbers = new ArrayList<>();
private UpdateState state = UpdateState.UPDATEABLE;
public void add(String articleNumber) {
articleNumbers.add(state.set(articleNumber));
}
public String getOrderNo() {
return orderNo;
public enum UpdateState {
UPDATEABLE(()->Validate.validState(true)), READONLY(()->Validate.validState(false));
private Runnable action;
private UpdateState(Runnable action) {
this.action=action;
}
public <T> T set(T value) {
action.run();
return value;
}
public static class ShoppingBasket1 {
private String orderNo;
private List<String> articleNumbers = new ArrayList<>();
public void add(String articleNumber) {
articleNumbers.add(articleNumber);
}
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
Predicates predicates = new Predicates("SSH");
System.getenv().keySet().stream().filter(predicates::containsPattern).collect(Collectors.toSet());
@nschlimm
nschlimm / Predicates.java
Last active January 30, 2019 08:25
Predicates with standard parameter
public static class Predicates {
private String pattern;
public boolean containsPattern(String string) {
return string.contains(pattern);
}
public Predicates(String pattern) {
this.pattern = pattern;
}
}
@nschlimm
nschlimm / gist:1060939
Created July 2, 2011 15:56
Ant build file to run Arquillian test
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="runtests" name="testng_tests">
<property environment="env" />
<property name="M2_REPO" value="C:/Users/nschlimm/.m2/repository" />
<property name="ECLIPSE_HOME" value="../../../../eclipse-3.6" />
@nschlimm
nschlimm / gist:1206265
Created September 9, 2011 13:54
ConcurrentTransformer
protected class ConcurrentTransformer {
private final Lock lock = new ReentrantLock();
private URL url = null;
private volatile Templates template = null;
private long lastCompileTime = Long.MAX_VALUE;
protected Templates generateTemplate(long ladezeitProzessApp) throws TransformerFactoryConfigurationError, TransformerConfigurationException, InterruptedException {
if (!mustCompile(loadTimeApplication)) {
return template;