[Biojava-l] Remove features from a sequence

Matthew Pocock matthew_pocock at yahoo.co.uk
Tue Jun 24 20:16:38 EDT 2003


Any way we slice this, we're going to end up implementing an iterator, 
right? The code is going to be messy - doing all the change notification 
and stuff - we can't call the normal remove features method, as that 
will barf the iterator, which leaves us with writing the notification 
code again inside the iterator remove(). Code duplication - twice the 
code, twice the bugs?

So, on balance, I guess we should throw NotImplementedException on 
remove(). Unless somebody has a bright idea?

Well, yet again, we've been reminded that all interfaces should throw 
exceptions for all methods that can fail. Write, read out loud, repeat.

Matthew

Thomas Down wrote:
> Once upon a time, Keith James wrote:
> 
>>It may also be worth noting that you /can/ do this:
>>
>>while (seqI.hasNext())
>>{
>>    Sequence seq = seqI.nextSequence();
>>
>>    for (Iterator i = seq.features(); i.hasNext();)
>>    {
>>        i.next();
>>        i.remove();
>>    }
>>}
>>
>>which is a way to avoid ConcurrentModificationException, but also a
>>way to avoid informing any listeners to Sequence that all its Features
>>have been stripped - and is likely to be bad.
> 
> 
> Ugh, that's actually pretty nasty, to the extent that I would
> call it a bug.  My initial thought was to fix it by firing the
> appropriate events, but this doesn't work since the Iterator.remove()
> method can't throw a ChangeVetoException.  So the options are:
> 
>    - Hack it (throw something like IllegalStateException)
>  
>    - Add ChangeVetoRuntimeException (seems like a Bad Thing to
>      me since we've always said that change vetoes are checked
>      exceptions up until now.
> 
>    - Forbid Iterator.remove().  Easiest to code, but seems like
>      a shame.
> 
> None of these options seems terribly appetizing to me, but I
> think we should do something.
> 
> Any preferences?
>  
>     Thomas.
> _______________________________________________
> Biojava-l mailing list  -  Biojava-l at biojava.org
> http://biojava.org/mailman/listinfo/biojava-l
> 


-- 
BioJava Consulting LTD - Support and training for BioJava
http://www.biojava.co.uk



More information about the Biojava-l mailing list