public static void main ( String [ ] args ) { Object [ ] list = null ; String foo = "foo" ; String bar = "bar" ; list = ListUtil . add ( list , foo ) ; System . out . println ( "add(foo): " + StringUtil . toString ( list ) ) ; list = ListUtil . add ( list , bar ) ; System . out . println ( "add(bar): " + StringUtil . toString ( list ) ) ; ListUtil . clearRef ( list , foo ) ; System . out . println ( "clear(foo): " + StringUtil . toString ( list ) ) ; String newBar = new String ( "bar" ) ; // prevent java from cleverly // referencing the same string // from the constant pool System . out . println ( "containsRef(newBar): " + ListUtil . containsRef ( list , newBar ) ) ; System . out . println ( "contains(newBar): " + ListUtil . contains ( list , newBar ) ) ; ListUtil . clear ( list , newBar ) ; System . out . println ( "clear(newBar): " + StringUtil . toString ( list ) ) ; list = ListUtil . add ( list , 0 , foo ) ; list = ListUtil . add ( list , 1 , bar ) ; System . out . println ( "Added foo+bar: " + StringUtil . toString ( list ) ) ; ListUtil . removeRef ( list , foo ) ; System . out . println ( "removeRef(foo): " + StringUtil . toString ( list ) ) ; list = ListUtil . add ( list , 0 , foo ) ; list = ListUtil . add ( list , 1 , bar ) ; System . out . println ( "Added foo+bar: " + StringUtil . toString ( list ) ) ; ListUtil . remove ( list , 0 ) ; System . out . println ( "remove(0): " + StringUtil . toString ( list ) ) ; ListUtil . remove ( list , 0 ) ; System . out . println ( "remove(0): " + StringUtil . toString ( list ) ) ; Object [ ] tl = ListUtil . testAndAddRef ( list , bar ) ; if ( tl == null ) { System . out . println ( "testAndAddRef(bar): failed: " + StringUtil . toString ( list ) ) ; } else { list = tl ; System . out . println ( "testAndAddRef(bar): added: " + StringUtil . toString ( list ) ) ; } String biz = "biz" ; tl = ListUtil . testAndAddRef ( list , biz ) ; if ( tl == null ) { System . out . println ( "testAndAddRef(biz): failed: " + StringUtil . toString ( list ) ) ; } else { list = tl ; System . out . println ( "testAndAddRef(biz): added: " + StringUtil . toString ( list ) ) ; } }
Run some tests .