1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/ConcurrentMap.java Thu Oct 03 15:40:35 2013 +0200
1.3 @@ -0,0 +1,165 @@
1.4 +/*
1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.6 + *
1.7 + * This code is free software; you can redistribute it and/or modify it
1.8 + * under the terms of the GNU General Public License version 2 only, as
1.9 + * published by the Free Software Foundation. Oracle designates this
1.10 + * particular file as subject to the "Classpath" exception as provided
1.11 + * by Oracle in the LICENSE file that accompanied this code.
1.12 + *
1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.16 + * version 2 for more details (a copy is included in the LICENSE file that
1.17 + * accompanied this code).
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License version
1.20 + * 2 along with this work; if not, write to the Free Software Foundation,
1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.22 + *
1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.24 + * or visit www.oracle.com if you need additional information or have any
1.25 + * questions.
1.26 + */
1.27 +
1.28 +/*
1.29 + * This file is available under and governed by the GNU General Public
1.30 + * License version 2 only, as published by the Free Software Foundation.
1.31 + * However, the following notice accompanied the original version of this
1.32 + * file:
1.33 + *
1.34 + * Written by Doug Lea with assistance from members of JCP JSR-166
1.35 + * Expert Group and released to the public domain, as explained at
1.36 + * http://creativecommons.org/publicdomain/zero/1.0/
1.37 + */
1.38 +
1.39 +package java.util.concurrent;
1.40 +import java.util.Map;
1.41 +
1.42 +/**
1.43 + * A {@link java.util.Map} providing additional atomic
1.44 + * <tt>putIfAbsent</tt>, <tt>remove</tt>, and <tt>replace</tt> methods.
1.45 + *
1.46 + * <p>Memory consistency effects: As with other concurrent
1.47 + * collections, actions in a thread prior to placing an object into a
1.48 + * {@code ConcurrentMap} as a key or value
1.49 + * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
1.50 + * actions subsequent to the access or removal of that object from
1.51 + * the {@code ConcurrentMap} in another thread.
1.52 + *
1.53 + * <p>This interface is a member of the
1.54 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
1.55 + * Java Collections Framework</a>.
1.56 + *
1.57 + * @since 1.5
1.58 + * @author Doug Lea
1.59 + * @param <K> the type of keys maintained by this map
1.60 + * @param <V> the type of mapped values
1.61 + */
1.62 +public interface ConcurrentMap<K, V> extends Map<K, V> {
1.63 + /**
1.64 + * If the specified key is not already associated
1.65 + * with a value, associate it with the given value.
1.66 + * This is equivalent to
1.67 + * <pre>
1.68 + * if (!map.containsKey(key))
1.69 + * return map.put(key, value);
1.70 + * else
1.71 + * return map.get(key);</pre>
1.72 + * except that the action is performed atomically.
1.73 + *
1.74 + * @param key key with which the specified value is to be associated
1.75 + * @param value value to be associated with the specified key
1.76 + * @return the previous value associated with the specified key, or
1.77 + * <tt>null</tt> if there was no mapping for the key.
1.78 + * (A <tt>null</tt> return can also indicate that the map
1.79 + * previously associated <tt>null</tt> with the key,
1.80 + * if the implementation supports null values.)
1.81 + * @throws UnsupportedOperationException if the <tt>put</tt> operation
1.82 + * is not supported by this map
1.83 + * @throws ClassCastException if the class of the specified key or value
1.84 + * prevents it from being stored in this map
1.85 + * @throws NullPointerException if the specified key or value is null,
1.86 + * and this map does not permit null keys or values
1.87 + * @throws IllegalArgumentException if some property of the specified key
1.88 + * or value prevents it from being stored in this map
1.89 + *
1.90 + */
1.91 + V putIfAbsent(K key, V value);
1.92 +
1.93 + /**
1.94 + * Removes the entry for a key only if currently mapped to a given value.
1.95 + * This is equivalent to
1.96 + * <pre>
1.97 + * if (map.containsKey(key) && map.get(key).equals(value)) {
1.98 + * map.remove(key);
1.99 + * return true;
1.100 + * } else return false;</pre>
1.101 + * except that the action is performed atomically.
1.102 + *
1.103 + * @param key key with which the specified value is associated
1.104 + * @param value value expected to be associated with the specified key
1.105 + * @return <tt>true</tt> if the value was removed
1.106 + * @throws UnsupportedOperationException if the <tt>remove</tt> operation
1.107 + * is not supported by this map
1.108 + * @throws ClassCastException if the key or value is of an inappropriate
1.109 + * type for this map
1.110 + * (<a href="../Collection.html#optional-restrictions">optional</a>)
1.111 + * @throws NullPointerException if the specified key or value is null,
1.112 + * and this map does not permit null keys or values
1.113 + * (<a href="../Collection.html#optional-restrictions">optional</a>)
1.114 + */
1.115 + boolean remove(Object key, Object value);
1.116 +
1.117 + /**
1.118 + * Replaces the entry for a key only if currently mapped to a given value.
1.119 + * This is equivalent to
1.120 + * <pre>
1.121 + * if (map.containsKey(key) && map.get(key).equals(oldValue)) {
1.122 + * map.put(key, newValue);
1.123 + * return true;
1.124 + * } else return false;</pre>
1.125 + * except that the action is performed atomically.
1.126 + *
1.127 + * @param key key with which the specified value is associated
1.128 + * @param oldValue value expected to be associated with the specified key
1.129 + * @param newValue value to be associated with the specified key
1.130 + * @return <tt>true</tt> if the value was replaced
1.131 + * @throws UnsupportedOperationException if the <tt>put</tt> operation
1.132 + * is not supported by this map
1.133 + * @throws ClassCastException if the class of a specified key or value
1.134 + * prevents it from being stored in this map
1.135 + * @throws NullPointerException if a specified key or value is null,
1.136 + * and this map does not permit null keys or values
1.137 + * @throws IllegalArgumentException if some property of a specified key
1.138 + * or value prevents it from being stored in this map
1.139 + */
1.140 + boolean replace(K key, V oldValue, V newValue);
1.141 +
1.142 + /**
1.143 + * Replaces the entry for a key only if currently mapped to some value.
1.144 + * This is equivalent to
1.145 + * <pre>
1.146 + * if (map.containsKey(key)) {
1.147 + * return map.put(key, value);
1.148 + * } else return null;</pre>
1.149 + * except that the action is performed atomically.
1.150 + *
1.151 + * @param key key with which the specified value is associated
1.152 + * @param value value to be associated with the specified key
1.153 + * @return the previous value associated with the specified key, or
1.154 + * <tt>null</tt> if there was no mapping for the key.
1.155 + * (A <tt>null</tt> return can also indicate that the map
1.156 + * previously associated <tt>null</tt> with the key,
1.157 + * if the implementation supports null values.)
1.158 + * @throws UnsupportedOperationException if the <tt>put</tt> operation
1.159 + * is not supported by this map
1.160 + * @throws ClassCastException if the class of the specified key or value
1.161 + * prevents it from being stored in this map
1.162 + * @throws NullPointerException if the specified key or value is null,
1.163 + * and this map does not permit null keys or values
1.164 + * @throws IllegalArgumentException if some property of the specified key
1.165 + * or value prevents it from being stored in this map
1.166 + */
1.167 + V replace(K key, V value);
1.168 +}