deleteFromDocumentlist?

Hi,

I am looking for an easy way to delete a document from a document list, depending on the value of one of the fields in the document. Of course this can be accomplished in a flow service by looping over the list, branch on a field and use appendToDocumentlist to append to a new list, but I am looking for a more elegant and less memory consuming way. My java knowledge is not well enough to invent a java service for this myself. Does anybody have an example for me?

Thanks
Andre

Unfortunately, there really isn’t a way to do this and refer to it as “elegant.”

A document list is essentially a Java array under the covers. As you may know, removing an element within an array (in virtually every popular language) is not really doable. Here are array element removal techniques:

  • Create a new array and copy over only the desired elements

  • “Remove” the undesired element by marking it null. Subsequent code must know to look for and properly process dead elements.

  • Do the same as the above then shift all the remaining elements up in the array, leaving the dead element at the end. Subsequent code must know to look for this “null termination” and act appropriately.

Here are a couple of ideas that may work depending upon your situation:

  • If you know you’re going to filter out documents, try to do so while building the document list in the first place. Of course this isn’t always possible.

  • Don’t build a document list. Instead, use Java classes to load the documents into a linked list or some other appropriate collection structure. You’d write Java services that wrapped the Java class–for example, a service the creates a new java.util.LinkedList and puts the object in the pipeline. Then other services, such as add, remove, iterate, etc. would manipulate that collection as needed. Then as a final step, you could convert the collection to a document list (IData array).

HTH.