All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gwt.emul.java.util.concurrent.BaseConcurrentHashMap Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The newest version!
package java.util.concurrent;

import java.util.*;
import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;

/**
 * Implementation of Map interface based on a hash table. [Sun
 * docs]
 * 
 * @param 
 *          key type
 * @param 
 *          value type
 */
public class BaseConcurrentHashMap extends AbstractHashMap
    implements Cloneable, Serializable, Map, ConcurrentMap {

  /**
   * Ensures that RPC will consider type parameter K to be exposed. It will be
   * pruned by dead code elimination.
   */
  @SuppressWarnings("unused")
  private K exposeKey;

  /**
   * Ensures that RPC will consider type parameter V to be exposed. It will be
   * pruned by dead code elimination.
   */
  @SuppressWarnings("unused")
  private V exposeValue;

  public BaseConcurrentHashMap() {
  }

  public BaseConcurrentHashMap(int ignored) {
    super(ignored);
  }

  public BaseConcurrentHashMap(int ignored, float alsoIgnored) {
    super(ignored, alsoIgnored);
  }

  public BaseConcurrentHashMap(Map toBeCopied) {
    super(toBeCopied);
  }

  @Override
  public Object clone() {
    return new BaseConcurrentHashMap(this);
  }

  @Override
  protected native boolean equals(Object value1, Object value2)
  /*-{
    return @java.util.Objects::equals(Ljava/lang/Object;Ljava/lang/Object;)(value1, value2);
  }-*/;

  @Override
  protected int getHashCode(Object key) {
    // Coerce to int -- our classes all do this, but a user-written class might
    // not.
    return ~~key.hashCode();
  }

  /**
   * If the specified key is not already associated with a value, associate it
   * with the given value. Performs
   * 
   * 
   * if (!map.containsKey(key))
   *   return map.put(key, value);
   * else
   *   return map.get(key);
   * 
*/ public V putIfAbsent(K key, V value) { if (!containsKey(key)) return put(key, value); else return get(key); } /** * Removes the entry for a key only if currently mapped to a given value. * Performs * *
   * if (map.containsKey(key) && map.get(key).equals(value)) {
   *   map.remove(key);
   *   return true;
   * } else
   *   return false;
   * 
*/ public boolean remove(Object key, Object value) { if (containsKey(key) && get(key).equals(value)) { remove(key); return true; } else return false; } /** * Replaces the entry for a key only if currently mapped to a given value. * Performs * *
   * if (map.containsKey(key) && map.get(key).equals(oldValue)) {
   *   map.put(key, newValue);
   *   return true;
   * } else
   *   return false;
   * 
* * except that the action is performed atomically. */ public boolean replace(K key, V oldValue, V newValue) { if (containsKey(key) && get(key).equals(oldValue)) { put(key, newValue); return true; } else return false; } /** * Replaces the entry for a key only if currently mapped to some value. This * performs * *
   * if (map.containsKey(key)) {
   *   return map.put(key, value);
   * } else
   *   return null;
   * 
* * except that the action is performed atomically. */ public V replace(K key, V value) { if (containsKey(key)) { return put(key, value); } else return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy