
com.jfreeman.attribute.InheritedAttribute Maven / Gradle / Ivy
package com.jfreeman.attribute;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import com.jfreeman.lazy.LateBound;
import com.jfreeman.lazy.Lazy;
/**
* @author jfreeman
*/
public class InheritedAttribute
implements Attribute
{
private final Map> _attrs = new ConcurrentHashMap<>();
private LateBound getOrCreate(N node) {
LateBound attr = _attrs.get(node);
if (attr == null) {
attr = LateBound.of();
_attrs.put(node, attr);
}
return attr;
}
/**
* {@inheritDoc}
*
* May be called before the node's value has been
* {@link #set(Object, Lazy)}.
*/
@Override
public Lazy get(N node) {
return getOrCreate(node);
}
@Override
public void set(N node, Lazy value) {
getOrCreate(node).bind(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy