rmuir commented on PR #14193:
URL: https://github.com/apache/lucene/pull/14193#issuecomment-2638323042

   OK I tried out a List-based API  as alternative to array-based API. It isn't 
fully correct, which is part of my issue, but see it here: 
https://github.com/apache/lucene/commit/8b535a1c2fb4008dbe4e0b007ac95155dfe640ba
   
   I was excited that it might cleanup the code, but it presented some 
problems. I think most problems are because we are talking about `int` arrays 
(codepoint ranges), but common use cases will of course use java `char`. 
   
   array-based API:
   ```java
   Automata.makeCharSet(new int[] {'a', 'A'});
   ```
   
   List-based API:
   ```java
   Automata.makeCharSet(List.of((int) 'a', (int) 'A'));
   ```
   
   It requires user to make casts because the boxed types in java suck.
   
   Also I'm not happy that with the List-based API, error-prone keeps catching 
me doing this:
   ```
   error: [BoxedPrimitiveEquality] Comparison using reference equality instead 
of value equality. Reference equality of boxed primitive types is usually not 
useful, as they are value objects, and it is bug-prone, as instances are cached 
for some values but not others.
             if (from.get(i) == to.get(i)) {
                             ^
       (see https://errorprone.info/bugpattern/BoxedPrimitiveEquality)
     Did you mean 'if (Objects.equals(from.get(i), to.get(i))) {' or 'if 
(from.get(i).equals(to.get(i))) {'?
   ```
   
   It happens because I keep forgetting to call `.intValue()` in special places.
   
   So, I'd like to stick with array API, net-net I think it is better. I will 
look at messy List code that I have in this parser and see if I can improve 
that to reduce chances of problems when parsing lists of ranges. I also have 
other changes in that commit that are unrelated good ones and will poach them 
into here.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to