<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Kevin,<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’m surprised you even noticed the methods.</blockquote><div><br></div><div>I develop and maintain a collection library, in which I copied checkPositionIndex because it is really commonly used by me.</div><div>I searched my library and found that checkPositionIndex has more than a hundred use cases in my library.</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">And basically, the adoption counts for those methods always remained very low. And I remember seeing a number of misuses, too.</blockquote><div><br></div><div>I was surprised by this information, I thought there should be many places using it.</div><div>Perhaps because it is often needed by other libraries that do not want to add dependencies on Guava.</div><div><br></div><div>This method should be very useful at least for implementing core libraries.</div><div>There are many copies of it in the Java standard library, and I found these just by searching casually:</div><div><ul><li>java.lang.String::checkOffset(int, int)</li><li>java.util.AbstractList.SubList::rangeCheckForAdd(int)</li><li>java.util.ArrayList::rangeCheckForAdd(int)</li><li>java.util.ArrayList.SubList::rangeCheckForAdd(int)</li><li>java.util.LinkedList::checkPositionIndex(int)</li><li>java.util.ImmutableCollections.SubList::rangeCheck(int)</li><li>java.util.ReverseOrderListView::checkClosedRange(int, int)</li><li>java.util.concurrent.CopyOnWriteArrayList.COWSubList::rangeCheckForAdd(int)</li></ul></div><div>There are also some methods that use if...throw directly to check these indexes:</div><div><ul><li>java.lang.AbstractStringBuilder::offsetByCodePoints(int, int)</li><li>java.lang.Character::offsetByCodePoints(CharSequence, int, int)</li><li>java.lang.invoke.MethodType::insertParameterTypes(int, Class<?>...)</li><li>java.util.ImmutableCollections.AbstractImmutableList::listIterator(int)</li><li>java.util.concurrent.CopyOnWriteArrayList::add(int, E)</li><li>java.util.regex.Matcher::find(int)</li></ul></div><div><br></div><div>Glavo</div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, Jan 14, 2025 at 4:19 AM Kevin Bourrillion <<a href="mailto:kevin.bourrillion@oracle.com">kevin.bourrillion@oracle.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>
Oh hey, I named those Guava methods. :-) This was my attempt to promote the terms “position indexes vs. element indexes” and hope that the idea caught on... which I’d say it still never has. I’m surprised you even noticed the methods.
<div><br>
</div>
<div>The notion is that “element indexes” are the buckets and “position indexes” are the possible insertion points
<i>between</i> buckets. I personally find it simpler to think of a method like `subList` as simply accepting two position indexes, rather than thinking about half-open ranges.</div>
<div><br>
</div>
<div>To me this was clarifying, but for people who never have this explained to them it’s probably not that clear.</div>
<div><br>
</div>
<div>And basically, the adoption counts for those methods always remained very low. And I remember seeing a number of misuses, too.</div>
<div><br>
</div>
<div>Not sure what to make of all this; just adding some context.</div>
<div><br>
</div>
<div><br id="m_-8350651927082199173lineBreakAtBeginningOfMessage">
<div><br>
<blockquote type="cite">
<div>On Jan 13, 2025, at 11:36 AM, Glavo <<a href="mailto:zjx001202@gmail.com" target="_blank">zjx001202@gmail.com</a>> wrote:</div>
<br>
<div>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Currently the java.util.Objects provide the method `checkIndex(int, int)` for checking indexes.</div>
<div dir="ltr">It is convenient, but cannot be used to implement methods such as List::add(int, E) because these methods accept an index pointing to the end of the collection.</div>
<div dir="ltr">So is it possible to add a new method to Objects to check this kind of index?</div>
<div dir="ltr">This is useful for implementing collections.</div>
<div dir="ltr">(The checkPositionIndex in the title is its name in guava. I don't like the name, but I don't have a better idea.) </div>
<div dir="ltr"><br>
</div>
<div>Glavo</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>

</blockquote></div>