Search in sources :

Example 41 with AbstractMap

use of java.util.AbstractMap in project j2objc by google.

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) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) IdentityHashMap(java.util.IdentityHashMap) Collection(java.util.Collection)

Example 42 with AbstractMap

use of java.util.AbstractMap in project j2objc by google.

the class TreeMapTest method test_clone.

/**
 * java.util.TreeMap#clone()
 */
public void test_clone() {
    // Test for method java.lang.Object java.util.TreeMap.clone()
    TreeMap clonedMap = (TreeMap) tm.clone();
    assertTrue("Cloned map does not equal the original map", clonedMap.equals(tm));
    assertTrue("Cloned map is the same reference as the original map", clonedMap != tm);
    for (Object element : objArray) {
        assertTrue("Cloned map contains incorrect elements", clonedMap.get(element.toString()) == tm.get(element.toString()));
    }
    TreeMap map = new TreeMap();
    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) NavigableSet(java.util.NavigableSet) HashSet(java.util.HashSet) Collection(java.util.Collection) TreeMap(java.util.TreeMap)

Example 43 with AbstractMap

use of java.util.AbstractMap in project j2objc by google.

the class HashMapTest method test_clone.

/**
 * java.util.HashMap#clone()
 */
public void test_clone() {
    // Test for method java.lang.Object java.util.HashMap.clone()
    HashMap hm2 = (HashMap) hm.clone();
    assertTrue("Clone answered equivalent HashMap", hm2 != hm);
    for (int counter = 0; counter < hmSize; counter++) assertTrue("Clone answered unequal HashMap", hm.get(objArray2[counter]) == hm2.get(objArray2[counter]));
    HashMap map = new HashMap();
    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());
    // regresion test for HARMONY-4603
    HashMap hashmap = new HashMap();
    MockClonable mock = new MockClonable(1);
    hashmap.put(1, mock);
    assertEquals(1, ((MockClonable) hashmap.get(1)).i);
    HashMap hm3 = (HashMap) hashmap.clone();
    assertEquals(1, ((MockClonable) hm3.get(1)).i);
    mock.i = 0;
    assertEquals(0, ((MockClonable) hashmap.get(1)).i);
    assertEquals(0, ((MockClonable) hm3.get(1)).i);
}
Also used : AbstractMap(java.util.AbstractMap) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Collection(java.util.Collection)

Example 44 with AbstractMap

use of java.util.AbstractMap in project rest.li by linkedin.

the class TestRestUtils method testValidateRequestHeadersForInProcessRequest.

@Test()
public void testValidateRequestHeadersForInProcessRequest() throws Exception {
    Map<String, String> headers = new AbstractMap<String, String>() {

        @Override
        public Set<Entry<String, String>> entrySet() {
            throw new IllegalStateException("Didn't expect headers to be accessed.");
        }
    };
    RequestContext requestContext = new RequestContext();
    requestContext.putLocalAttr(ServerResourceContext.CONTEXT_IN_PROCESS_RESOLUTION_KEY, true);
    ServerResourceContext resourceContext = new ResourceContextImpl();
    RestUtils.validateRequestHeadersAndUpdateResourceContext(headers, Collections.emptySet(), resourceContext, requestContext);
    Assert.assertEquals(resourceContext.getResponseMimeType(), ContentType.JSON.getHeaderKey());
}
Also used : AbstractMap(java.util.AbstractMap) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 45 with AbstractMap

use of java.util.AbstractMap in project crate by crate.

the class MetadataIndexUpgradeService method checkMappingsCompatibility.

/**
 * Checks the mappings for compatibility with the current version
 */
private void checkMappingsCompatibility(IndexMetadata indexMetadata) {
    try {
        // We cannot instantiate real analysis server or similarity service at this point because the node
        // might not have been started yet. However, we don't really need real analyzers or similarities at
        // this stage - so we can fake it using constant maps accepting every key.
        // This is ok because all used similarities and analyzers for this index were known before the upgrade.
        // Missing analyzers and similarities plugin will still trigger the appropriate error during the
        // actual upgrade.
        IndexSettings indexSettings = new IndexSettings(indexMetadata, this.settings);
        final NamedAnalyzer fakeDefault = new NamedAnalyzer("fake_default", AnalyzerScope.INDEX, new Analyzer() {

            @Override
            protected TokenStreamComponents createComponents(String fieldName) {
                throw new UnsupportedOperationException("shouldn't be here");
            }
        });
        final Map<String, NamedAnalyzer> analyzerMap = new AbstractMap<String, NamedAnalyzer>() {

            @Override
            public NamedAnalyzer get(Object key) {
                assert key instanceof String : "key must be a string but was: " + key.getClass();
                return new NamedAnalyzer((String) key, AnalyzerScope.INDEX, fakeDefault.analyzer());
            }

            // this entrySet impl isn't fully correct but necessary as IndexAnalyzers will iterate
            // over all analyzers to close them
            @Override
            public Set<Entry<String, NamedAnalyzer>> entrySet() {
                return Collections.emptySet();
            }
        };
        try (IndexAnalyzers fakeIndexAnalzyers = new IndexAnalyzers(indexSettings, fakeDefault, fakeDefault, fakeDefault, analyzerMap, analyzerMap, analyzerMap)) {
            MapperService mapperService = new MapperService(indexSettings, fakeIndexAnalzyers, xContentRegistry, mapperRegistry, () -> null);
            mapperService.merge(indexMetadata, MapperService.MergeReason.MAPPING_RECOVERY);
        }
    } catch (Exception ex) {
        // Wrap the inner exception so we have the index name in the exception message
        throw new IllegalStateException("unable to upgrade the mappings for the index [" + indexMetadata.getIndex() + "]", ex);
    }
}
Also used : NamedAnalyzer(org.elasticsearch.index.analysis.NamedAnalyzer) IndexSettings(org.elasticsearch.index.IndexSettings) Analyzer(org.apache.lucene.analysis.Analyzer) NamedAnalyzer(org.elasticsearch.index.analysis.NamedAnalyzer) AbstractMap(java.util.AbstractMap) IndexAnalyzers(org.elasticsearch.index.analysis.IndexAnalyzers) MapperService(org.elasticsearch.index.mapper.MapperService)

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