1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2 <!--NewPage--> 3 <HTML> 4 <HEAD> 5 <!-- Generated by javadoc (build 1.6.0-google-internal) on Mon Jan 04 20:47:59 PST 2010 --> 6 <TITLE> 7 MapMaker (Guava Libraries 2010.01.04) 8 </TITLE> 9 10 <META NAME="date" CONTENT="2010-01-04"> 11 12 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style"> 13 14 <SCRIPT type="text/javascript"> 15 function windowTitle() 16 { 17 if (location.href.indexOf('is-external=true') == -1) { 18 parent.document.title="MapMaker (Guava Libraries 2010.01.04)"; 19 } 20 } 21 </SCRIPT> 22 <NOSCRIPT> 23 </NOSCRIPT> 24 25 </HEAD> 26 27 <BODY BGCOLOR="white" onload="windowTitle();"> 28 <HR> 29 30 31 <!-- ========= START OF TOP NAVBAR ======= --> 32 <A NAME="navbar_top"><!-- --></A> 33 <A HREF="#skip-navbar_top" title="Skip navigation links"></A> 34 <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> 35 <TR> 36 <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> 37 <A NAME="navbar_top_firstrow"><!-- --></A> 38 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> 39 <TR ALIGN="center" VALIGN="top"> 40 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> 41 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> 42 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> 43 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/MapMaker.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> 44 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> 45 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> 46 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> 47 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> 48 </TR> 49 </TABLE> 50 </TD> 51 <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> 52 </EM> 53 </TD> 54 </TR> 55 56 <TR> 57 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 58 <A HREF="../../../../com/google/common/collect/MapDifference.ValueDifference.html" title="interface in com.google.common.collect"><B>PREV CLASS</B></A> 59 <A HREF="../../../../com/google/common/collect/Maps.html" title="class in com.google.common.collect"><B>NEXT CLASS</B></A></FONT></TD> 60 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 61 <A HREF="../../../../index.html?com/google/common/collect/MapMaker.html" target="_top"><B>FRAMES</B></A> 62 <A HREF="MapMaker.html" target="_top"><B>NO FRAMES</B></A> 63 <SCRIPT type="text/javascript"> 64 <!-- 65 if(window==top) { 66 document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); 67 } 68 //--> 69 </SCRIPT> 70 <NOSCRIPT> 71 <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A> 72 </NOSCRIPT> 73 74 75 </FONT></TD> 76 </TR> 77 <TR> 78 <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 79 SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD> 80 <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 81 DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD> 82 </TR> 83 </TABLE> 84 <A NAME="skip-navbar_top"></A> 85 <!-- ========= END OF TOP NAVBAR ========= --> 86 87 <HR> 88 <!-- ======== START OF CLASS DATA ======== --> 89 <H2> 90 <FONT SIZE="-1"> 91 com.google.common.collect</FONT> 92 <BR> 93 Class MapMaker</H2> 94 <PRE> 95 <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</A> 96 <IMG SRC="../../../../resources/inherit.gif" ALT="extended by "><B>com.google.common.collect.MapMaker</B> 97 </PRE> 98 <HR> 99 <DL> 100 <DT><PRE>public final class <B>MapMaker</B><DT>extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></DL> 101 </PRE> 102 103 <P> 104 A <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentMap.html?is-external=true" title="class or interface in java.util.concurrent"><CODE>ConcurrentMap</CODE></A> builder, providing any combination of these 105 features: <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/SoftReference.html?is-external=true" title="class or interface in java.lang.ref">soft</A> or <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/WeakReference.html?is-external=true" title="class or interface in java.lang.ref">weak</A> keys, soft or weak values, timed expiration, and on-demand 106 computation of values. Usage example: <pre> <code>ConcurrentMap<Key, Graph> graphs = new MapMaker() 107 .concurrencyLevel(32) 108 .softKeys() 109 .weakValues() 110 .expiration(30, TimeUnit.MINUTES) 111 .makeComputingMap( 112 new Function<Key, Graph>() { 113 public Graph apply(Key key) { 114 return createExpensiveGraph(key); 115 } 116 });</code></pre> 117 118 These features are all optional; <code>new MapMaker().makeMap()</code> 119 returns a valid concurrent map that behaves exactly like a 120 <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentHashMap.html?is-external=true" title="class or interface in java.util.concurrent"><CODE>ConcurrentHashMap</CODE></A>. 121 122 The returned map is implemented as a hash table with similar performance 123 characteristics to <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentHashMap.html?is-external=true" title="class or interface in java.util.concurrent"><CODE>ConcurrentHashMap</CODE></A>. It supports all optional 124 operations of the <code>ConcurrentMap</code> interface. It does not permit 125 null keys or values. It is serializable; however, serializing a map that 126 uses soft or weak references can give unpredictable results. 127 128 <p><b>Note:</b> by default, the returned map uses equality comparisons 129 (the <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang"><CODE>equals</CODE></A> method) to determine equality 130 for keys or values. However, if <A HREF="../../../../com/google/common/collect/MapMaker.html#weakKeys()"><CODE>weakKeys()</CODE></A> or <A HREF="../../../../com/google/common/collect/MapMaker.html#softKeys()"><CODE>softKeys()</CODE></A> was specified, the map uses identity (<code>==</code>) 131 comparisons instead for keys. Likewise, if <A HREF="../../../../com/google/common/collect/MapMaker.html#weakValues()"><CODE>weakValues()</CODE></A> or 132 <A HREF="../../../../com/google/common/collect/MapMaker.html#softValues()"><CODE>softValues()</CODE></A> was specified, the map uses identity comparisons 133 for values. 134 135 <p>The returned map has <i>weakly consistent iteration</i>: an iterator 136 over one of the map's view collections may reflect some, all or none of 137 the changes made to the map after the iterator was created. 138 139 <p>An entry whose key or value is reclaimed by the garbage collector 140 immediately disappears from the map. (If the default settings of strong 141 keys and strong values are used, this will never happen.) The client can 142 never observe a partially-reclaimed entry. Any <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Map.Entry.html?is-external=true" title="class or interface in java.util"><CODE>Map.Entry</CODE></A> 143 instance retrieved from the map's <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Map.html?is-external=true#entrySet()" title="class or interface in java.util">entry set</A> 144 is snapshot of that entry's state at the time of retrieval. 145 146 <p><code>new MapMaker().weakKeys().makeMap()</code> can almost always be 147 used as a drop-in replacement for <A HREF="http://java.sun.com/javase/6/docs/api/java/util/WeakHashMap.html?is-external=true" title="class or interface in java.util"><CODE>WeakHashMap</CODE></A>, adding 148 concurrency, asynchronous cleanup, identity-based equality for keys, and 149 great flexibility. 150 <P> 151 152 <P> 153 <DL> 154 <DT><B>Since:</B></DT> 155 <DD>2010.01.04 <b>stable</b> (imported from Google Collections Library)</DD> 156 <DT><B>Author:</B></DT> 157 <DD>Bob Lee, Kevin Bourrillion</DD> 158 </DL> 159 <HR> 160 161 <P> 162 163 <!-- ======== CONSTRUCTOR SUMMARY ======== --> 164 165 <A NAME="constructor_summary"><!-- --></A> 166 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 167 <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 168 <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> 169 <B>Constructor Summary</B></FONT></TH> 170 </TR> 171 <TR BGCOLOR="white" CLASS="TableRowColor"> 172 <TD><CODE><B><A HREF="../../../../com/google/common/collect/MapMaker.html#MapMaker()">MapMaker</A></B>()</CODE> 173 174 <BR> 175 Constructs a new <code>MapMaker</code> instance with default settings, 176 including strong keys, strong values, and no automatic expiration.</TD> 177 </TR> 178 </TABLE> 179 180 <!-- ========== METHOD SUMMARY =========== --> 181 182 <A NAME="method_summary"><!-- --></A> 183 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 184 <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 185 <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> 186 <B>Method Summary</B></FONT></TH> 187 </TR> 188 <TR BGCOLOR="white" CLASS="TableRowColor"> 189 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 190 <CODE> <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A></CODE></FONT></TD> 191 <TD><CODE><B><A HREF="../../../../com/google/common/collect/MapMaker.html#concurrencyLevel(int)">concurrencyLevel</A></B>(int concurrencyLevel)</CODE> 192 193 <BR> 194 Guides the allowed concurrency among update operations.</TD> 195 </TR> 196 <TR BGCOLOR="white" CLASS="TableRowColor"> 197 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 198 <CODE> <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A></CODE></FONT></TD> 199 <TD><CODE><B><A HREF="../../../../com/google/common/collect/MapMaker.html#expiration(long, java.util.concurrent.TimeUnit)">expiration</A></B>(long duration, 200 <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/TimeUnit.html?is-external=true" title="class or interface in java.util.concurrent">TimeUnit</A> unit)</CODE> 201 202 <BR> 203 Specifies that each entry should be automatically removed from the 204 map once a fixed duration has passed since the entry's creation.</TD> 205 </TR> 206 <TR BGCOLOR="white" CLASS="TableRowColor"> 207 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 208 <CODE> <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A></CODE></FONT></TD> 209 <TD><CODE><B><A HREF="../../../../com/google/common/collect/MapMaker.html#initialCapacity(int)">initialCapacity</A></B>(int initialCapacity)</CODE> 210 211 <BR> 212 Sets a custom initial capacity (defaults to 16).</TD> 213 </TR> 214 <TR BGCOLOR="white" CLASS="TableRowColor"> 215 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 216 <CODE> 217 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY=""> 218 <TR ALIGN="right" VALIGN=""> 219 <TD NOWRAP><FONT SIZE="-1"> 220 <CODE><K,V> <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentMap.html?is-external=true" title="class or interface in java.util.concurrent">ConcurrentMap</A><K,V></CODE></FONT></TD> 221 </TR> 222 </TABLE> 223 </CODE></FONT></TD> 224 <TD><CODE><B><A HREF="../../../../com/google/common/collect/MapMaker.html#makeComputingMap(com.google.common.base.Function)">makeComputingMap</A></B>(<A HREF="../../../../com/google/common/base/Function.html" title="interface in com.google.common.base">Function</A><? super K,? extends V> computingFunction)</CODE> 225 226 <BR> 227 Builds a map that supports atomic, on-demand computation of values.</TD> 228 </TR> 229 <TR BGCOLOR="white" CLASS="TableRowColor"> 230 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 231 <CODE> 232 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY=""> 233 <TR ALIGN="right" VALIGN=""> 234 <TD NOWRAP><FONT SIZE="-1"> 235 <CODE><K,V> <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentMap.html?is-external=true" title="class or interface in java.util.concurrent">ConcurrentMap</A><K,V></CODE></FONT></TD> 236 </TR> 237 </TABLE> 238 </CODE></FONT></TD> 239 <TD><CODE><B><A HREF="../../../../com/google/common/collect/MapMaker.html#makeMap()">makeMap</A></B>()</CODE> 240 241 <BR> 242 Builds the final map, without on-demand computation of values.</TD> 243 </TR> 244 <TR BGCOLOR="white" CLASS="TableRowColor"> 245 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 246 <CODE> <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A></CODE></FONT></TD> 247 <TD><CODE><B><A HREF="../../../../com/google/common/collect/MapMaker.html#softKeys()">softKeys</A></B>()</CODE> 248 249 <BR> 250 Specifies that each key (not value) stored in the map should be 251 wrapped in a <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/SoftReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>SoftReference</CODE></A> (by default, strong references 252 are used).</TD> 253 </TR> 254 <TR BGCOLOR="white" CLASS="TableRowColor"> 255 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 256 <CODE> <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A></CODE></FONT></TD> 257 <TD><CODE><B><A HREF="../../../../com/google/common/collect/MapMaker.html#softValues()">softValues</A></B>()</CODE> 258 259 <BR> 260 Specifies that each value (not key) stored in the map should be 261 wrapped in a <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/SoftReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>SoftReference</CODE></A> (by default, strong references 262 are used).</TD> 263 </TR> 264 <TR BGCOLOR="white" CLASS="TableRowColor"> 265 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 266 <CODE> <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A></CODE></FONT></TD> 267 <TD><CODE><B><A HREF="../../../../com/google/common/collect/MapMaker.html#weakKeys()">weakKeys</A></B>()</CODE> 268 269 <BR> 270 Specifies that each key (not value) stored in the map should be 271 wrapped in a <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/WeakReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>WeakReference</CODE></A> (by default, strong references 272 are used).</TD> 273 </TR> 274 <TR BGCOLOR="white" CLASS="TableRowColor"> 275 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 276 <CODE> <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A></CODE></FONT></TD> 277 <TD><CODE><B><A HREF="../../../../com/google/common/collect/MapMaker.html#weakValues()">weakValues</A></B>()</CODE> 278 279 <BR> 280 Specifies that each value (not key) stored in the map should be 281 wrapped in a <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/WeakReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>WeakReference</CODE></A> (by default, strong references 282 are used).</TD> 283 </TR> 284 </TABLE> 285 <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A> 286 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 287 <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"> 288 <TH ALIGN="left"><B>Methods inherited from class java.lang.<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></B></TH> 289 </TR> 290 <TR BGCOLOR="white" CLASS="TableRowColor"> 291 <TD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</A></CODE></TD> 292 </TR> 293 </TABLE> 294 295 <P> 296 297 <!-- ========= CONSTRUCTOR DETAIL ======== --> 298 299 <A NAME="constructor_detail"><!-- --></A> 300 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 301 <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 302 <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> 303 <B>Constructor Detail</B></FONT></TH> 304 </TR> 305 </TABLE> 306 307 <A NAME="MapMaker()"><!-- --></A><H3> 308 MapMaker</H3> 309 <PRE> 310 public <B>MapMaker</B>()</PRE> 311 <DL> 312 <DD>Constructs a new <code>MapMaker</code> instance with default settings, 313 including strong keys, strong values, and no automatic expiration. 314 <P> 315 </DL> 316 317 <!-- ============ METHOD DETAIL ========== --> 318 319 <A NAME="method_detail"><!-- --></A> 320 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 321 <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 322 <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> 323 <B>Method Detail</B></FONT></TH> 324 </TR> 325 </TABLE> 326 327 <A NAME="initialCapacity(int)"><!-- --></A><H3> 328 initialCapacity</H3> 329 <PRE> 330 public <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A> <B>initialCapacity</B>(int initialCapacity)</PRE> 331 <DL> 332 <DD>Sets a custom initial capacity (defaults to 16). Resizing this or 333 any other kind of hash table is a relatively slow operation, so, 334 when possible, it is a good idea to provide estimates of expected 335 table sizes. 336 <P> 337 <DD><DL> 338 339 <DT><B>Throws:</B> 340 <DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>initialCapacity</code> is 341 negative 342 <DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalStateException.html?is-external=true" title="class or interface in java.lang">IllegalStateException</A></CODE> - if an initial capacity was already set</DL> 343 </DD> 344 </DL> 345 <HR> 346 347 <A NAME="concurrencyLevel(int)"><!-- --></A><H3> 348 concurrencyLevel</H3> 349 <PRE> 350 public <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A> <B>concurrencyLevel</B>(int concurrencyLevel)</PRE> 351 <DL> 352 <DD>Guides the allowed concurrency among update operations. Used as a 353 hint for internal sizing. The table is internally partitioned to try 354 to permit the indicated number of concurrent updates without 355 contention. Because placement in hash tables is essentially random, 356 the actual concurrency will vary. Ideally, you should choose a value 357 to accommodate as many threads as will ever concurrently modify the 358 table. Using a significantly higher value than you need can waste 359 space and time, and a significantly lower value can lead to thread 360 contention. But overestimates and underestimates within an order of 361 magnitude do not usually have much noticeable impact. A value of one 362 is appropriate when it is known that only one thread will modify and 363 all others will only read. Defaults to 16. 364 <P> 365 <DD><DL> 366 367 <DT><B>Throws:</B> 368 <DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>concurrencyLevel</code> is 369 nonpositive 370 <DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalStateException.html?is-external=true" title="class or interface in java.lang">IllegalStateException</A></CODE> - if a concurrency level was already set</DL> 371 </DD> 372 </DL> 373 <HR> 374 375 <A NAME="weakKeys()"><!-- --></A><H3> 376 weakKeys</H3> 377 <PRE> 378 public <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A> <B>weakKeys</B>()</PRE> 379 <DL> 380 <DD>Specifies that each key (not value) stored in the map should be 381 wrapped in a <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/WeakReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>WeakReference</CODE></A> (by default, strong references 382 are used). 383 384 <p><b>Note:</b> the map will use identity (<code>==</code>) comparison 385 to determine equality of weak keys, which may not behave as you expect. 386 For example, storing a key in the map and then attempting a lookup 387 using a different but <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang"><CODE>equals</CODE></A>-equivalent 388 key will always fail. 389 <P> 390 <DD><DL> 391 392 <DT><B>Throws:</B> 393 <DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalStateException.html?is-external=true" title="class or interface in java.lang">IllegalStateException</A></CODE> - if the key strength was already set<DT><B>See Also:</B><DD><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/WeakReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>WeakReference</CODE></A></DL> 394 </DD> 395 </DL> 396 <HR> 397 398 <A NAME="softKeys()"><!-- --></A><H3> 399 softKeys</H3> 400 <PRE> 401 public <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A> <B>softKeys</B>()</PRE> 402 <DL> 403 <DD>Specifies that each key (not value) stored in the map should be 404 wrapped in a <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/SoftReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>SoftReference</CODE></A> (by default, strong references 405 are used). 406 407 <p><b>Note:</b> the map will use identity (<code>==</code>) comparison 408 to determine equality of soft keys, which may not behave as you expect. 409 For example, storing a key in the map and then attempting a lookup 410 using a different but <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang"><CODE>equals</CODE></A>-equivalent 411 key will always fail. 412 <P> 413 <DD><DL> 414 415 <DT><B>Throws:</B> 416 <DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalStateException.html?is-external=true" title="class or interface in java.lang">IllegalStateException</A></CODE> - if the key strength was already set<DT><B>See Also:</B><DD><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/SoftReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>SoftReference</CODE></A></DL> 417 </DD> 418 </DL> 419 <HR> 420 421 <A NAME="weakValues()"><!-- --></A><H3> 422 weakValues</H3> 423 <PRE> 424 public <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A> <B>weakValues</B>()</PRE> 425 <DL> 426 <DD>Specifies that each value (not key) stored in the map should be 427 wrapped in a <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/WeakReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>WeakReference</CODE></A> (by default, strong references 428 are used). 429 430 <p>Weak values will be garbage collected once they are weakly 431 reachable. This makes them a poor candidate for caching; consider 432 <A HREF="../../../../com/google/common/collect/MapMaker.html#softValues()"><CODE>softValues()</CODE></A> instead. 433 434 <p><b>Note:</b> the map will use identity (<code>==</code>) comparison 435 to determine equality of weak values. This will notably impact 436 the behavior of <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Map.html?is-external=true#containsValue(java.lang.Object)" title="class or interface in java.util"><CODE>containsValue</CODE></A>, 437 <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentMap.html?is-external=true#remove(java.lang.Object, java.lang.Object)" title="class or interface in java.util.concurrent"><CODE>remove(Object, Object)</CODE></A>, 438 and <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentMap.html?is-external=true#replace(K, V, V)" title="class or interface in java.util.concurrent"><CODE>replace(K, V, V)</CODE></A>. 439 <P> 440 <DD><DL> 441 442 <DT><B>Throws:</B> 443 <DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalStateException.html?is-external=true" title="class or interface in java.lang">IllegalStateException</A></CODE> - if the key strength was already set<DT><B>See Also:</B><DD><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/WeakReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>WeakReference</CODE></A></DL> 444 </DD> 445 </DL> 446 <HR> 447 448 <A NAME="softValues()"><!-- --></A><H3> 449 softValues</H3> 450 <PRE> 451 public <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A> <B>softValues</B>()</PRE> 452 <DL> 453 <DD>Specifies that each value (not key) stored in the map should be 454 wrapped in a <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/SoftReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>SoftReference</CODE></A> (by default, strong references 455 are used). 456 457 <p>Soft values will be garbage collected in response to memory 458 demand, and in a least-recently-used manner. This makes them a 459 good candidate for caching. 460 461 <p><b>Note:</b> the map will use identity (<code>==</code>) comparison 462 to determine equality of soft values. This will notably impact 463 the behavior of <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Map.html?is-external=true#containsValue(java.lang.Object)" title="class or interface in java.util"><CODE>containsValue</CODE></A>, 464 <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentMap.html?is-external=true#remove(java.lang.Object, java.lang.Object)" title="class or interface in java.util.concurrent"><CODE>remove(Object, Object)</CODE></A>, 465 and <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentMap.html?is-external=true#replace(K, V, V)" title="class or interface in java.util.concurrent"><CODE>replace(K, V, V)</CODE></A>. 466 <P> 467 <DD><DL> 468 469 <DT><B>Throws:</B> 470 <DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalStateException.html?is-external=true" title="class or interface in java.lang">IllegalStateException</A></CODE> - if the value strength was already set<DT><B>See Also:</B><DD><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/ref/SoftReference.html?is-external=true" title="class or interface in java.lang.ref"><CODE>SoftReference</CODE></A></DL> 471 </DD> 472 </DL> 473 <HR> 474 475 <A NAME="expiration(long, java.util.concurrent.TimeUnit)"><!-- --></A><H3> 476 expiration</H3> 477 <PRE> 478 public <A HREF="../../../../com/google/common/collect/MapMaker.html" title="class in com.google.common.collect">MapMaker</A> <B>expiration</B>(long duration, 479 <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/TimeUnit.html?is-external=true" title="class or interface in java.util.concurrent">TimeUnit</A> unit)</PRE> 480 <DL> 481 <DD>Specifies that each entry should be automatically removed from the 482 map once a fixed duration has passed since the entry's creation. 483 <P> 484 <DD><DL> 485 <DT><B>Parameters:</B><DD><CODE>duration</CODE> - the length of time after an entry is created that it 486 should be automatically removed<DD><CODE>unit</CODE> - the unit that <code>duration</code> is expressed in 487 <DT><B>Throws:</B> 488 <DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>duration</code> is not positive 489 <DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalStateException.html?is-external=true" title="class or interface in java.lang">IllegalStateException</A></CODE> - if the expiration time was already set</DL> 490 </DD> 491 </DL> 492 <HR> 493 494 <A NAME="makeMap()"><!-- --></A><H3> 495 makeMap</H3> 496 <PRE> 497 public <K,V> <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentMap.html?is-external=true" title="class or interface in java.util.concurrent">ConcurrentMap</A><K,V> <B>makeMap</B>()</PRE> 498 <DL> 499 <DD>Builds the final map, without on-demand computation of values. This method 500 does not alter the state of this <code>MapMaker</code> instance, so it can be 501 invoked again to create multiple independent maps. 502 <P> 503 <DD><DL> 504 <DT><B>Type Parameters:</B><DD><CODE>K</CODE> - the type of keys to be stored in the returned map<DD><CODE>V</CODE> - the type of values to be stored in the returned map 505 <DT><B>Returns:</B><DD>a concurrent map having the requested features</DL> 506 </DD> 507 </DL> 508 <HR> 509 510 <A NAME="makeComputingMap(com.google.common.base.Function)"><!-- --></A><H3> 511 makeComputingMap</H3> 512 <PRE> 513 public <K,V> <A HREF="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentMap.html?is-external=true" title="class or interface in java.util.concurrent">ConcurrentMap</A><K,V> <B>makeComputingMap</B>(<A HREF="../../../../com/google/common/base/Function.html" title="interface in com.google.common.base">Function</A><? super K,? extends V> computingFunction)</PRE> 514 <DL> 515 <DD>Builds a map that supports atomic, on-demand computation of values. <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Map.html?is-external=true#get(java.lang.Object)" title="class or interface in java.util"><CODE>Map.get(java.lang.Object)</CODE></A> either returns an already-computed value for the given key, 516 atomically computes it using the supplied function, or, if another thread 517 is currently computing the value for this key, simply waits for that thread 518 to finish and returns its computed value. Note that the function may be 519 executed concurrently by multiple threads, but only for distinct keys. 520 521 <p>If an entry's value has not finished computing yet, query methods 522 besides <code>get</code> return immediately as if an entry doesn't exist. In 523 other words, an entry isn't externally visible until the value's 524 computation completes. 525 526 <p><A HREF="http://java.sun.com/javase/6/docs/api/java/util/Map.html?is-external=true#get(java.lang.Object)" title="class or interface in java.util"><CODE>Map.get(java.lang.Object)</CODE></A> on the returned map will never return <code>null</code>. It 527 may throw: 528 529 <ul> 530 <li><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang"><CODE>NullPointerException</CODE></A> if the key is null or the computing 531 function returns null 532 <li><A HREF="../../../../com/google/common/collect/ComputationException.html" title="class in com.google.common.collect"><CODE>ComputationException</CODE></A> if an exception was thrown by the 533 computing function. If that exception is already of type <A HREF="../../../../com/google/common/collect/ComputationException.html" title="class in com.google.common.collect"><CODE>ComputationException</CODE></A>, it is propagated directly; otherwise it is 534 wrapped. 535 </ul> 536 537 <p><b>Note:</b> Callers of <code>get</code> <i>must</i> ensure that the key 538 argument is of type <code>K</code>. The <code>get</code> method accepts <code>Object</code>, so the key type is not checked at compile time. Passing an object 539 of a type other than <code>K</code> can result in that object being unsafely 540 passed to the computing function as type <code>K</code>, and unsafely stored in 541 the map. 542 543 <p>If <A HREF="http://java.sun.com/javase/6/docs/api/java/util/Map.html?is-external=true#put(K, V)" title="class or interface in java.util"><CODE>Map.put(K, V)</CODE></A> is called before a computation completes, other 544 threads waiting on the computation will wake up and return the stored 545 value. When the computation completes, its new result will overwrite the 546 value that was put in the map manually. 547 548 <p>This method does not alter the state of this <code>MapMaker</code> instance, 549 so it can be invoked again to create multiple independent maps. 550 <P> 551 <DD><DL> 552 </DL> 553 </DD> 554 </DL> 555 <!-- ========= END OF CLASS DATA ========= --> 556 <HR> 557 558 559 <!-- ======= START OF BOTTOM NAVBAR ====== --> 560 <A NAME="navbar_bottom"><!-- --></A> 561 <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A> 562 <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> 563 <TR> 564 <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> 565 <A NAME="navbar_bottom_firstrow"><!-- --></A> 566 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> 567 <TR ALIGN="center" VALIGN="top"> 568 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> 569 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> 570 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> 571 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/MapMaker.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> 572 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> 573 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> 574 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> 575 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> 576 </TR> 577 </TABLE> 578 </TD> 579 <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> 580 </EM> 581 </TD> 582 </TR> 583 584 <TR> 585 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 586 <A HREF="../../../../com/google/common/collect/MapDifference.ValueDifference.html" title="interface in com.google.common.collect"><B>PREV CLASS</B></A> 587 <A HREF="../../../../com/google/common/collect/Maps.html" title="class in com.google.common.collect"><B>NEXT CLASS</B></A></FONT></TD> 588 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 589 <A HREF="../../../../index.html?com/google/common/collect/MapMaker.html" target="_top"><B>FRAMES</B></A> 590 <A HREF="MapMaker.html" target="_top"><B>NO FRAMES</B></A> 591 <SCRIPT type="text/javascript"> 592 <!-- 593 if(window==top) { 594 document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); 595 } 596 //--> 597 </SCRIPT> 598 <NOSCRIPT> 599 <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A> 600 </NOSCRIPT> 601 602 603 </FONT></TD> 604 </TR> 605 <TR> 606 <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 607 SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD> 608 <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 609 DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD> 610 </TR> 611 </TABLE> 612 <A NAME="skip-navbar_bottom"></A> 613 <!-- ======== END OF BOTTOM NAVBAR ======= --> 614 615 <HR> 616 617 </BODY> 618 </HTML> 619