Search in sources :

Example 11 with AbstractMap

use of java.util.AbstractMap in project elasticsearch by elastic.

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 at this point because the node might not have
        // been started yet. However, we don't really need real analyzers at this stage - so we can fake it
        IndexSettings indexSettings = new IndexSettings(indexMetaData, this.settings);
        SimilarityService similarityService = new SimilarityService(indexSettings, Collections.emptyMap());
        final NamedAnalyzer fakeDefault = new NamedAnalyzer("fake_default", AnalyzerScope.INDEX, new Analyzer() {

            @Override
            protected TokenStreamComponents createComponents(String fieldName) {
                throw new UnsupportedOperationException("shouldn't be here");
            }
        });
        // this is just a fake map that always returns the same value for any possible string key
        // also the entrySet impl isn't fully correct but we implement it since internally
        // IndexAnalyzers will iterate over all analyzers to close them.
        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());
            }

            @Override
            public Set<Entry<String, NamedAnalyzer>> entrySet() {
                return Collections.emptySet();
            }
        };
        try (IndexAnalyzers fakeIndexAnalzyers = new IndexAnalyzers(indexSettings, fakeDefault, fakeDefault, fakeDefault, analyzerMap, analyzerMap)) {
            MapperService mapperService = new MapperService(indexSettings, fakeIndexAnalzyers, xContentRegistry, similarityService, mapperRegistry, () -> null);
            mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY, false);
        }
    } 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) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) IndexAnalyzers(org.elasticsearch.index.analysis.IndexAnalyzers) MapperService(org.elasticsearch.index.mapper.MapperService)

Example 12 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) HashMap(java.util.HashMap) Collection(java.util.Collection)

Example 13 with AbstractMap

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

the class AbstractMapTest method test_keySet.

/**
     * java.util.AbstractMap#keySet()
     */
public void test_keySet() {
    AbstractMap map1 = new HashMap(0);
    assertSame("HashMap(0)", map1.keySet(), map1.keySet());
    AbstractMap map2 = new HashMap(10);
    assertSame("HashMap(10)", map2.keySet(), map2.keySet());
    Map map3 = Collections.EMPTY_MAP;
    assertSame("EMPTY_MAP", map3.keySet(), map3.keySet());
    AbstractMap map4 = new IdentityHashMap(1);
    assertSame("IdentityHashMap", map4.keySet(), map4.keySet());
    AbstractMap map5 = new LinkedHashMap(122);
    assertSame("LinkedHashMap", map5.keySet(), map5.keySet());
    AbstractMap map6 = new TreeMap();
    assertSame("TreeMap", map6.keySet(), map6.keySet());
    AbstractMap map7 = new WeakHashMap();
    assertSame("WeakHashMap", map7.keySet(), map7.keySet());
}
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) TreeMap(java.util.TreeMap) 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) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap)

Example 14 with AbstractMap

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

the class AbstractMapTest method test_removeLjava_lang_Object.

/**
     * @tests java.util.AbstractMap#remove(java.lang.Object)
     */
public void test_removeLjava_lang_Object() {
    Object key = new Object();
    Object value = new Object();
    AbstractMap map1 = new HashMap(0);
    map1.put("key", value);
    assertSame("HashMap(0)", map1.remove("key"), value);
    AbstractMap map4 = new IdentityHashMap(1);
    map4.put(key, value);
    assertSame("IdentityHashMap", map4.remove(key), value);
    AbstractMap map5 = new LinkedHashMap(122);
    map5.put(key, value);
    assertSame("LinkedHashMap", map5.remove(key), value);
    AbstractMap map6 = new TreeMap(new Comparator() {

        // Bogus comparator
        public int compare(Object object1, Object object2) {
            return 0;
        }
    });
    map6.put(key, value);
    assertSame("TreeMap", map6.remove(key), value);
    AbstractMap aSpecialMap = new MyMap();
    aSpecialMap.put(specialKey, specialValue);
    Object valueOut = aSpecialMap.remove(specialKey);
    assertSame("MyMap", valueOut, specialValue);
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) Comparator(java.util.Comparator)

Example 15 with AbstractMap

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

the class AbstractMapTest method test_clear.

/**
     * @tests java.util.AbstractMap#clear()
     */
public void test_clear() {
    // normal clear()
    AbstractMap map = new HashMap();
    map.put(1, 1);
    map.clear();
    assertTrue(map.isEmpty());
    // Special entrySet return a Set with no clear method.
    AbstractMap myMap = new MocAbstractMap();
    try {
        myMap.clear();
        fail("Should throw UnsupportedOprationException");
    } catch (UnsupportedOperationException e) {
    // expected
    }
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

AbstractMap (java.util.AbstractMap)23 LinkedHashMap (java.util.LinkedHashMap)14 HashMap (java.util.HashMap)13 IdentityHashMap (java.util.IdentityHashMap)13 TreeMap (java.util.TreeMap)12 Map (java.util.Map)8 WeakHashMap (java.util.WeakHashMap)8 Collection (java.util.Collection)5 Set (java.util.Set)5 Comparator (java.util.Comparator)3 Decorator (javax.enterprise.inject.spi.Decorator)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 IndexSettings (org.elasticsearch.index.IndexSettings)1 IndexAnalyzers (org.elasticsearch.index.analysis.IndexAnalyzers)1 NamedAnalyzer (org.elasticsearch.index.analysis.NamedAnalyzer)1 MapperService (org.elasticsearch.index.mapper.MapperService)1 SimilarityService (org.elasticsearch.index.similarity.SimilarityService)1 CurrentInjectionPoint (org.jboss.weld.injection.CurrentInjectionPoint)1 EmptyInjectionPoint (org.jboss.weld.injection.EmptyInjectionPoint)1