java.util.IdentityHashMap#remove ( )源码实例Demo

下面列出了java.util.IdentityHashMap#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: j2objc   文件: IdentityHashMapTest.java
/**
 * java.util.IdentityHashMap#remove(java.lang.Object)
 * java.util.IdentityHashMap#keySet()
 */
public void test_remove() {
    IdentityHashMap map = new IdentityHashMap();
    map.put(null, null);
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.remove("key1");

    assertTrue("Did not remove key1", !map.containsKey("key1"));
    assertTrue("Did not remove the value for key1", !map
            .containsValue("value1"));

    assertTrue("Modified key2", map.get("key2") != null
            && map.get("key2") == "value2");
    assertNull("Modified null entry", map.get(null));
}
 
源代码2 项目: symja_android_library   文件: ModuleReplaceAll.java
private IdentityHashMap<ISymbol, IExpr> putSingleVariable(ISymbol symbol, IdentityHashMap<ISymbol, IExpr> variables,
		final String varAppend, boolean isFunction) {
	IExpr temp = fModuleVariables.get(symbol);
	if (isFunction) {
		if (variables == null) {
			variables = (IdentityHashMap<ISymbol, IExpr>) fModuleVariables.clone();
		}
		variables.put(symbol, F.Dummy(symbol.toString() + varAppend));
	} else if (temp != null) {
		if (variables == null) {
			variables = (IdentityHashMap<ISymbol, IExpr>) fModuleVariables.clone();
		}
		variables.remove(symbol);
		if (!temp.isPresent()) {
			variables.put(symbol, F.Dummy(symbol.toString() + varAppend));
		}
	}
	return variables;
}
 
源代码3 项目: ignite   文件: GridToStringBuilder.java
/**
 * Print value with length limitation.
 *
 * @param buf buffer to print to.
 * @param cls value class.
 * @param val value to print.
 */
private static void toString(SBLimitedLength buf, Class<?> cls, Object val) {
    if (val == null) {
        buf.a("null");

        return;
    }

    if (cls == null)
        cls = val.getClass();

    if (cls.isPrimitive()) {
        buf.a(val);

        return;
    }

    IdentityHashMap<Object, EntryReference> svdObjs = savedObjects.get();

    if (handleRecursion(buf, val, cls, svdObjs))
        return;

    svdObjs.put(val, new EntryReference(buf.length()));

    try {
        if (cls.isArray())
            addArray(buf, cls, val);
        else if (val instanceof Collection)
            addCollection(buf, (Collection) val);
        else if (val instanceof Map)
            addMap(buf, (Map<?, ?>) val);
        else
            buf.a(val);
    }
    finally {
        svdObjs.remove(val);
    }
}
 
源代码4 项目: armeria   文件: GrpcUnsafeBufferUtil.java
/**
 * Releases the {@link ByteBuf} backing the specified {@link Message}.
 */
public static void releaseBuffer(Object message, RequestContext ctx) {
    final IdentityHashMap<Object, ByteBuf> buffers = ctx.attr(BUFFERS);
    checkState(buffers != null,
               "Releasing buffer even though storeBuffer has not been called.");
    final ByteBuf removed = buffers.remove(message);
    if (removed == null) {
        throw new IllegalArgumentException("The provided message does not have a stored buffer.");
    }
    removed.release();
}
 
源代码5 项目: j2objc   文件: IdentityHashMapTest.java
/**
 * java.util.IdentityHashMap#remove(java.lang.Object)
 */
public void test_removeLjava_lang_Object() {
    // Test for method java.lang.Object
    // java.util.IdentityHashMap.remove(java.lang.Object)
    int size = hm.size();
    Integer x = ((Integer) hm.remove(objArray2[9]));
    assertTrue("Remove returned incorrect value", x.equals(new Integer(9)));
    assertNull("Failed to remove given key", hm.get(objArray2[9]));
    assertTrue("Failed to decrement size", hm.size() == (size - 1));
    assertNull("Remove of non-existent key returned non-null", hm
            .remove("LCLCLC"));

    IdentityHashMap m = new IdentityHashMap();
    m.put(null, "test");
    assertNull("Failed with same hash as null",
            m.remove(objArray[0]));
    assertEquals("Failed with null key", "test", m.remove(null));

    // Regression for HARMONY-37
    IdentityHashMap<String, String> hashMap = new IdentityHashMap<String, String>();
    hashMap.remove("absent");
    assertEquals("Assert 0: Size is incorrect", 0, hashMap.size());

    hashMap.put("key", "value");
    hashMap.remove("key");
    assertEquals("Assert 1: After removing non-null element size is incorrect", 0, hashMap.size());

    hashMap.put(null, null);
    assertEquals("Assert 2: adding literal null failed", 1, hashMap.size());
    hashMap.remove(null);
    assertEquals("Assert 3: After removing null element size is incorrect", 0, hashMap.size());
}
 
源代码6 项目: j2objc   文件: IdentityHashMapTest.java
/**
 * java.util.IdentityHashMap#containsKey(java.lang.Object)
 * java.util.IdentityHashMap#containsValue(java.lang.Object)
 * java.util.IdentityHashMap#put(java.lang.Object, java.lang.Object)
 * java.util.IdentityHashMap#get(java.lang.Object)
 */
public void test_null_Keys_and_Values() {
    // tests with null keys and values
    IdentityHashMap map = new IdentityHashMap();
    Object result;

    // null key and null value
    result = map.put(null, null);
    assertTrue("testA can not find null key", map.containsKey(null));
    assertTrue("testA can not find null value", map.containsValue(null));
    assertNull("testA can not get null value for null key",
            map.get(null));
    assertNull("testA put returned wrong value", result);

    // null value
    String value = "a value";
    result = map.put(null, value);
    assertTrue("testB can not find null key", map.containsKey(null));
    assertTrue("testB can not find a value with null key", map
            .containsValue(value));
    assertTrue("testB can not get value for null key",
            map.get(null) == value);
    assertNull("testB put returned wrong value", result);

    // a null key
    String key = "a key";
    result = map.put(key, null);
    assertTrue("testC can not find a key with null value", map
            .containsKey(key));
    assertTrue("testC can not find null value", map.containsValue(null));
    assertNull("testC can not get null value for key", map.get(key));
    assertNull("testC put returned wrong value", result);

    // another null key
    String anothervalue = "another value";
    result = map.put(null, anothervalue);
    assertTrue("testD can not find null key", map.containsKey(null));
    assertTrue("testD can not find a value with null key", map
            .containsValue(anothervalue));
    assertTrue("testD can not get value for null key",
            map.get(null) == anothervalue);
    assertTrue("testD put returned wrong value", result == value);

    // remove a null key
    result = map.remove(null);
    assertTrue("testE remove returned wrong value", result == anothervalue);
    assertTrue("testE should not find null key", !map.containsKey(null));
    assertTrue("testE should not find a value with null key", !map
            .containsValue(anothervalue));
    assertNull("testE should not get value for null key",
            map.get(null));
}