-
Couldn't load subscription status.
- Fork 1.8k
LANG-1504 - Adding labels to split StopWatch feature #1473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
@edelgadoh |
4056078 to
b7a0928
Compare
|
Hi @garydgregory , yeah, I'm running In the last commit I did, almost all jobs passed except for MacOs 13 JDK 25 that failed https://github.com/edelgadoh/commons-lang-bugfix/actions/runs/18793891189/job/53630024591 with this: but it's not related to my change, my fork is already synced with master. If I get more time, I'll try to explore this another issue in a different thread. |
|
Hello @edelgadoh |
5799ce2 to
dded536
Compare
|
Hi @garydgregory , I fixed the unrelated test and I think now it's ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @edelgadoh
Thank you for your pull request.
Please rebase on git master.
I have comments scattered throughout the PR.
The most important aspect is that this new split code does not integrate with the existing split code; these two must be made to work in sync. See StopWatch.getSplitDuration() for example.
I've converted this PR back to a draft. You can change to ready when you are done reviewing my comments and are done pushing.
src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java
Outdated
Show resolved
Hide resolved
9b512d2 to
9df5701
Compare
|
Hi @garydgregory,
Please let me know if now it's better, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @edelgadoh ( CC @ppkarwasz )
Thank you for your updates.
This PR still doesn't address integration with the existing split APIs. We shouldn't have 2 separate split systems in the same class. The existing APIs are listed below with some initial thoughts. The existing split logic should be reimplemented on top of the new one, and the existing tests should pass if all goes well.
-
StopWatch.split(): Adding to the end of the split list seems reasonable. -
StopWatch.unsplit(): Removing from the end of the split list (matchingsplit()). -
StopWatch.getSplitDuration(): "This is the Duration between start and latest split."
This looks like it should be reimplemented to work from the last split in the list (or should it be the first). We might need additional tests. -
StopWatch.getSplitNanoTime(): "This is the time between start and latest split." -
StopWatch.getSplitTime(): "This is the time between start and latest split." -
StopWatch.toSplitString(): "Gets a summary of the split time that this StopWatch recorded as a string."
We need to decide if this works with the whole list of just the last one. -
StopWatch.formatSplitTime(): "Formats the split time"
We need to decide if this works with the whole list of just the last one. -
StopWatch.toString()can change as we see fit since its primary purpose is a debug helper.
|
Hi @garydgregory , I just refactored to address the integration with the existing split API based on your suggestions, I checked all methods you listed above and now it's synced, I think now it's closer to what is expected, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @edelgadoh
Thank you for your updates.
The integration is not fully tested, for example, the following new test fails:
@Test
void testGetSplits() {
final StopWatch stopWatch = StopWatch.create();
assertTrue(stopWatch.getSplits().isEmpty());
stopWatch.start();
testGetSplits(stopWatch);
testGetSplits(StopWatch.createStarted());
}
private void testGetSplits(final StopWatch watch) {
assertTrue(watch.getSplits().isEmpty());
watch.split();
assertEquals(1, watch.getSplits().size());
watch.unsplit();
assertTrue(watch.getSplits().isEmpty());
}The failure is:
java.lang.NullPointerException
at java.base/java.util.Collections$UnmodifiableCollection.<init>(Collections.java:1030)
at java.base/java.util.Collections$UnmodifiableList.<init>(Collections.java:1303)
at java.base/java.util.Collections.unmodifiableList(Collections.java:1290)
at org.apache.commons.lang3.time.StopWatch.getSplits(StopWatch.java:345)
at org.apache.commons.lang3.time.StopWatchTest.testGetSplits(StopWatchTest.java:226)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
My advice is to initialize the splits list with the instance variable declaration and then use List.clear() to reset the list when needed. The added benefit is that you can then make splits final.
|
Hi @garydgregory, good catch, I just applied your suggestion and the NPE is fixed. |
Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.I created this new PR that is based on this another one #482 created 5 years ago, since the fork belongs to another DEV it was not possible to cherry-pick it and It seems the previous owner didn't reply anymore.
I'm happy to contribute on this feature, any feedback will be fixed / pushed as soon as I have available time.