private Iterator < String > getIterator ( ) { final Set < String > copy = getPrefixes ( ) ; final Iterator < String > copyIt = copy . iterator ( ) ; return new Iterator < String > ( ) { private String lastOne = null ; @ Override public boolean hasNext ( ) { return copyIt . hasNext ( ) ; } @ Override public String next ( ) { if ( copyIt . hasNext ( ) ) { lastOne = copyIt . next ( ) ; } else { throw new NoSuchElementException ( ) ; } return lastOne ; } @ Override public void remove ( ) { try { lock . writeLock ( ) . lock ( ) ; prefixes . remove ( lastOne ) ; } finally { lock . writeLock ( ) . unlock ( ) ; } } } ; }
Gets the iterator .