Example usage for java.util WeakHashMap WeakHashMap

List of usage examples for java.util WeakHashMap WeakHashMap

Introduction

In this page you can find the example usage for java.util WeakHashMap WeakHashMap.

Prototype

public WeakHashMap(Map<? extends K, ? extends V> m) 

Source Link

Document

Constructs a new WeakHashMap with the same mappings as the specified map.

Usage

From source file:Main.java

public static void main(String[] args) {
    WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(100);

    System.out.println("Putting values into the Map");
    weakHashMap.put("1", "first");
    weakHashMap.put("2", "two");
    weakHashMap.put("3", "from java2s.com");

    // checking the size of the Map
    System.out.println("Map values: " + weakHashMap);

    Collection col = weakHashMap.values();
    System.out.println("Collection values: " + col);
}

From source file:Main.java

public static void main(String[] args) {
    WeakHashMap<String, String> hashMap = new HashMap<String, String>();

    hashMap.put("1", "first");
    hashMap.put("2", "two");
    hashMap.put("3", "from java2s.com");
    Map<String, String> weakHashMap = new WeakHashMap<String, String>(hashMap);
}

From source file:Main.java

public static <K, V> WeakHashMap<K, V> createWeakHashMap(int initialCapacity) {
    return new WeakHashMap<K, V>(initialCapacity);
}

From source file:Main.java

public static <K, V> WeakHashMap<K, V> newWeakHashMap(final int initialCapacity) {
    return new WeakHashMap<K, V>(initialCapacity);
}

From source file:Main.java

public static <K, V> WeakHashMap<K, V> newWeakHashMap(final Map<? extends K, ? extends V> m) {
    return new WeakHashMap<K, V>(m);
}

From source file:WeakHashSet.java

public WeakHashSet(Collection c) {
    map = new WeakHashMap(Math.max((int) (c.size() / .75f) + 1, 16));
    addAll(c);
}

From source file:WeakHashSet.java

public WeakHashSet(int initialCapacity) {
    map = new WeakHashMap(initialCapacity);
}

From source file:org.springframework.util.CachingMapDecorator.java

/**
 * Create a CachingMapDecorator with initial size,
 * using an underlying synchronized Map.
 * @param weakKeys whether to use weak references for keys
 * @param size the initial cache size// w w w  .j ava  2 s.  c  om
 */
public CachingMapDecorator(boolean weakKeys, int size) {
    Map internalMap = weakKeys ? (Map) new WeakHashMap(size) : new HashMap(size);
    this.targetMap = Collections.synchronizedMap(internalMap);
}

From source file:org.getobjects.foundation.NSNotificationCenter.java

public void addObserver(Object _observer, NSSelector _sel, String _name, Object _object) {
    if (_observer == null || _sel == null)
        return;/*from   www.j av  a2 s. c o m*/

    if (_name == null && _object == null) {
        this.addOmniscientObserver(_observer, _sel);
        return;
    }

    NSNotificationObserver observer = new NSNotificationSelectorObserver(_observer, _sel);

    /* add to name list */

    if (_name != null) {
        List<NSNotificationObserver> observers = null;

        if (this.nameToObserver == null) {
            this.nameToObserver = new HashMap<String, List<NSNotificationObserver>>(4);
        } else
            observers = this.nameToObserver.get(_name);

        if (observers == null) {
            observers = new ArrayList<NSNotificationObserver>(4);
            this.nameToObserver.put(_name, observers);
        }

        observers.add(observer);
    }

    /* add to object list */

    if (_object != null) {
        List<NSNotificationObserver> observers = null;

        if (this.objectToObserver == null) {
            this.objectToObserver = new WeakHashMap<Object, List<NSNotificationObserver>>(4);
        } else
            observers = this.objectToObserver.get(_object);

        if (observers == null) {
            observers = new ArrayList<NSNotificationObserver>(4);
            this.nameToObserver.put(_name, observers);
        }

        observers.add(observer);
    }
}

From source file:WeakHashSet.java

/** 
 * Constructs a new WeakHashSet with default values passed the the backing store and
 * fills it with the given collection. Note that duplicates in the collection will
 * merely be overwritten/*from   w w w  .  j  av  a  2  s .c  o  m*/
 *
 * @see java.util.WeakHashMap#WeakHashMap(Collection)
 */
public WeakHashSet(final Collection c) {
    backingStore = new WeakHashMap(Math.max((int) (c.size() / .75f) + 1, 16));
    addAll(c);
}