<div dir="ltr">Hello, Markus.<br><br>API is not limited to timespans. It was a sample implementation for Range interface back when it was not refactored into abstract class, which, by the way, was removed from PR as for now.<br><br>My initial motivation was to provide a range for date and time values, so I based general shape pretty heavily on the date time libraries. Nevertheless, as you might see, API is type-agnostic, and one of the goals is to make ranges specializable for different types (although this would require additional research)<br><br>Best regards</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 23, 2024 at 9:10 PM Olexandr Rotan <<a href="mailto:rotanolexandr842@gmail.com">rotanolexandr842@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello! Thanks for your comments<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The start() and end() be should be specifiable as either inclusive or exclusive, otherwise open bounds are not possible. For example, how would one express the range of all Strings strictly less than "zzz"? (note every element in the infinite sequence "zzy", "zzyy", "zzyyy", ... is less than "zzz"). This is why for example NavigableSet.subSet() has parameters for that.</blockquote><div><br></div><div>This has been addressed by modifying API today, now all types of ranges support both exclusive and inclusive bounds.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I've never encountered a negative range and am skeptical that it would actually be useful. What's an example of a real-world use case? I don't see how they would help diagrams visualization other than maybe saving you a boolean, i.e., you could just use the normal range and draw the arrow the other way.</blockquote><div><br></div><div>I guess this was my fault as I chose the wrong design perspective. I have already commented on this pull request. Basically, I have some physics background and I used to view ranges as vectors instead of scalars, so it was just fluent to me in some way to allow negative ranges. Anyway, now that I have received unanimous feedback regarding the requirement of inclusive/exclusive bounds, and having both negative ranges and different types of bounds just blows up the implementations, so negative ranges were dropped.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">In my experience, when you work with ranges you often also need to work with sets of ranges. If we had a Range class then it would be natural to also have a RangeSet class as well with union, intersection, difference, and ordered iteration operations, etc.</blockquote><div><br></div><div>That is true. I saw high demand on it in comments, so now this is my second priority in the list to develop Union type and common supertype for it and Range (after making bounds compile-time checked so users don't have to suffer exceptions if range does not have bound).</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">You are restricting to domains that implement Comparable, but this limits usefulness. For example, byte[] arrays are often ordered lexicographically as unsigned values and we want to work with ranges of byte[] arrays. It would be more general to allow supplying a Comparator (if needed, otherwise null). Then you would also want to expose this using a comparator() method (like SortedSet does). Note that Guava does not allow providing a Comparator so they voted the other way on this.</blockquote><div><br></div><div>This would make range arithmetics tangled. What if you intersect ranges with different comparators? What is the behaviour of gap and difference? What if you want to unionize them? This most likely will lead to breach of Union contract, which guarantees that ranges do not overlap. Even if users pass a comparator to every operation, what will guarantee that end > start for this comparator for both ranges? There are a lot of issues with this initiative.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Guava has addressed this same problem; their approach worth reviewing: <a href="https://github.com/google/guava/wiki/RangesExplained" target="_blank">https://github.com/google/guava/wiki/RangesExplained</a></blockquote><div><br></div><div>Thanks. I will look into it for references. To my shame, I haven't looked into guava when designing the API, so this will be really useful.</div><div><br></div><div>Best regards</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 23, 2024 at 5:10 AM Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" target="_blank">archie.cobbs@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 22, 2024 at 2:03 PM Olexandr Rotan <<a href="mailto:rotanolexandr842@gmail.com" target="_blank">rotanolexandr842@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello everyone! I am writing here today to invite everyone to participate in the discussion regarding the Range APi proposal I have made into JDK.</div></blockquote><div><br></div><div><div dir="ltr">A few comments...</div><div dir="ltr"><br></div><div>Guava has addressed this same problem; their approach worth reviewing: <a href="https://github.com/google/guava/wiki/RangesExplained" target="_blank">https://github.com/google/guava/wiki/RangesExplained</a></div><div><br></div><div>You are restricting to domains that implement Comparable, but this limits usefulness. For example, byte[] arrays are often ordered lexicographically as unsigned values and we want to work with ranges of byte[] arrays. It would be more general to allow supplying a Comparator (if needed, otherwise null). Then you would also want to expose this using a comparator() method (like SortedSet does). Note that Guava does not allow providing a Comparator so they voted the other way on this.<br></div><div><br></div><div>The start() and end() be should be specifiable as either inclusive or exclusive, otherwise open bounds are not possible. For example, how would one express the range of all Strings strictly less than "zzz"? (note every element in the infinite sequence "zzy", "zzyy", "zzyyy", ... is less than "zzz"). This is why for example NavigableSet.subSet() has parameters for that.<br></div><div><br></div><div>I've never encountered a negative range and am skeptical that it would actually be useful. What's an example of a real-world use case? I don't see how they would help diagrams visualization other than maybe saving you a boolean, i.e., you could just use the normal range and draw the arrow the other way.<br></div><br></div><div>In my experience, when you work with ranges you often also need to work with sets of ranges. If we had a Range class then it would be natural to also have a RangeSet class as well with union, intersection, difference, and ordered iteration operations, etc.</div><div><br></div><div>-Archie<br></div></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>
</blockquote></div>
</blockquote></div>