1 22 23 24 package com.mchange.v2.coalesce; 25 26 import java.util.*; 27 import java.lang.ref.WeakReference ; 28 29 class AbstractWeakCoalescer implements Coalescer 30 { 31 Map wcoalesced; 32 33 AbstractWeakCoalescer( Map wcoalesced ) 34 { this.wcoalesced = wcoalesced; } 35 36 public Object coalesce( Object o ) 37 { 38 Object out = null; 40 41 WeakReference wr = (WeakReference ) wcoalesced.get( o ); 42 if ( wr != null ) 43 out = wr.get(); if ( out == null ) 46 { 47 wcoalesced.put( o , new WeakReference (o) ); 48 out = o; 49 } 50 return out; 51 } 52 53 public int countCoalesced() 54 { return wcoalesced.size(); } 55 56 public Iterator iterator() 57 { return new CoalescerIterator( wcoalesced.keySet().iterator() ); } 58 } 59 60 61 62 | Popular Tags |