Java Doc for SoftCache.java in  » 6.0-JDK-Modules » j2me » sun » misc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » sun.misc 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.util.AbstractMap
      sun.misc.SoftCache

SoftCache
public class SoftCache extends AbstractMap implements Map(Code)
A memory-sensitive implementation of the Map interface.

A SoftCache object uses java.lang.ref.SoftReferencesoft references to implement a memory-sensitive hash map. If the garbage collector determines at a certain point in time that a value object in a SoftCache entry is no longer strongly reachable, then it may remove that entry in order to release the memory occupied by the value object. All SoftCache objects are guaranteed to be completely cleared before the virtual machine will throw an OutOfMemoryError. Because of this automatic clearing feature, the behavior of this class is somewhat different from that of other Map implementations.

Both null values and the null key are supported. This class has the same performance characteristics as the HashMap class, and has the same efficiency parameters of initial capacity and load factor.

Like most collection classes, this class is not synchronized. A synchronized SoftCache may be constructed using the Collections.synchronizedMap method.

In typical usage this class will be subclassed and the fill method will be overridden. When the get method is invoked on a key for which there is no mapping in the cache, it will in turn invoke the fill method on that key in an attempt to construct a corresponding value. If the fill method returns such a value then the cache will be updated and the new value will be returned. Thus, for example, a simple URL-content cache can be constructed as follows:

 public class URLCache extends SoftCache {
 protected Object fill(Object key) {
 return ((URL)key).getContent();
 }
 }
 

The behavior of the SoftCache class depends in part upon the actions of the garbage collector, so several familiar (though not required) Map invariants do not hold for this class.

Because entries are removed from a SoftCache in response to dynamic advice from the garbage collector, a SoftCache may behave as though an unknown thread is silently removing entries. In particular, even if you synchronize on a SoftCache instance and invoke none of its mutator methods, it is possible for the size method to return smaller values over time, for the isEmpty method to return false and then true, for the containsKey method to return true and later false for a given key, for the get method to return a value for a given key but later return null, for the put method to return null and the remove method to return false for a key that previously appeared to be in the map, and for successive examinations of the key set, the value set, and the entry set to yield successively smaller numbers of elements.
version:
   1.4, 00/02/02
author:
   Mark Reinhold
since:
   JDK1.2
See Also:   java.util.HashMap
See Also:   java.lang.ref.SoftReference




Constructor Summary
public  SoftCache(int initialCapacity, float loadFactor)
     Construct a new, empty SoftCache with the given initial capacity and the given load factor.
public  SoftCache(int initialCapacity)
     Construct a new, empty SoftCache with the given initial capacity and the default load factor.
public  SoftCache()
     Construct a new, empty SoftCache with the default capacity and the default load factor.

Method Summary
public  voidclear()
     Remove all mappings from this cache.
public  booleancontainsKey(Object key)
     Return true if this cache contains a mapping for the specified key.
public  SetentrySet()
     Return a Set view of the mappings in this cache.
protected  Objectfill(Object key)
     Create a value object for the given key.
public  Objectget(Object key)
     Return the value to which this cache maps the specified key.
public  booleanisEmpty()
     Return true if this cache contains no key-value mappings.
public  Objectput(Object key, Object value)
     Update this cache so that the given key maps to the given value.
public  Objectremove(Object key)
     Remove the mapping for the given key from this cache, if present.
public  intsize()
     Return the number of key-value mappings in this cache.


Constructor Detail
SoftCache
public SoftCache(int initialCapacity, float loadFactor)(Code)
Construct a new, empty SoftCache with the given initial capacity and the given load factor.
Parameters:
  initialCapacity - The initial capacity of the cache
Parameters:
  loadFactor - A number between 0.0 and 1.0
throws:
  IllegalArgumentException - If the initial capacity is less thanor equal to zero, or if the loadfactor is less than zero



SoftCache
public SoftCache(int initialCapacity)(Code)
Construct a new, empty SoftCache with the given initial capacity and the default load factor.
Parameters:
  initialCapacity - The initial capacity of the cache
throws:
  IllegalArgumentException - If the initial capacity is less thanor equal to zero



SoftCache
public SoftCache()(Code)
Construct a new, empty SoftCache with the default capacity and the default load factor.




Method Detail
clear
public void clear()(Code)
Remove all mappings from this cache.



containsKey
public boolean containsKey(Object key)(Code)
Return true if this cache contains a mapping for the specified key. If there is no mapping for the key, this method will not attempt to construct one by invoking the fill method.
Parameters:
  key - The key whose presence in the cache is to be tested



entrySet
public Set entrySet()(Code)
Return a Set view of the mappings in this cache.



fill
protected Object fill(Object key)(Code)
Create a value object for the given key. This method is invoked by the get method when there is no entry for key. If this method returns a non-null value, then the cache will be updated to map key to that value, and that value will be returned by the get method.

The default implementation of this method simply returns null for every key value. A subclass may override this method to provide more useful behavior.
Parameters:
  key - The key for which a value is to be computed A value for key, or null if onecould not be computed
See Also:   SoftCache.get




get
public Object get(Object key)(Code)
Return the value to which this cache maps the specified key. If the cache does not presently contain a value for this key, then invoke the fill method in an attempt to compute such a value. If that method returns a non-null value, then update the cache and return the new value. Otherwise, return null.

Note that because this method may update the cache, it is considered a mutator and may cause ConcurrentModificationExceptions to be thrown if invoked while an iterator is in use.
Parameters:
  key - The key whose associated value, if any, is to be returned
See Also:   SoftCache.fill




isEmpty
public boolean isEmpty()(Code)
Return true if this cache contains no key-value mappings.



put
public Object put(Object key, Object value)(Code)
Update this cache so that the given key maps to the given value. If the cache previously contained a mapping for key then that mapping is replaced and the old value is returned.
Parameters:
  key - The key that is to be mapped to the givenvalue
Parameters:
  value - The value to which the given key is to bemapped The previous value to which this key was mapped, ornull if if there was no mapping for the key



remove
public Object remove(Object key)(Code)
Remove the mapping for the given key from this cache, if present.
Parameters:
  key - The key whose mapping is to be removed The value to which this key was mapped, or null ifthere was no mapping for the key



size
public int size()(Code)
Return the number of key-value mappings in this cache. The time required by this operation is linear in the size of the map.



Methods inherited from java.util.AbstractMap
public void clear()(Code)(Java Doc)
protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean containsKey(Object key)(Code)(Java Doc)
public boolean containsValue(Object value)(Code)(Java Doc)
abstract public Set entrySet()(Code)(Java Doc)
public boolean equals(Object o)(Code)(Java Doc)
public Object get(Object key)(Code)(Java Doc)
public int hashCode()(Code)(Java Doc)
public boolean isEmpty()(Code)(Java Doc)
public Set keySet()(Code)(Java Doc)
public Object put(Object key, Object value)(Code)(Java Doc)
public void putAll(Map t)(Code)(Java Doc)
public Object remove(Object key)(Code)(Java Doc)
public int size()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
public Collection values()(Code)(Java Doc)

Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.