javolution.context.internal.LocalContextImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javolution-core-java-msftbx Show documentation
Show all versions of javolution-core-java-msftbx Show documentation
Only the Java Core part of Javolution library, with slight modifications for use in MSFTBX.
/*
* 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;
}
}