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());
}
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());
}
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);
}
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());
}
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);
}
}
Aggregations