Search in sources :

Example 31 with AbstractMap

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());
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap)

Example 32 with AbstractMap

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());
}
Also used : AbstractMap(java.util.AbstractMap) Set(java.util.Set) IdentityHashMap(java.util.IdentityHashMap) Collection(java.util.Collection)

Example 33 with AbstractMap

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);
}
Also used : AbstractMap(java.util.AbstractMap) Decorator(javax.enterprise.inject.spi.Decorator) CurrentInjectionPoint(org.jboss.weld.injection.CurrentInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) EmptyInjectionPoint(org.jboss.weld.injection.EmptyInjectionPoint)

Example 34 with AbstractMap

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;
            }
        }
    };
}
Also used : AbstractMap(java.util.AbstractMap) Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 35 with AbstractMap

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;
}
Also used : AbstractMap(java.util.AbstractMap)

Aggregations

AbstractMap (java.util.AbstractMap)46 HashMap (java.util.HashMap)27 Map (java.util.Map)20 IdentityHashMap (java.util.IdentityHashMap)19 LinkedHashMap (java.util.LinkedHashMap)19 TreeMap (java.util.TreeMap)17 WeakHashMap (java.util.WeakHashMap)13 Collection (java.util.Collection)8 Set (java.util.Set)7 InputStream (java.io.InputStream)4 SequenceInputStream (java.io.SequenceInputStream)3 Comparator (java.util.Comparator)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ReadResult (io.pravega.segmentstore.contracts.ReadResult)2 IOException (java.io.IOException)2 Cleanup (lombok.Cleanup)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 IndexSettings (org.elasticsearch.index.IndexSettings)2