1 8 package org.apache.avalon.excalibur.cache; 9 10 import java.util.ArrayList ; 11 import java.util.Iterator ; 12 13 17 public abstract class AbstractCache 18 implements Cache 19 { 20 protected ArrayList m_listeners; 21 22 public AbstractCache() 23 { 24 m_listeners = new ArrayList (); 25 } 26 27 public void addListener( final CacheListener listener ) 28 { 29 m_listeners.add( listener ); 30 } 31 32 public void removeListener( final CacheListener listener ) 33 { 34 m_listeners.remove( listener ); 35 } 36 37 protected void notifyAdded( final Object key, final Object value ) 38 { 39 final CacheEvent event = new CacheEvent( this, key, value ); 40 41 final int s = m_listeners.size(); 42 for ( int i = 0; i < s; i++ ) 43 { 44 ((CacheListener)m_listeners.get( i )).added( event ); 45 } 46 } 47 48 protected void notifyRemoved( final Object key, final Object value ) 49 { 50 final CacheEvent event = new CacheEvent( this, key, value ); 51 52 final int s = m_listeners.size(); 53 for ( int i = 0; i < s; i++ ) 54 { 55 ((CacheListener)m_listeners.get( i )).removed( event ); 56 } 57 } 58 } 59 | Popular Tags |