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; } }; }
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; } }; }
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); } }; }
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; } }; }
/** * 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); }