use of java.util.AbstractMap in project robovm by robovm.
the class AbstractMapTest method test_clone.
/**
* java.util.AbstractMap#clone()
*/
public void test_clone() {
class MyMap extends AbstractMap implements Cloneable {
private Map map = new HashMap();
public Set entrySet() {
return map.entrySet();
}
public Object put(Object key, Object value) {
return map.put(key, value);
}
public Map getMap() {
return map;
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// android-changed
throw new AssertionError(e);
}
}
}
;
MyMap map = new MyMap();
map.put("one", "1");
Map.Entry entry = (Map.Entry) map.entrySet().iterator().next();
assertTrue("entry not added", entry.getKey() == "one" && entry.getValue() == "1");
MyMap mapClone = (MyMap) map.clone();
assertTrue("clone not shallow", map.getMap() == mapClone.getMap());
}
use of java.util.AbstractMap in project robovm by robovm.
the class IdentityHashMapTest method test_clone.
/**
* java.util.IdentityHashMap#clone()
*/
public void test_clone() {
// Test for method java.lang.Object java.util.IdentityHashMap.clone()
IdentityHashMap hm2 = (IdentityHashMap) hm.clone();
assertTrue("Clone answered equivalent IdentityHashMap", hm2 != hm);
for (int counter = 0; counter < hmSize; counter++) assertTrue("Clone answered unequal IdentityHashMap", hm.get(objArray2[counter]) == hm2.get(objArray2[counter]));
IdentityHashMap map = new IdentityHashMap();
map.put("key", "value");
// get the keySet() and values() on the original Map
Set keys = map.keySet();
Collection values = map.values();
assertEquals("values() does not work", "value", values.iterator().next());
assertEquals("keySet() does not work", "key", keys.iterator().next());
AbstractMap map2 = (AbstractMap) map.clone();
map2.put("key", "value2");
Collection values2 = map2.values();
assertTrue("values() is identical", values2 != values);
// values() and keySet() on the cloned() map should be different
assertEquals("values() was not cloned", "value2", values2.iterator().next());
map2.clear();
map2.put("key2", "value3");
Set key2 = map2.keySet();
assertTrue("keySet() is identical", key2 != keys);
assertEquals("keySet() was not cloned", "key2", key2.iterator().next());
}
use of java.util.AbstractMap in project aries by apache.
the class ConfigurationBean method create0.
protected <T> T create0(CreationalContext<T> creationalContext) {
Map<String, Object> map = new AbstractMap<String, Object>() {
@Override
public Set<java.util.Map.Entry<String, Object>> entrySet() {
return _configurationDependency.getConfiguration().entrySet();
}
};
T instance = cast(Conversions.c().convert(map).to(_configurationDependency.getBeanClass()));
InjectionPoint ip = getInjectionPoint(_currentInjectionPoint);
if (ip == null) {
return instance;
}
List<Decorator<?>> decorators = getDecorators(ip);
if (decorators.isEmpty()) {
return instance;
}
return Decorators.getOuterDelegate(cast(this), instance, creationalContext, cast(getBeanClass()), ip, _beanManagerImpl, decorators);
}
use of java.util.AbstractMap in project com.revolsys.open by revolsys.
the class JexlHttpServletRequestContext method getVars.
@Override
public Map getVars() {
return new AbstractMap() {
@Override
public Set entrySet() {
final Map map = new HashMap();
map.putAll(JexlHttpServletRequestContext.this.request.getParameterMap());
for (final Enumeration names = JexlHttpServletRequestContext.this.request.getAttributeNames(); names.hasMoreElements(); ) {
final String name = (String) names.nextElement();
map.put(name, JexlHttpServletRequestContext.this.request.getAttribute(name));
}
if (JexlHttpServletRequestContext.this.servletContext != null) {
for (final Enumeration names = JexlHttpServletRequestContext.this.servletContext.getAttributeNames(); names.hasMoreElements(); ) {
final String name = (String) names.nextElement();
map.put(name, JexlHttpServletRequestContext.this.servletContext.getAttribute(name));
}
}
return map.entrySet();
}
@Override
public Object get(final Object key) {
if (key.equals("request")) {
return JexlHttpServletRequestContext.this.request;
} else if (key.equals("requestURI")) {
return JexlHttpServletRequestContext.this.urlPathHelper.getOriginatingRequestUri(JexlHttpServletRequestContext.this.request);
}
final String keyString = key.toString();
Object value = null;
if (JexlHttpServletRequestContext.this.servletContext != null) {
value = JexlHttpServletRequestContext.this.servletContext.getAttribute(keyString);
}
if (value == null) {
value = JexlHttpServletRequestContext.this.request.getAttribute(keyString);
if (value == null) {
value = JexlHttpServletRequestContext.this.request.getParameter(keyString);
}
}
if (value == null) {
return "";
} else {
return value;
}
}
};
}
use of java.util.AbstractMap in project sonar-java by SonarSource.
the class WithAnonymousClass method mainMethod1.
public void mainMethod1() {
AbstractMap anonymousMap = new AbstractMap() {
public Set entrySet() {
return null;
}
};
anonymousMap.entrySet();
anonymousMap = null;
}
Aggregations