uima-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Eckart de Castilho <...@apache.org>
Subject Re: [jira] [Created] (UIMA-4135) support for modifying indexed FSs
Date Mon, 01 Dec 2014 21:09:07 GMT
On 01.12.2014, at 19:24, Marshall Schor <msa@schor.com> wrote:

> One approach would use the try/ finally form:
> 
>  controlVar = cas.startUimaIndexProtectedBlock();
>  try {
>    some code which modifies a FS (or maybe, multiple FSs
>  } finally {
>    controlVar.close();  // causes any "removes" to be now re-added to indices
>  }
> 
> A form like the above could use in Java 8 the simpler try-with-resources form:
>  try (controlVar = cas.startUimaIndexProtectedBlock()) {
>    some code which modifies a FS (or maybe, multiple FSs
>  }

For me, this smells a but like abusing try/catch, although I admit that
it also has some elegance.

Why not use an anonymous inner class like this:

cas.transaction(new Transaction<CAS>() {
  void perform(CAS cas) {
    // make modifications
  }
});

Afaik this works also in Java versions prior to 7. It's the kind of thing
one did before lambda arrived.

Cheers,

-- Richard
Mime
View raw message