javax.swing.text
Class SegmentCache

java.lang.Object
  |
  +--javax.swing.text.SegmentCache

class SegmentCache
extends Object

SegmentCache caches Segments to avoid continually creating and destroying of Segments. A common use of this class would be:

   Segment segment = segmentCache.getSegment();
   // do something with segment
   ...
   segmentCache.releaseSegment(segment);
 

Version:
1.3 12/03/01

Field Summary
private  List segments
          A list of the currently unused Segments.
private static SegmentCache sharedCache
          A global cache.
 
Constructor Summary
SegmentCache()
          Creates and returns a SegmentCache.
 
Method Summary
 Segment getSegment()
          Returns a Segment.
static SegmentCache getSharedInstance()
          Returns the shared SegmentCache.
static Segment getSharedSegment()
          A convenience method to get a Segment from the shared SegmentCache.
 void releaseSegment(Segment segment)
          Releases a Segment.
static void releaseSharedSegment(Segment segment)
          A convenience method to release a Segment to the shared SegmentCache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sharedCache

private static SegmentCache sharedCache
A global cache.


segments

private List segments
A list of the currently unused Segments.

Constructor Detail

SegmentCache

public SegmentCache()
Creates and returns a SegmentCache.

Method Detail

getSharedInstance

public static SegmentCache getSharedInstance()
Returns the shared SegmentCache.


getSharedSegment

public static Segment getSharedSegment()
A convenience method to get a Segment from the shared SegmentCache.


releaseSharedSegment

public static void releaseSharedSegment(Segment segment)
A convenience method to release a Segment to the shared SegmentCache.


getSegment

public Segment getSegment()
Returns a Segment. When done, the Segment should be recycled by invoking releaseSegment.


releaseSegment

public void releaseSegment(Segment segment)
Releases a Segment. You should not use a Segment after you release it, and you should NEVER release the same Segment more than once, eg:
   segmentCache.releaseSegment(segment);
   segmentCache.releaseSegment(segment);
 
Will likely result in very bad things happening!



comments?