javolution.context.internal.LocalContextImpl Maven / Gradle / Ivy
The newest version!
/*
* Javolution - Java(TM) Solution for Real-Time and Embedded Systems
* Copyright (C) 2012 - Javolution (http://javolution.org/)
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software is
* freely granted, provided that this notice is preserved.
*/
package javolution.context.internal;
import javolution.context.LocalContext;
import javolution.util.FastMap;
/**
* Holds the default implementation of LocalContext.
*/
public final class LocalContextImpl extends LocalContext {
private FastMap, Object> localSettings = new FastMap, Object>();
private LocalContextImpl parent;
@Override
protected LocalContext inner() {
LocalContextImpl ctx = new LocalContextImpl();
ctx.parent = this;
return ctx;
}
@Override
public void supersede(Parameter param, T localValue) {
if (localValue == null) throw new NullPointerException();
localSettings.put(param, localValue);
}
@SuppressWarnings("unchecked")
@Override
protected T getValue(Parameter param, T defaultValue) {
Object value = localSettings.get(param);
if (value != null) return (T) value;
if (parent != null) return parent.getValue(param, defaultValue);
return defaultValue;
}
}