<s> package org . eclipse . jdt . internal . core ; import java . text . NumberFormat ; import java . util . Enumeration ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IResource ; import org . eclipse . jdt . core . IBuffer ; import org . eclipse . jdt . core . IOpenable ; public class BufferManager { protected static BufferManager DEFAULT_BUFFER_MANAGER ; protected static boolean VERBOSE ; private BufferCache openBuffers = new BufferCache ( 60 ) ; protected org . eclipse . jdt . core . IBufferFactory defaultBufferFactory = new org . eclipse . jdt . core . IBufferFactory ( ) { public IBuffer createBuffer ( IOpenable owner ) { return BufferManager . createBuffer ( owner ) ; } } ; protected void addBuffer ( IBuffer buffer ) { if ( VERBOSE ) { String owner = ( ( Openable ) buffer . getOwner ( ) ) . toStringWithAncestors ( ) ; System . out . println ( "" + owner ) ; } synchronized ( this . openBuffers ) { this . openBuffers . put ( buffer . getOwner ( ) , buffer ) ; } this . openBuffers . closeBuffers ( ) ; if ( VERBOSE ) { System . out . println ( "" + NumberFormat . getInstance ( ) . format ( this . openBuffers . fillingRatio ( ) ) + "%" ) ; } } public static IBuffer createBuffer ( IOpenable owner ) { JavaElement element = ( JavaElement ) owner ; IResource resource = element . resource ( ) ; return new Buffer ( resource instanceof IFile ? ( IFile ) resource : null , owner , element . isReadOnly ( ) ) ; } public static IBuffer createNullBuffer ( IOpenable owner ) { JavaElement element = ( JavaElement ) owner ; IResource resource = element . resource ( ) ; return new NullBuffer ( resource instanceof IFile ? ( IFile ) resource : null , owner , element . isReadOnly ( ) ) ; } public IBuffer getBuffer ( IOpenable owner ) { synchronized ( this . openBuffers ) { return ( IBuffer ) this . openBuffers . get ( owner ) ; } } public synchronized static BufferManager getDefaultBufferManager ( ) { if ( DEFAULT_BUFFER_MANAGER == null ) { DEFAULT_BUFFER_MANAGER = new BufferManager ( ) ; } return DEFAULT_BUFFER_MANAGER ; } public org . eclipse . jdt . core . IBufferFactory getDefaultBufferFactory ( ) { return this . defaultBufferFactory ; } public Enumeration getOpenBuffers ( ) { Enumeration result ; synchronized ( this . openBuffers ) { this . openBuffers . shrink ( ) ; result = this . openBuffers . elements ( ) ; } this . openBuffers . closeBuffers ( ) ; return result ; } protected void removeBuffer ( IBuffer buffer ) { if ( VERBOSE ) { String owner = ( ( Openable ) buffer . getOwner ( ) ) . toStringWithAncestors ( ) ; System . out . println ( "" + owner ) ; } synchronized ( this . openBuffers ) { this . openBuffers . remove ( buffer . getOwner ( ) ) ; } this . openBuffers . closeBuffers ( ) ; if ( VERBOSE ) { System . out . println ( "" + NumberFormat . getInstance ( ) . format ( this . openBuffers . fillingRatio ( ) ) + "%" ) ; } } } </s>