/** * * @return the previous value associated with the specified key, or <tt>null</tt> if there was no * mapping for the key * @throws NullPointerException if the specified key or value is null */ public V replace(int key, V value) { if (value == null) throw new NullPointerException(); int hash = hash(key); return segmentFor(hash).replace(key, hash, value); }
/** * * @return the previous value associated with the specified key, or <tt>null</tt> if there was no * mapping for the key * @throws NullPointerException if the specified key or value is null */ public V putIfAbsent(int key, V value) { if (value == null) throw new NullPointerException(); int hash = hash(key); return segmentFor(hash).put(key, hash, value, true); }
/** * * @throws NullPointerException if any of the arguments are null */ public boolean replace(int key, V oldValue, V newValue) { if (oldValue == null || newValue == null) throw new NullPointerException(); int hash = hash(key); return segmentFor(hash).replace(key, hash, oldValue, newValue); }
/** * Tests if the specified object is a key in this table. * * @param key possible key * @return <tt>true</tt> if and only if the specified object is a key in this table, as determined * by the <tt>equals</tt> method; <tt>false</tt> otherwise. * @throws NullPointerException if the specified key is null */ public boolean containsKey(int key) { int hash = hash(key); return segmentFor(hash).containsKey(key, hash); }
/** * * @throws NullPointerException if the specified key is null */ public boolean remove(int key, Object value) { int hash = hash(key); if (value == null) return false; return segmentFor(hash).remove(key, hash, value) != null; }
/** * Removes the key (and its corresponding value) from this map. This method does nothing if the * key is not in the map. * * @param key the key that needs to be removed * @return the previous value associated with <tt>key</tt>, or <tt>null</tt> if there was no * mapping for <tt>key</tt> * @throws NullPointerException if the specified key is null */ public V remove(int key) { int hash = hash(key); return segmentFor(hash).remove(key, hash, null); }
/** * Returns the value to which the specified key is mapped, or {@code null} if this map contains no * mapping for the key. * * <p> * More formally, if this map contains a mapping from a key {@code k} to a value {@code v} such * that {@code key.equals(k)}, then this method returns {@code v}; otherwise it returns * {@code null}. (There can be at most one such mapping.) * * @throws NullPointerException if the specified key is null */ public V get(int key) { int hash = hash(key); return segmentFor(hash).get(key, hash); }
/** * Maps the specified key to the specified value in this table. Neither the key nor the value can * be null. * * <p> * The value can be retrieved by calling the <tt>get</tt> method with a key that is equal to the * original key. * * @param key key with which the specified value is to be associated * @param value value to be associated with the specified key * @return the previous value associated with <tt>key</tt>, or <tt>null</tt> if there was no * mapping for <tt>key</tt> * @throws NullPointerException if the specified key or value is null */ public V put(int key, V value) { if (value == null) throw new NullPointerException(); int hash = hash(key); return segmentFor(hash).put(key, hash, value, false); }