implementation of a generic iterator interface, api changes#238
implementation of a generic iterator interface, api changes#238rsoika wants to merge 10 commits into
Conversation
|
Hello Ralph, Your work does really improve the former implementation a lot! I find the prior existing search functionalty quite difficult to understand, while the underlying search scenario seems relativ easy (looking for strings in certain elements within the document), its API improvement seems quite complex to me and I might need more time and/or discussions! Only looked briefly into it today and realized, I need to sleep over it and look over it during next week as it is not easy to decide. :-) Some questions on the prior & new API you might speed up my review: For instance,
To make things even more complex, I would like to point out that this functionality was added by IBM Beijing around 2009. StarOffice team was dismissed by Oracle in 2010. And I started to work for Open-XChange in 2011 on ODFDOM to be used as the backend of a WebOffice only dispatching editor changes instead of exchanging complete documents. Long story short, instead of refactoring this selection (I guess I simply have not thought at that time), I created a new one in parallel in changes package: Fun fact, basically the Hyperlink is just a Selection of Text with the property of an URL! :-) It is not part of this API change as it has no change functionality, but in theory these both parts belong closer together. Have a nice Sunday, Ralph! PS: Some other functionality as tables have overlapping in the change package, too... |
|
Hi Svante, yes I agree with you that the methods Currently you can't call next() several times in series because nothing will change. Should we change this in a first next step
|
|
Yes, I think this would be a good idea to do as you suggest! |
|
I have now adjusted the API accordingly. In the process, I have also improved some tests. Now to me this looks much better. I hope you are happy with it too? |
|
Hello Ralph, I do not want to be too strict as the original donated code was never that hard reviewed, let's see if we the same understanding or maye I am overseeing something. ;-) We have this two methods:
If hasNext() might be called in the very beginning, it certainly have to call the similar underlying functionality similar to the next() function to search if there is some string to be found in the ODF. The found string should be cached, as if hasNext() is being called just again this cached string should be returned (instead of looking for a new one), right? if afterwards next() is called, it would first check if there is a cached string from hasNext(), if this is the case, this one will be returned and set to null, if null from the beginning the same search function as called by hasNext() is being triggered. That is basically what I wanted to write on Sunday, but I was without coffein :-) PS: We might as well have a good old voice call (or VOIP) to quickly discuss this and some context - as I now looked a bit deeper into this functionality! :-) |
|
I agree totally with you. And I have tried my very best - except the caching idea. |
|
Hi @svanteschubert, I archived my first goal and the So this looks now really much better! But now: The So what should I do? Should I go through all the junit tests and tweak this Selection methods? Or do you have a maybe better API I could use here? If so maybe we got much better junit test out of this work... |
|
Hi Ralph, I might look into this earliest in the late afternoon, therefore I will answer now briefly:
These are indeed good news!!
The scenario of the existing change code is that a list of ODF changes (delivered in JSON) is being applied to the ODF document. The change position is defined by an integer list, similar to an XPath counting the user entities (but not the XML). Thanks so far for your help, Ralph. Very much appreciated! |
|
Hi, @svanteschubert See here: Please do not peek to much into my code now - it is work in progress..... So now, only the junit test that are manipulating the elements are now broken. It would be great if we could switch to your change API. |
|
Hi, @svanteschubert once again I want to share my thoughts (but please don't feel pressured by me now and read it when you find time): I finished the TextNavigation implementation. The class now implements the Iterator interface in a elegant way and it works like a charm. I am very happy with this. You can search for regex-patterns and navigate through the document. For my own project this is all what I expect from the navigator. The Selection class - which is the object class returned by the navigator - provides the Container Element and even the position within the text where the pattern was found. So far everything is super fine. BUT: The I - and this is my personal opinion - would not expect that a Navigator API provides me methods to modifiy the document. I am sure it is easy enough with the existing API to change the document content when iterating through the document. At least I have done this in our own project by simply modify the content of an Container Element returned by the Navigator. (I did not even notice that the A lot of the junit tests dealing with the modification of the current selection, are currently broken. This is because these tests depend on the modify-methods provided by the I think it should be not to difficulty to re-implement these tests with the core functionality and not using the replace/paste/delete/... methods on the So my question is: Do you think it is worth to re-implement the junit tests and later remove the modify-methods from the Navigator API? |
|
Hi, @svanteschubert The Iterator Interface is now correctly implemented for both Navigation implementations. I cleaned up the code as good as I was able to. I inserted the After diving deeper and deeper into the code, I understood that the modify methods are needed inside the Navigation for use cases in which you whant to replace parts of a paragraph including the correct formatting. Most of junit tests are dealing with style sheets during modification. The method Anyway - now all Unit Test are fine - except the tests dealing with the methods The test As you can see, this test is working fine. So things are not totally bad. But if the parent element hat more occurrences of the text pattern (like in the test method I was not able to fix the problem and have now given up a bit frustrated. It would be great if you would still accept my changes so far and we could track the PasteAtFront and PasteAtEnd methods as a separate issue. What do you think? |
|
@rsoika Thank you so far, I am curious on what you changed and on the problems you mentioned. |
|
@svanteschubert no problem. When you find time next week that's fine. We can also do a short call next week to synchronize and sort out confusions ;-) |

I changed the API as suggested here.
In addition the
Navigationinterface now implements aIteratorinterface in a generic way.This makes the code in my opinion much more readable and the Class cast is no longer needed: