Example usage for java.util WeakHashMap put

List of usage examples for java.util WeakHashMap put

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this 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> weakHashMap = new WeakHashMap<String, String>();

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

    // checking Map
    System.out.println("Map: " + weakHashMap);

    // putting value at key 2
    String str = (String) weakHashMap.put("2", "newvalue");
    System.out.println("Returned value: " + str);
    System.out.println("New Map: " + weakHashMap);
}

From source file:Main.java

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

    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> weakHashMapOne = new WeakHashMap<String, String>();
    WeakHashMap<String, String> weakHashMapTwo = new WeakHashMap<String, String>();

    System.out.println("Populating two Maps");

    weakHashMapOne.put("1", "first");
    weakHashMapOne.put("2", "two");
    weakHashMapOne.put("3", "from java2s.com");

    weakHashMapTwo.put("1", "1st");
    weakHashMapTwo.put("2", "2nd");
    weakHashMapTwo.put("3", "3rd");

    // checking Map
    System.out.println("Before - Map 1: " + weakHashMapOne);
    System.out.println("Before - Map 2: " + weakHashMapTwo);

    // putting map 2 into map1
    weakHashMapOne.putAll(weakHashMapTwo);

    System.out.println("After - Map 1: " + weakHashMapOne);
    System.out.println("After - Map 2: " + weakHashMapTwo);
}

From source file:Main.java

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

    // check map contents
    System.out.println("Checking the map entries");
    System.out.println("Map is empty: " + weakHashMap.isEmpty());

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

    // checking Map
    System.out.println("Map is empty: " + weakHashMap.isEmpty());
}

From source file:MethodHashing.java

public static long calculateHash(Method method) {
    Map methodHashes = (Map) hashMap.get(method.getDeclaringClass());

    if (methodHashes == null) {
        methodHashes = getInterfaceHashes(method.getDeclaringClass());

        // Copy and add
        WeakHashMap newHashMap = new WeakHashMap();
        newHashMap.putAll(hashMap);//from   w  ww  .j a  v  a  2  s.  c  o  m
        newHashMap.put(method.getDeclaringClass(), methodHashes);
        hashMap = newHashMap;
    }

    return ((Long) methodHashes.get(method.toString())).longValue();
}

From source file:com.qmetry.qaf.automation.util.StringUtil.java

/**
 * @param csvKeyVal/*from  w  ww. j  a  v a  2 s . c om*/
 *            array of key=value pair.
 * @param ensureKeyUppercase
 *            : if true then it will set upper-case key for value
 * @return map
 */
public static Map<String, String> toMap(String[] csvKeyVal, boolean ensureKeyUppercase) {
    WeakHashMap<String, String> map = new WeakHashMap<String, String>();
    if (null == csvKeyVal) {
        return map;
    }
    for (String param : csvKeyVal) {
        if (isNotBlank(param)) {
            String[] kv = param.split("=");
            map.put(ensureKeyUppercase ? kv[0].toUpperCase() : kv[0], kv.length > 1 ? (kv[1]) : "");
        }
    }
    return map;
}

From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java

private void addQueue(String url, ImageView iv) {
    WeakHashMap<ImageView, BitmapAjaxCallback> ivs = queueMap.get(url);
    if (ivs == null) {
        if (queueMap.containsKey(url)) {
            //already a image view fetching
            ivs = new WeakHashMap<ImageView, BitmapAjaxCallback>();
            ivs.put(iv, this);
            queueMap.put(url, ivs);/*from   w  w  w  . j  a v  a  2 s  . c  o  m*/
        } else {
            //register a view by putting a url with no value
            queueMap.put(url, null);
        }
    } else {
        //add to list of image views
        ivs.put(iv, this);
    }
}

From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java

private void addQueue(String url, ImageView iv) {

    WeakHashMap<ImageView, BitmapAjaxCallback> ivs = queueMap.get(url);

    if (ivs == null) {

        if (queueMap.containsKey(url)) {
            //already a image view fetching
            ivs = new WeakHashMap<ImageView, BitmapAjaxCallback>();
            ivs.put(iv, this);
            queueMap.put(url, ivs);//from   w ww . j a v  a2 s  . c  o m
        } else {
            //register a view by putting a url with no value
            queueMap.put(url, null);
        }

    } else {
        //add to list of image views
        ivs.put(iv, this);

    }

}

From source file:org.apache.axis.handlers.soap.SOAPService.java

/** 
 * Add this passed in Session to this Service's list of sessions
 *///from www.j a  v a  2 s  . c  o m
public void addSession(Session session) {
    WeakHashMap map = (WeakHashMap) sessions.get(this.getName());
    if (map == null) {
        map = new WeakHashMap();
        sessions.put(this.getName(), map);
    }
    if (!map.containsKey(session))
        map.put(session, null);
}