FileDocCategorySizeDatePackage
DebugWeakList.javaAPI DocAzureus 3.0.3.44606Mon Dec 11 16:29:30 GMT 2006org.gudy.azureus2.core3.util

DebugWeakList

public class DebugWeakList extends Object

Fields Summary
static final boolean
DEBUG
private String
name
private List
list
Constructors Summary
public DebugWeakList(String _name)

	
	
	
			 
	
		name	= _name;
		list	= new ArrayList();
	
public DebugWeakList(String _name, DebugWeakList l)

		name	= _name;
		list 	= new ArrayList( l.list );
	
Methods Summary
public voidadd(java.lang.Object obj)

		if ( DEBUG ){
		
			list.add( new Object[]{ obj.getClass(), new WeakReference( obj )});
			
		}else{
			
			list.add( obj );
		}
	
public booleancontains(java.lang.Object obj)

		if ( DEBUG ){

			Iterator	it = list.iterator();
			
			while( it.hasNext()){
				
				Object[]	entry  = (Object[])it.next();
				
				WeakReference	wr = (WeakReference)entry[1];
				
				Object	target = wr.get();
				
				if ( target == null ){
					
					it.remove();
					
					logRemoved((Class)entry[0]);
					
				}else if ( target == obj ){
					
					return( true );
				}
			}
			
			return( false );
		}else{
			
			return( list.contains( obj ));
		}
	
public intestimatedSize()

		return( list.size());
	
public java.util.Iteratoriterator()

		if ( DEBUG ){

			return( new WeakListIterator());
			
		}else{
			
			return( list.iterator());
		}
	
protected voidlogRemoved(java.lang.Class cla)

		Debug.out( "Object '" + cla + "' was not removed correctly from " + name );
	
public voidremove(java.lang.Object obj)

		if ( DEBUG ){

			Iterator	it = list.iterator();
			
			while( it.hasNext()){
				
				Object[]	entry  = (Object[])it.next();
				
				WeakReference	wr = (WeakReference)entry[1];
				
				Object	target = wr.get();
				
				if ( target == null ){
					
					it.remove();
					
					logRemoved((Class)entry[0]);
					
				}else if ( target == obj ){
					
					it.remove();
					
					return;
				}
			}
		}else{
			
			list.remove( obj );
		}