use of java.util.IdentityHashMap in project robovm by robovm.
the class AbstractMapTest method test_removeLjava_lang_Object.
/**
* 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 map7 = new WeakHashMap();
map7.put(key, value);
assertSame("WeakHashMap", map7.remove(key), value);
AbstractMap aSpecialMap = new MyMap();
aSpecialMap.put(specialKey, specialValue);
Object valueOut = aSpecialMap.remove(specialKey);
assertSame("MyMap", valueOut, specialValue);
}
use of java.util.IdentityHashMap in project robovm by robovm.
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());
}
use of java.util.IdentityHashMap in project fastjson by alibaba.
the class ConcurrentHashMapDeserializerTest method test_className2.
@SuppressWarnings("rawtypes")
public void test_className2() throws Exception {
IdentityHashMap map = (IdentityHashMap) JSON.parse("{\"@type\":\"java.util.IdentityHashMap\", \"id\":123}");
Assert.assertEquals(1, map.size());
}
use of java.util.IdentityHashMap in project dubbo by alibaba.
the class JavaBeanSerializeUtil method serializeInternal.
private static void serializeInternal(JavaBeanDescriptor descriptor, Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) {
if (obj == null || descriptor == null) {
return;
}
if (obj.getClass().isEnum()) {
descriptor.setEnumNameProperty(((Enum<?>) obj).name());
} else if (ReflectUtils.isPrimitive(obj.getClass())) {
descriptor.setPrimitiveProperty(obj);
} else if (Class.class.equals(obj.getClass())) {
descriptor.setClassNameProperty(((Class<?>) obj).getName());
} else if (obj.getClass().isArray()) {
int len = Array.getLength(obj);
for (int i = 0; i < len; i++) {
Object item = Array.get(obj, i);
if (item == null) {
descriptor.setProperty(i, null);
} else {
JavaBeanDescriptor itemDescriptor = createDescriptorIfAbsent(item, accessor, cache);
descriptor.setProperty(i, itemDescriptor);
}
}
} else if (obj instanceof Collection) {
Collection collection = (Collection) obj;
int index = 0;
for (Object item : collection) {
if (item == null) {
descriptor.setProperty(index++, null);
} else {
JavaBeanDescriptor itemDescriptor = createDescriptorIfAbsent(item, accessor, cache);
descriptor.setProperty(index++, itemDescriptor);
}
}
} else if (obj instanceof Map) {
Map map = (Map) obj;
for (Object key : map.keySet()) {
Object value = map.get(key);
Object keyDescriptor = key == null ? null : createDescriptorIfAbsent(key, accessor, cache);
Object valueDescriptor = value == null ? null : createDescriptorIfAbsent(value, accessor, cache);
descriptor.setProperty(keyDescriptor, valueDescriptor);
}
// ~ end of loop map
} else {
if (JavaBeanAccessor.isAccessByMethod(accessor)) {
Map<String, Method> methods = ReflectUtils.getBeanPropertyReadMethods(obj.getClass());
for (Map.Entry<String, Method> entry : methods.entrySet()) {
try {
Object value = entry.getValue().invoke(obj);
if (value == null) {
continue;
}
JavaBeanDescriptor valueDescriptor = createDescriptorIfAbsent(value, accessor, cache);
descriptor.setProperty(entry.getKey(), valueDescriptor);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
// ~ end of loop method map
}
if (JavaBeanAccessor.isAccessByField(accessor)) {
Map<String, Field> fields = ReflectUtils.getBeanPropertyFields(obj.getClass());
for (Map.Entry<String, Field> entry : fields.entrySet()) {
if (!descriptor.containsProperty(entry.getKey())) {
try {
Object value = entry.getValue().get(obj);
if (value == null) {
continue;
}
JavaBeanDescriptor valueDescriptor = createDescriptorIfAbsent(value, accessor, cache);
descriptor.setProperty(entry.getKey(), valueDescriptor);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
// ~ end of loop field map
}
// ~ end of if (JavaBeanAccessor.isAccessByField(accessor))
}
// ~ end of else
}
use of java.util.IdentityHashMap in project lombok by rzwitserloot.
the class Delombok method delombok.
public boolean delombok() throws IOException {
LombokOptions options = LombokOptionsFactory.getDelombokOptions(context);
options.deleteLombokAnnotations();
options.putJavacOption("ENCODING", charset.name());
if (classpath != null)
options.putJavacOption("CLASSPATH", classpath);
if (sourcepath != null)
options.putJavacOption("SOURCEPATH", sourcepath);
if (bootclasspath != null)
options.putJavacOption("BOOTCLASSPATH", bootclasspath);
options.setFormatPreferences(new FormatPreferences(formatPrefs));
options.put("compilePolicy", "check");
CommentCatcher catcher = CommentCatcher.create(context);
JavaCompiler compiler = catcher.getCompiler();
List<JCCompilationUnit> roots = new ArrayList<JCCompilationUnit>();
Map<JCCompilationUnit, File> baseMap = new IdentityHashMap<JCCompilationUnit, File>();
compiler.initProcessAnnotations(Collections.singleton(new lombok.javac.apt.LombokProcessor()));
for (File fileToParse : filesToParse) {
@SuppressWarnings("deprecation") JCCompilationUnit unit = compiler.parse(fileToParse.getAbsolutePath());
baseMap.put(unit, fileToBase.get(fileToParse));
roots.add(unit);
}
if (compiler.errorCount() > 0) {
// At least one parse error. No point continuing (a real javac run doesn't either).
return false;
}
for (JCCompilationUnit unit : roots) {
catcher.setComments(unit, new DocCommentIntegrator().integrate(catcher.getComments(unit), unit));
}
com.sun.tools.javac.util.List<JCCompilationUnit> trees = compiler.enterTrees(toJavacList(roots));
JavaCompiler delegate = compiler.processAnnotations(trees);
Object care = callAttributeMethodOnJavaCompiler(delegate, delegate.todo);
callFlowMethodOnJavaCompiler(delegate, care);
FormatPreferences fps = new FormatPreferences(formatPrefs);
for (JCCompilationUnit unit : roots) {
DelombokResult result = new DelombokResult(catcher.getComments(unit), unit, force || options.isChanged(unit), fps);
if (verbose)
feedback.printf("File: %s [%s%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged", force && !options.isChanged(unit) ? " (forced)" : "");
Writer rawWriter;
if (presetWriter != null)
rawWriter = createUnicodeEscapeWriter(presetWriter);
else if (output == null)
rawWriter = createStandardOutWriter();
else
rawWriter = createFileWriter(output, baseMap.get(unit), unit.sourcefile.toUri());
BufferedWriter writer = new BufferedWriter(rawWriter);
try {
result.print(writer);
} finally {
if (output != null) {
writer.close();
} else {
writer.flush();
}
}
}
delegate.close();
return true;
}
Aggregations