Closed Despair2000 closed 4 years ago
remove
is fully supported in org.apache.commons.collections.buffer.CircularFifoBuffer
.
Simple example is just to remove the object after you take it. Something like
event = buf.get()
buf.remove(event)
If you call remove()
without any input object, then the least recently added item will be removed from the queue.
The full docs for the circular buffer are here: https://commons.apache.org/proper/commons-collections/javadocs/api-3.2.2/org/apache/commons/collections/buffer/CircularFifoBuffer.html
remove
I could make work (removing the last added event) it is removeIf
I have trouble with. How would such a condition look like?
Thank you very much for the link to the docs but am I blind or is the removeIf method missing there?
I'm not sure that removeIf
is defined for circular buffer -- methods(buf)
does not show it and it is not in the docs. Where did/does removeIf
show up?
You could use anonymous functions to implement simple removeIf
functionality. Something like:
test = @(e)e<0
test(4)
test(-6)
Then you can iterate over the elements in the buffer and apply test
to each one. If test
returns true then remove the item.
function removeIf(buf, func)
% get list of events from buffer
events = collection2cell(buf);
% iterate over evenets in buffer
for i = 1:numel(events)
% get the ith event
e = events{i};
% apply the test criteria for event
if func(e); buf.remove(e); end
end
end
Finally, create some anonymous function like eqReqId = @(e)e.data.reqId==123
and call removeIf(buf,eqReqId)
Just create a buffer and then look at the methods, there is a removeIf method. But your solution looks fine. Thank you!
you're right -- removeIf is in Apache Commons version 4.4 (I was looking at older ver 3.2.2).
Do you have a link to the documentation? I’m searching but I can’t find the syntax. I found it named at one place but this is all.
Am 16.10.2019 um 16:08 schrieb Abel Brown notifications@github.com:
you're right -- removeIf is in Apache Commons version 4.4 (I was looking at older ver 3.2.2).
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/76?email_source=notifications&email_token=AJFOPM43K5KKXEEJYWVPRVTQO4N65A5CNFSM4JA3TUBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBMT5EQ#issuecomment-542719634, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJFOPM552MYRTNWJGKQAYJLQO4N65ANCNFSM4JA3TUBA.
Hi @softwarespartan
The circularfifos we are using with IB4m have removeIf methods. Could you give an example how you call these? I tried but can't make it work.
i think it might be useful to remove for example filled orders from the orders buffer. So I want to remove an event with e.data.orderId = XXXX or something similar.
is this possible with this method?