本文整理汇总了Java中com.google.common.collect.ForwardingMap类的典型用法代码示例。如果您正苦于以下问题:Java ForwardingMap类的具体用法?Java ForwardingMap怎么用?Java ForwardingMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ForwardingMap类属于com.google.common.collect包,在下文中一共展示了ForwardingMap类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUserData
import com.google.common.collect.ForwardingMap; //导入依赖的package包/类
private Map<String, String> createUserData(final TModule module) {
// TODO GH-230 consider disallowing serializing reconciled modules to index with fail-safe behavior:
// if (module.isPreLinkingPhase() || module.isReconciled()) {
if (module.isPreLinkingPhase()) {
return UserdataMapper.createTimestampUserData(module);
}
return new ForwardingMap<String, String>() {
private Map<String, String> delegate;
@Override
protected Map<String, String> delegate() {
if (delegate == null) {
try {
delegate = UserdataMapper.createUserData(module);
N4JSResource resource = (N4JSResource) module.eResource();
UserdataMapper.writeDependenciesToUserData(resource, delegate);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
return delegate;
}
};
}
示例2: createLazyUserData
import com.google.common.collect.ForwardingMap; //导入依赖的package包/类
protected Map<String, String> createLazyUserData(final EObject eObject) {
return new ForwardingMap<String, String>() {
private Map<String,String> delegate;
@Override
protected Map<String, String> delegate() {
if(delegate == null) {
Builder<String, String> userData = ImmutableMap.builder();
createUserData(eObject, userData);
delegate = userData.build();
}
return delegate;
}
};
}
示例3: getValues
import com.google.common.collect.ForwardingMap; //导入依赖的package包/类
public Map<String, String> getValues()
{
return new ForwardingMap<String, String>() {
@Override
protected Map<String, String> delegate()
{
return values;
}
@Override
public String remove(Object object) {
dirty();
return super.remove(object);
}
@Override
public void clear() {
dirty();
super.clear();
}
@Override
public String put(String key, String value) {
final String oldValue = super.put(key, value);
if (!Objects.equal(value, oldValue)) {
dirty();
}
return oldValue;
}
@Override
public void putAll(Map<? extends String, ? extends String> map) {
dirty();
super.putAll(map);
}
};
}
示例4: init
import com.google.common.collect.ForwardingMap; //导入依赖的package包/类
private void init(final Map<String, String> map) {
data = new ForwardingMap<String, String>() {
@Override
protected Map<String, String> delegate() {
return map;
}
@Override
public String get(final Object key) {
String ov = fixedValues.get(key);
return ov == null ? delegate().get(key) : ov;
}
@Override
public boolean containsKey(final Object key) {
return fixedValues.containsKey(key) || delegate().containsKey(key);
}
@Override
public Set<Entry<String, String>> entrySet() {
Set<String> fixedValueKeys = fixedValues.keySet();
Set<Entry<String, String>> result = Sets.newHashSet(fixedValues.entrySet());
for (Entry<String, String> entry : delegate().entrySet()) {
if (!fixedValueKeys.contains(entry.getKey())) {
result.add(entry);
}
}
return result;
}
@Override
public Set<String> keySet() {
Set<String> keys = Sets.newHashSet(fixedValues.keySet());
keys.addAll(delegate().keySet());
return keys;
}
};
}
示例5: superClassTypeArguments
import com.google.common.collect.ForwardingMap; //导入依赖的package包/类
/**
* Test super-class type argument determination.
*/
@Test
public void superClassTypeArguments()
{
final Class<MapLongString> childClass = MapLongString.class;
final List<Class<?>> typeArguments = getSuperclassTypeArguments(ForwardingMap.class,
childClass);
log.debug("Class " + childClass + " typeArguments = " + typeArguments);
assertEquals(asList(Long.class, String.class), typeArguments);
}