<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">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">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>