Java 8 IdentityHashMap - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 IdentityHashMap class.

This code example shows how to use the following methods:get, put
        // java.util.IdentityHashMap.put(java.lang.Object, java.lang.Object) 
        hm.put("KEY", "VALUE");
        assertEquals("Failed to install key/value pair",
                "VALUE", hm.get("KEY"));
 
        IdentityHashMap m = new IdentityHashMap();
        Short s0 = new Short((short) 0);
        m.put(s0, "short");
        m.put(null, "test");
        Integer i0 = new Integer(0);
        m.put(i0, "int");
        assertEquals("Failed adding to bucket containing null",
                "short", m.get(s0));
        assertEquals("Failed adding to bucket containing null2", "int", m.get(i0)
                ); 
    } 
 
    /** 
     * java.util.IdentityHashMap#putAll(java.util.Map) 
     */ 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:entrySet, put
import java.util.Map; 
 
public class EntrySetIteratorRemoveInvalidatesEntry { 
    public static void main(String[] args) throws Exception {
        final IdentityHashMap<String, String> identityHashMap =
            new IdentityHashMap<>();
 
        identityHashMap.put("One", "Un");
        identityHashMap.put("Two", "Deux");
        identityHashMap.put("Three", "Trois");
 
        Iterator<Map.Entry<String, String>> entrySetIterator =
            identityHashMap.entrySet().iterator();
        Map.Entry<String, String> entry = entrySetIterator.next();
 
        entrySetIterator.remove();
 
        try { 
            entry.getKey();
            throw new RuntimeException("Test FAILED: Entry not invalidated by removal.");
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:entrySet, put
import java.util.Map;
 
public class EntrySetIteratorRemoveInvalidatesEntry { 
    public static void main(String[] args) throws Exception {
        final IdentityHashMap<String, String> identityHashMap =
            new IdentityHashMap<>();
 
        identityHashMap.put("One", "Un");
        identityHashMap.put("Two", "Deux");
        identityHashMap.put("Three", "Trois");
 
        Iterator<Map.Entry<String, String>> entrySetIterator =
            identityHashMap.entrySet().iterator();
        Map.Entry<String, String> entry = entrySetIterator.next();
 
        entrySetIterator.remove();
 
        try { 
            entry.getKey();
            throw new RuntimeException("Test FAILED: Entry not invalidated by removal.");
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:put
 
 
    private static final Map<Class<?>, String> primitives;
 
    static { 
        Map<Class<?>, String> p = new IdentityHashMap<Class<?>, String>();
        p.put(void.class, "V");
        p.put(byte.class, "B");
        p.put(char.class, "C");
        p.put(double.class, "D");
        p.put(float.class, "F");
        p.put(int.class, "I");
        p.put(long.class, "J");
        p.put(short.class, "S");
        p.put(boolean.class, "Z");
        primitives = Collections.unmodifiableMap(p);
    } 
 
    /** 
     * Changes a class name to the internal form suitable for use in a descriptor string. 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
        return serviceName.append(moduleName).append(beanName).append(viewClassName);
    } 
 
    public static class Builder { 
        private final String viewClassName;
        private final Map<Method, EJBMethodSecurityAttribute> methodSecurityAttributes = new IdentityHashMap<>();
 
        public Builder(final String viewClassName) {
            this.viewClassName = viewClassName;
        } 
 
        public void addMethodSecurityMetadata(final Method viewMethod, final EJBMethodSecurityAttribute securityAttribute) {
            methodSecurityAttributes.put(viewMethod, securityAttribute);
        } 
 
        public EJBViewMethodSecurityAttributesService build() { 
            return new EJBViewMethodSecurityAttributesService(viewClassName, methodSecurityAttributes);
        } 
    } 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:entrySet, put
import java.util.Set; 
 
public class DistinctEntrySetElements { 
    public static void main(String[] args) throws Exception {
        final IdentityHashMap<String, String> identityHashMap =
            new IdentityHashMap<>();
 
        identityHashMap.put("One", "Un");
        identityHashMap.put("Two", "Deux");
        identityHashMap.put("Three", "Trois");
 
        Set<Map.Entry<String, String>> entrySet = identityHashMap.entrySet();
        HashSet<Map.Entry<String, String>> hashSet = new HashSet<>(entrySet);
 
        // NB: These comparisons are valid in this case because none of the 
        //     keys put into 'identityHashMap' above are equal to any other. 
        if (false == hashSet.equals(entrySet)) {
            throw new RuntimeException("Test FAILED: Sets are not equal.");
        } 
        if (hashSet.hashCode() != entrySet.hashCode()) {
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:entrySet, put
import java.util.Set;
 
public class DistinctEntrySetElements { 
    public static void main(String[] args) throws Exception {
        final IdentityHashMap<String, String> identityHashMap =
            new IdentityHashMap<>();
 
        identityHashMap.put("One", "Un");
        identityHashMap.put("Two", "Deux");
        identityHashMap.put("Three", "Trois");
 
        Set<Map.Entry<String, String>> entrySet = identityHashMap.entrySet();
        HashSet<Map.Entry<String, String>> hashSet = new HashSet<>(entrySet);
 
        // NB: These comparisons are valid in this case because none of the 
        //     keys put into 'identityHashMap' above are equal to any other. 
        if (false == hashSet.equals(entrySet)) {
            throw new RuntimeException("Test FAILED: Sets are not equal.");
        } 
        if (hashSet.hashCode() != entrySet.hashCode()) {
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:containsKey
    public boolean add( T t ){
        return _map.put( t , "a" ) == null;
    } 
 
    public boolean contains( T t ){
        return _map.containsKey( t );
    } 
 
    public void remove( T t ){
        _map.remove( t );
    } 
 
    public void removeall( Iterable<T> coll ){
        for ( T t : coll )
            _map.remove( t );
    } 
 
    public void clear(){ 
	_map.clear();
    } 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
import java.util.Map; 
 
import org.junit.Assert; 
 
public class DestroyCountCache extends SortedMapBackedCache { 
  static Map<DIHCache,DIHCache> destroyed = new IdentityHashMap<>(); 
   
  @Override 
  public void destroy() { 
    super.destroy(); 
    Assert.assertThat(destroyed.put(this, this), nullValue()); 
  } 
   
  public DestroyCountCache() {} 
   
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:containsKey, put
      final IdentityHashMap<Object, Serializable> alreadyDecomposed) {
    if (object == null) {
      return null; 
    } 
     
    if (alreadyDecomposed.containsKey(object)) {
      return alreadyDecomposed.get(object);
    } 
    else { 
      final Serializable mutableContainer = createMutableContainer(object);
      alreadyDecomposed.put(object, mutableContainer);
      decomposeInto(object, mutableContainer, alreadyDecomposed);
      return mutableContainer;
    } 
  } 
   
  abstract Serializable createMutableContainer(Object o);
   
  abstract void decomposeInto(Object o, Serializable container,
      IdentityHashMap<Object, Serializable> alreadyDecomposed);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 IdentityHashMap Methods: