Re: RFR: 8317611: Add a tool like jdeprscan to find usage of restricted methods [v5]

2024-06-20 Thread Evemose
On Thu, 20 Jun 2024 12:11:25 GMT, Jorn Vernee  wrote:

>> This PR adds a new JDK tool, called `jnativescan`, that can be used to find 
>> code that accesses native functionality. Currently this includes `native` 
>> method declarations, and methods marked with `@Restricted`.
>> 
>> The tool accepts a list of class path and module path entries through 
>> `--class-path` and `--module-path`, and a set of root modules through 
>> `--add-modules`, as well as an optional target release with `--release`.
>> 
>> The default mode is for the tool to report all uses of `@Restricted` 
>> methods, and `native` method declaration in a tree-like structure:
>> 
>> 
>> app.jar (ALL-UNNAMED):
>>   main.Main:
>> main.Main::main(String[])void references restricted methods:
>>   java.lang.foreign.MemorySegment::reinterpret(long)MemorySegment
>> main.Main::m()void is a native method declaration
>> 
>> 
>> The `--print-native-access` option can be used print out all the module 
>> names of modules doing native access in a comma separated list. For class 
>> path code, this will print out `ALL-UNNAMED`.
>> 
>> Testing: 
>> - `langtools_jnativescan` tests.
>> - Running the tool over jextract's libclang bindings, which use the FFM API, 
>> and thus has a lot of references to `@Restricted` methods.
>> - tier 1-3
>
> Jorn Vernee has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   update man page header to be consisten with the others

Just as a guest here. Just theoretically, wouldn't it be better to create one 
uniform tool to detect all "undesired" APIs. This would be more flexible, and 
potentially could be adapted to use some kind of "meticulous" mode, that will 
also indicate usage of public APIs, that, while never will be removed, are 
recommended to remove in favor of new alternatives (like old Date API or old 
collections". Just a thought btw, not a proposal for now

-

PR Comment: https://git.openjdk.org/jdk/pull/19774#issuecomment-2180594098


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v15]

2024-04-25 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with one additional commit 
since the last revision:

  Revert

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/59cbeb69..9166be30

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=14
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=13-14

  Stats: 1 line in 1 file changed: 0 ins; 1 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v14]

2024-04-25 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with one additional commit 
since the last revision:

  Empty commit to rerun checks

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/d2f358b3..59cbeb69

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=13
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=12-13

  Stats: 1 line in 1 file changed: 1 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v13]

2024-04-24 Thread Evemose
On Wed, 24 Apr 2024 12:00:47 GMT, Evemose  wrote:

>> **Subject**
>> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
>> `java.util.List`
>> 
>> **Motivation**
>> The motivation behind this proposal is to enhance the functionality of the 
>> `List` interface by providing a more flexible way to find the index of an 
>> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
>> object as a parameter. This limits the flexibility of these methods as they 
>> can only find the index of exact object matches.
>> 
>> The proposed methods would accept a `Predicate` as a parameter, allowing 
>> users to define a condition that the desired element must meet. This would 
>> provide a more flexible and powerful way to find the index of an element in 
>> a list.
>> 
>> Here is a brief overview of the changes made in this pull request:
>> 
>> 1. Added the `indexOf(Predicate filter)` method to the `List` 
>> interface.
>> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
>> interface.
>> 3. Implemented these methods in all non-abstract classes that implement the 
>> `List` interface.
>> 
>> The changes have been thoroughly tested to ensure they work as expected and 
>> do not introduce any regressions. The test cases cover a variety of 
>> scenarios to ensure the robustness of the implementation.
>> 
>> For example, consider the following test case:
>> 
>> List list = new ArrayList<>();
>> list.add("Object one");
>> list.add("NotObject two");
>> list.add("NotObject three");
>> 
>> int index1 = list.indexOf(s -> s.contains("ct t"));
>> System.out.println(index1); // Expected output: 1
>> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
>> System.out.println(index2); // Expected output: 2
>> 
>> 
>> Currently, to achieve the same result, we would have to use a more verbose 
>> approach:
>> 
>> int index1 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).contains("ct t"))
>>  .findFirst()
>>  .orElse(-1);
>> System.out.println(index1); // Output: 1
>> int index2 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).startsWith("NotObject"))
>>      .reduce((first, second) -> second)
>>  .orElse(-1);
>> System.out.println(index2); // Output: 2
>> 
>> 
>> I believe these additions would greatly enhance the functionality and 
>> flexibility of the `List` interface, making it more powerful and 
>> user-friendly. I look forward to your feedback and am open to making any 
>> necessary changes bas...
>
> Evemose has updated the pull request incrementally with two additional 
> commits since the last revision:
> 
>  - ArrayList made findIndexInRange private
>
>Co-authored-by: ExE Boss <3889017+exe-b...@users.noreply.github.com>
>  - ArrayList made findLastIndexInRange private
>
>Co-authored-by: ExE Boss <3889017+exe-b...@users.noreply.github.com>

Seems like run failed due to internal problems of openjdk. I will trigger rerun 
a bit later.

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2074989809


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v13]

2024-04-24 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with two additional commits 
since the last revision:

 - ArrayList made findIndexInRange private
   
   Co-authored-by: ExE Boss <3889017+exe-b...@users.noreply.github.com>
 - ArrayList made findLastIndexInRange private
   
   Co-authored-by: ExE Boss <3889017+exe-b...@users.noreply.github.com>

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/349ee6bd..d2f358b3

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=12
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=11-12

  Stats: 2 lines in 1 file changed: 0 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v12]

2024-04-24 Thread Evemose
On Tue, 23 Apr 2024 13:54:42 GMT, Evemose  wrote:

>> **Subject**
>> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
>> `java.util.List`
>> 
>> **Motivation**
>> The motivation behind this proposal is to enhance the functionality of the 
>> `List` interface by providing a more flexible way to find the index of an 
>> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
>> object as a parameter. This limits the flexibility of these methods as they 
>> can only find the index of exact object matches.
>> 
>> The proposed methods would accept a `Predicate` as a parameter, allowing 
>> users to define a condition that the desired element must meet. This would 
>> provide a more flexible and powerful way to find the index of an element in 
>> a list.
>> 
>> Here is a brief overview of the changes made in this pull request:
>> 
>> 1. Added the `indexOf(Predicate filter)` method to the `List` 
>> interface.
>> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
>> interface.
>> 3. Implemented these methods in all non-abstract classes that implement the 
>> `List` interface.
>> 
>> The changes have been thoroughly tested to ensure they work as expected and 
>> do not introduce any regressions. The test cases cover a variety of 
>> scenarios to ensure the robustness of the implementation.
>> 
>> For example, consider the following test case:
>> 
>> List list = new ArrayList<>();
>> list.add("Object one");
>> list.add("NotObject two");
>> list.add("NotObject three");
>> 
>> int index1 = list.indexOf(s -> s.contains("ct t"));
>> System.out.println(index1); // Expected output: 1
>> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
>> System.out.println(index2); // Expected output: 2
>> 
>> 
>> Currently, to achieve the same result, we would have to use a more verbose 
>> approach:
>> 
>> int index1 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).contains("ct t"))
>>  .findFirst()
>>  .orElse(-1);
>> System.out.println(index1); // Output: 1
>> int index2 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).startsWith("NotObject"))
>>      .reduce((first, second) -> second)
>>  .orElse(-1);
>> System.out.println(index2); // Output: 2
>> 
>> 
>> I believe these additions would greatly enhance the functionality and 
>> flexibility of the `List` interface, making it more powerful and 
>> user-friendly. I look forward to your feedback and am open to making any 
>> necessary changes bas...
>
> Evemose has updated the pull request incrementally with three additional 
> commits since the last revision:
> 
>  - Added Objects import to sun List
>  - Replaced on-demand import in com.sunList
>  - added non-null assertions

Commited proposed changes. Also still would appreciate any help about what to 
write it csr template (you can see what I figured a few messages above)

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2074774403


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v12]

2024-04-24 Thread Evemose
On Tue, 23 Apr 2024 20:30:22 GMT, ExE Boss  wrote:

>> Evemose has updated the pull request incrementally with three additional 
>> commits since the last revision:
>> 
>>  - Added Objects import to sun List
>>  - Replaced on-demand import in com.sunList
>>  - added non-null assertions
>
> src/java.base/share/classes/java/util/ArrayList.java line 380:
> 
>> 378: }
>> 379: 
>> 380: int findLastIndexInRange(Predicate filter, int start, 
>> int end) {
> 
> Suggestion:
> 
> private int findLastIndexInRange(Predicate filter, int start, 
> int end) {

Yeah i though about it but indexOfRange arent private here so either there is a 
point in it or its just legacy without any particular meaning

-

PR Review Comment: https://git.openjdk.org/jdk/pull/18639#discussion_r1577501340


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v11]

2024-04-23 Thread Evemose
On Fri, 19 Apr 2024 22:27:15 GMT, xxDark  wrote:

>>> I noticed that most (if not all) methods don't ensure non-nullability of 
>>> `filter` so NPE would only be thrown if the list is not empty.
>> 
>> Yeah, thats true. not sure if it has to throw NPE even if list is emply
>
>> > I noticed that most (if not all) methods don't ensure non-nullability of 
>> > `filter` so NPE would only be thrown if the list is not empty.
>> 
>> Yeah, thats true. not sure if it has to throw NPE even if list is emply
> 
> Yes, it does. If it shouldn't, then why isn't code in the java.util.List is 
> like this:
> 
> default int findIndex(Predicate filter) {
>   ListIterator iterator = listIterator();
>   if (!iterator.hasNext()) return -1;
>   Objects.requireNonNull(filter);
>   int index = 0;
>   do {
>   if (filter.test(iterator.next()))
>   return index;
>   index++;
>   } while (iterator.hasNext());
>   return -1;
> }
> 
> Also see methods like `removveIf`. All methods should do checks even if they 
> essentially do nothing.

@xxDark Added null asserions everywhere except sublists that delegate execution 
to other lists, except for SynchroziedLsit so it doesnt acquire monitor with 
invalid predicate. I think this would be the best choice

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2067762652


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v2]

2024-04-23 Thread Evemose
On Fri, 19 Apr 2024 12:10:34 GMT, Chen Liang  wrote:

>> @minborg Sorry to bother you with this kind of question, but i cant manage 
>> to find where exactly and how I can file CSR review request. Could you help 
>> me out?
>
> @Evemose Please revert formatting changes in existing classes. Unfortunately 
> there's no single code style across all of JDK, but you shouldn't try to 
> format code/methods that's not touched by your new method addition.

@liach Seems like discussion in mails has came to some conclusion (or people 
just arent interested in it anymore). Therefore, i think its time to file for 
csr. Here is a draft request text, but Im not sure how to fill in some fields:
Summary: Add findIndex(Predicate) and findLastIndex(Predicate) to List
Problem: Modification of java.utilList interface by adding findIndex(Predicate) 
and findLastIndex(Predicate) methods might introduce behavioural or byteecode 
incompatibilities
Solution: // dont know what to write here tbh
Specification: // do i have to paste changed code here, or provide links, or 
what?
Alternatives: syntax line indexOf(Predicate) and lastIndexOf(Predicate) was 
concidered, but discarded due to behavioural incompatibilities with invokation 
indexOf(null)

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2072079213


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v11]

2024-04-23 Thread Evemose
On Fri, 19 Apr 2024 15:49:11 GMT, Evemose  wrote:

>> **Subject**
>> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
>> `java.util.List`
>> 
>> **Motivation**
>> The motivation behind this proposal is to enhance the functionality of the 
>> `List` interface by providing a more flexible way to find the index of an 
>> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
>> object as a parameter. This limits the flexibility of these methods as they 
>> can only find the index of exact object matches.
>> 
>> The proposed methods would accept a `Predicate` as a parameter, allowing 
>> users to define a condition that the desired element must meet. This would 
>> provide a more flexible and powerful way to find the index of an element in 
>> a list.
>> 
>> Here is a brief overview of the changes made in this pull request:
>> 
>> 1. Added the `indexOf(Predicate filter)` method to the `List` 
>> interface.
>> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
>> interface.
>> 3. Implemented these methods in all non-abstract classes that implement the 
>> `List` interface.
>> 
>> The changes have been thoroughly tested to ensure they work as expected and 
>> do not introduce any regressions. The test cases cover a variety of 
>> scenarios to ensure the robustness of the implementation.
>> 
>> For example, consider the following test case:
>> 
>> List list = new ArrayList<>();
>> list.add("Object one");
>> list.add("NotObject two");
>> list.add("NotObject three");
>> 
>> int index1 = list.indexOf(s -> s.contains("ct t"));
>> System.out.println(index1); // Expected output: 1
>> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
>> System.out.println(index2); // Expected output: 2
>> 
>> 
>> Currently, to achieve the same result, we would have to use a more verbose 
>> approach:
>> 
>> int index1 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).contains("ct t"))
>>  .findFirst()
>>  .orElse(-1);
>> System.out.println(index1); // Output: 1
>> int index2 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).startsWith("NotObject"))
>>      .reduce((first, second) -> second)
>>  .orElse(-1);
>> System.out.println(index2); // Output: 2
>> 
>> 
>> I believe these additions would greatly enhance the functionality and 
>> flexibility of the `List` interface, making it more powerful and 
>> user-friendly. I look forward to your feedback and am open to making any 
>> necessary changes bas...
>
> Evemose has updated the pull request incrementally with one additional commit 
> since the last revision:
> 
>   reverted code style changes in Vector

> > > I noticed that most (if not all) methods don't ensure non-nullability of 
> > > `filter` so NPE would only be thrown if the list is not empty.
> > 
> > 
> > Yeah, thats true. not sure if it has to throw NPE even if list is emply
> 
> Yes, it does. If it shouldn't, then why isn't code in the java.util.List is 
> like this:
> 
> ```java
> default int findIndex(Predicate filter) {
>   ListIterator iterator = listIterator();
>   if (!iterator.hasNext()) return -1;
>   Objects.requireNonNull(filter);
>   int index = 0;
>   do {
>   if (filter.test(iterator.next()))
>   return index;
>   index++;
>   } while (iterator.hasNext());
>   return -1;
> }
> ```
> 
> Also see methods like `removveIf`. All methods should do checks even if they 
> essentially do nothing.

ok, i will fix this in a while

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2067357432


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v11]

2024-04-23 Thread Evemose
On Fri, 19 Apr 2024 21:36:42 GMT, xxDark  wrote:

> I noticed that most (if not all) methods don't ensure non-nullability of 
> `filter` so NPE would only be thrown if the list is not empty.

Yeah, thats true. not sure if it has to throw NPE even if list is emply

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2067350248


Re: RFR: 8329760: Add indexOf(Predicate filter) to java.util.List interface [v12]

2024-04-23 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with three additional 
commits since the last revision:

 - Added Objects import to sun List
 - Replaced on-demand import in com.sunList
 - added non-null assertions

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/de6e18e7..349ee6bd

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=11
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=10-11

  Stats: 29 lines in 8 files changed: 27 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v10]

2024-04-19 Thread Evemose
On Fri, 19 Apr 2024 15:39:12 GMT, Evemose  wrote:

>> **Subject**
>> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
>> `java.util.List`
>> 
>> **Motivation**
>> The motivation behind this proposal is to enhance the functionality of the 
>> `List` interface by providing a more flexible way to find the index of an 
>> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
>> object as a parameter. This limits the flexibility of these methods as they 
>> can only find the index of exact object matches.
>> 
>> The proposed methods would accept a `Predicate` as a parameter, allowing 
>> users to define a condition that the desired element must meet. This would 
>> provide a more flexible and powerful way to find the index of an element in 
>> a list.
>> 
>> Here is a brief overview of the changes made in this pull request:
>> 
>> 1. Added the `indexOf(Predicate filter)` method to the `List` 
>> interface.
>> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
>> interface.
>> 3. Implemented these methods in all non-abstract classes that implement the 
>> `List` interface.
>> 
>> The changes have been thoroughly tested to ensure they work as expected and 
>> do not introduce any regressions. The test cases cover a variety of 
>> scenarios to ensure the robustness of the implementation.
>> 
>> For example, consider the following test case:
>> 
>> List list = new ArrayList<>();
>> list.add("Object one");
>> list.add("NotObject two");
>> list.add("NotObject three");
>> 
>> int index1 = list.indexOf(s -> s.contains("ct t"));
>> System.out.println(index1); // Expected output: 1
>> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
>> System.out.println(index2); // Expected output: 2
>> 
>> 
>> Currently, to achieve the same result, we would have to use a more verbose 
>> approach:
>> 
>> int index1 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).contains("ct t"))
>>  .findFirst()
>>  .orElse(-1);
>> System.out.println(index1); // Output: 1
>> int index2 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).startsWith("NotObject"))
>>      .reduce((first, second) -> second)
>>  .orElse(-1);
>> System.out.println(index2); // Output: 2
>> 
>> 
>> I believe these additions would greatly enhance the functionality and 
>> flexibility of the `List` interface, making it more powerful and 
>> user-friendly. I look forward to your feedback and am open to making any 
>> necessary changes bas...
>
> Evemose has updated the pull request incrementally with two additional 
> commits since the last revision:
> 
>  - Merge remote-tracking branch 'origin/feature/indexOf-with-predicate' into 
> feature/indexOf-with-predicate
>
># Conflicts:
>#  src/java.base/share/classes/java/util/LinkedList.java
>#  src/java.base/share/classes/java/util/ReverseOrderListView.java
>#  src/java.base/share/classes/java/util/Vector.java
>#  
> test/jdk/java/util/Spliterator/SpliteratorTraversingAndSplittingTest.java
>  - reverted code style changes

Also regarding tests. Not sure if they are needed at all as implementations are 
no longer then 15 lines, but if it is mandatory step, I guess i will add them 
after I finished collecting feedback so I will have final version of what this 
methods behaviour should look like

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2066841853


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v9]

2024-04-19 Thread Evemose
On Fri, 19 Apr 2024 14:11:20 GMT, Roger Riggs  wrote:

>> Evemose has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Update Vector.java
>
> Please revert the formatting as soon as possible; its noise as far as 
> reviewers are concerned. 
> You want reviewers to focus on the suitability of the API and clarity of the 
> specification first, then later on the implementation.  Thanks

@RogerRiggs Been done. It turned out much easier then i though it would

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2066838257


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v11]

2024-04-19 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with one additional commit 
since the last revision:

  reverted code style changes in Vector

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/2c37ecef..de6e18e7

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=10
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=09-10

  Stats: 145 lines in 1 file changed: 5 ins; 13 del; 127 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v10]

2024-04-19 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with two additional commits 
since the last revision:

 - Merge remote-tracking branch 'origin/feature/indexOf-with-predicate' into 
feature/indexOf-with-predicate
   
   # Conflicts:
   #src/java.base/share/classes/java/util/LinkedList.java
   #src/java.base/share/classes/java/util/ReverseOrderListView.java
   #src/java.base/share/classes/java/util/Vector.java
   #
test/jdk/java/util/Spliterator/SpliteratorTraversingAndSplittingTest.java
 - reverted code style changes

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/97b9bff4..2c37ecef

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=09
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=08-09

  Stats: 210 lines in 6 files changed: 11 ins; 44 del; 155 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v9]

2024-04-19 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with one additional commit 
since the last revision:

  Update Vector.java

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/49c4993b..97b9bff4

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=08
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=07-08

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v8]

2024-04-19 Thread Evemose
On Fri, 19 Apr 2024 12:47:12 GMT, Evemose  wrote:

>> **Subject**
>> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
>> `java.util.List`
>> 
>> **Motivation**
>> The motivation behind this proposal is to enhance the functionality of the 
>> `List` interface by providing a more flexible way to find the index of an 
>> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
>> object as a parameter. This limits the flexibility of these methods as they 
>> can only find the index of exact object matches.
>> 
>> The proposed methods would accept a `Predicate` as a parameter, allowing 
>> users to define a condition that the desired element must meet. This would 
>> provide a more flexible and powerful way to find the index of an element in 
>> a list.
>> 
>> Here is a brief overview of the changes made in this pull request:
>> 
>> 1. Added the `indexOf(Predicate filter)` method to the `List` 
>> interface.
>> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
>> interface.
>> 3. Implemented these methods in all non-abstract classes that implement the 
>> `List` interface.
>> 
>> The changes have been thoroughly tested to ensure they work as expected and 
>> do not introduce any regressions. The test cases cover a variety of 
>> scenarios to ensure the robustness of the implementation.
>> 
>> For example, consider the following test case:
>> 
>> List list = new ArrayList<>();
>> list.add("Object one");
>> list.add("NotObject two");
>> list.add("NotObject three");
>> 
>> int index1 = list.indexOf(s -> s.contains("ct t"));
>> System.out.println(index1); // Expected output: 1
>> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
>> System.out.println(index2); // Expected output: 2
>> 
>> 
>> Currently, to achieve the same result, we would have to use a more verbose 
>> approach:
>> 
>> int index1 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).contains("ct t"))
>>  .findFirst()
>>  .orElse(-1);
>> System.out.println(index1); // Output: 1
>> int index2 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).startsWith("NotObject"))
>>      .reduce((first, second) -> second)
>>  .orElse(-1);
>> System.out.println(index2); // Output: 2
>> 
>> 
>> I believe these additions would greatly enhance the functionality and 
>> flexibility of the `List` interface, making it more powerful and 
>> user-friendly. I look forward to your feedback and am open to making any 
>> necessary changes bas...
>
> Evemose has updated the pull request incrementally with two additional 
> commits since the last revision:
> 
>  - Update SpliteratorTraversingAndSplittingTest.java
>  - Update Arrays.java

I requested post in core-libs-dev. I guess I will wait a week or two to gather 
feedback of community before filing for CSR

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2066509181


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v8]

2024-04-19 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with two additional commits 
since the last revision:

 - Update SpliteratorTraversingAndSplittingTest.java
 - Update Arrays.java

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/625c5b46..49c4993b

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=07
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=06-07

  Stats: 2 lines in 2 files changed: 2 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v2]

2024-04-19 Thread Evemose
On Fri, 19 Apr 2024 12:10:34 GMT, Chen Liang  wrote:

>> @minborg Sorry to bother you with this kind of question, but i cant manage 
>> to find where exactly and how I can file CSR review request. Could you help 
>> me out?
>
> @Evemose Please revert formatting changes in existing classes. Unfortunately 
> there's no single code style across all of JDK, but you shouldn't try to 
> format code/methods that's not touched by your new method addition.

@liach i did revert changes where it was possible but in few files it will be 
just too resource-consuming to revert indentations to previous state. If this 
will be crucial, ill deal with it before merging

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2066480208


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v7]

2024-04-19 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with two additional commits 
since the last revision:

 - Update CopyOnWriteArrayList.java
 - Reformat LinkedList.java

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/d7f5e97e..625c5b46

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=06
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=05-06

  Stats: 2 lines in 2 files changed: 0 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v6]

2024-04-19 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with 14 additional commits 
since the last revision:

 - Update LinkedList.java
 - Update LinkedList.java
 - Reformat LinkedList.java
 - Removed trailing whitespace in Collections.java
 - Update CopyOnWriteArrayList.java
 - Reformated imports in Vector.java
 - Reformated imports in CopyOnWriteArrayList.java
 - Removed on-demand import from SpliteratorTraversingAndSplittingTest.java
 - Update ListFactories.java
 - Update ReverseOrderListView.java
 - ... and 4 more: https://git.openjdk.org/jdk/compare/5beec920...d7f5e97e

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/5beec920..d7f5e97e

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=05
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=04-05

  Stats: 59 lines in 7 files changed: 33 ins; 6 del; 20 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v5]

2024-04-19 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with one additional commit 
since the last revision:

  Fixed javadocs in LinkedList.java

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/34b3695f..5beec920

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=04
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=03-04

  Stats: 5 lines in 1 file changed: 0 ins; 0 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v4]

2024-04-19 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with one additional commit 
since the last revision:

  Fixed javadocs in ArrayList

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/5fcdfd87..34b3695f

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=03
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=02-03

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v3]

2024-04-19 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards
> 
> PS: In ...

Evemose has updated the pull request incrementally with one additional commit 
since the last revision:

  Removed extra line from previous commit

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/21ce4892..5fcdfd87

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=02
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=01-02

  Stats: 1 line in 1 file changed: 0 ins; 1 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v2]

2024-04-19 Thread Evemose
On Fri, 19 Apr 2024 09:39:40 GMT, Per Minborg  wrote:

>> Evemose has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   empty commit to trigger check rerun
>
> Adding (default) methods to `List` would have significant compatibility 
> ramifications. Also, the PR needs to contain significant testing of the new 
> proposed methods.

@minborg Sorry to bother you with this kind of question, but i cant manage to 
find where exactly and how I can file CSR review request. Could you help me out?

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2066385281


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface [v2]

2024-04-18 Thread Evemose
> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards

Evemose has updated the pull request incrementally with one additional commit 
since the last revision:

  empty commit to trigger check rerun

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18639/files
  - new: https://git.openjdk.org/jdk/pull/18639/files/025bcf39..21ce4892

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=18639=01
 - incr: https://webrevs.openjdk.org/?repo=jdk=18639=00-01

  Stats: 1 line in 1 file changed: 1 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface

2024-04-18 Thread Evemose
On Tue, 9 Apr 2024 22:02:56 GMT, xxDark  wrote:

> This does not solve the problem though. Source compatibility would still be 
> broken as one would still need to add casts everywhere, or am I 
> misinterpreting something?

The code you have provided in example is still valid and non-ambigous, even 
without cast. The default behaviour of java compiler is to choose method where 
parameter at corresponding position is closest type upwards in class hierarchy. 
null is considered "bottom" type, which means it is at the bottom of 
simultaneously every class hierarchy. Compiler looks upward in class hierarchy 
and first class it encounters is Predicate, as Object is superclass of 
Predicate, and chooses indexOf(Predicate) as method to invoke. When casting 
null to type, compiler treats null as object of casted type rather then bottom 
type. However, if changes are delivered as is, default behaviour of 
indexOf(null) will be changed, which is not desired, of course, and, although 
delegation to indexOf(Object) in case of null as passed value is 
counterintuitive, it will preserve the current state of things.

> See 
> [this](https://github.com/search?q=%22indexOf%28null%29%22+language%3AJava+=code)
>  and 
> [that](https://github.com/search?q=%22lastIndexOf%28null%29%22+language%3AJava+=code)
>  query.

Thats a valid point, haven`t though about qurying where null is valid value.

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2046174903


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface

2024-04-18 Thread Evemose
On Wed, 10 Apr 2024 11:20:32 GMT, xxDark  wrote:

> Should be `findIndex`? Similarly with `findLastIndex`.

Yeah i guess IDE didnt do a great job with refactor. I will review aall changes 
manually a bit later

-

PR Review Comment: https://git.openjdk.org/jdk/pull/18639#discussion_r1559373902


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface

2024-04-18 Thread Evemose
On Tue, 9 Apr 2024 20:48:19 GMT, Chen Liang  wrote:

> A few remarks:
> 
> 1. The concern on `indexOf(Object)` and `indexOf(Predicate)` is valid; 
> `Optional` has `orElse` vs. `orElseGet` to avoid these clashes. The behavior 
> change of `indexOf(null)` is a source incompatibility.
> 2. Have you considered `indexOf(predicate/object, startIndex)` like the 
> indexOf for `String`?
> 
> Also, a significant difference between String/arrays and `List` is that 
> `List` is structurally modifiable; the index may be no longer valid after a 
> modification. Thus the index is not as useful.
> 
> For example, in an [unrolled linked 
> list](https://en.wikipedia.org/wiki/Unrolled_linked_list) implementation, 
> each block can be independently locked for read/write access, maybe like 
> this: `[1, 2, 3] -> [4, 5] -> [6, 7, 8, 9]` An index would be useless if any 
> part of this list updates, but if the position information is stored in a 
> `ListIterator` and we add an `beforeNext(predicate)` that moves the cursor to 
> right before the next element that matches the predicate (or the tail if 
> there's no match), this would be much more useful.

The concern about change in behaviour of indexOf(null) is completely valid, 
although indexOf(null) is kind of exotic scenario. One possible workaround is 
to temporally (for an intermidiate period) or permanently delegate null value 
handing to indexOf(Object), which seems odd for me to me tbh, although it 
preserves source compatibility.

Regarding to indexOf(predicate/object, startIndex), i thought about this, but 
firstly I would like to have a final and approved version of indexOf(predicate) 
to have a reference I`m certain in.

As for beforeNext(Predicate) for ListIterator, I havent thought about that, but 
now that you`ve mentioned it, I could also consider implementing such thing. 
However, concern about possible index invalidation is more applicable to the 
nature of indexOf itself rather then this proposal. This method is primarly 
used when index is needed right here and now or passed to operation that is not 
supposed to modify list. I guess ListIterator.beforeNext and List.indexOf serve 
different, altough alike purpose, and therefore, in my opinion, there are place 
for both in Java

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2046103546


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface

2024-04-18 Thread Evemose
On Mon, 8 Apr 2024 03:57:33 GMT, ExE Boss  wrote:

>> **Subject**
>> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
>> `java.util.List`
>> 
>> **Motivation**
>> The motivation behind this proposal is to enhance the functionality of the 
>> `List` interface by providing a more flexible way to find the index of an 
>> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
>> object as a parameter. This limits the flexibility of these methods as they 
>> can only find the index of exact object matches.
>> 
>> The proposed methods would accept a `Predicate` as a parameter, allowing 
>> users to define a condition that the desired element must meet. This would 
>> provide a more flexible and powerful way to find the index of an element in 
>> a list.
>> 
>> Here is a brief overview of the changes made in this pull request:
>> 
>> 1. Added the `indexOf(Predicate filter)` method to the `List` 
>> interface.
>> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
>> interface.
>> 3. Implemented these methods in all non-abstract classes that implement the 
>> `List` interface.
>> 
>> The changes have been thoroughly tested to ensure they work as expected and 
>> do not introduce any regressions. The test cases cover a variety of 
>> scenarios to ensure the robustness of the implementation.
>> 
>> For example, consider the following test case:
>> 
>> List list = new ArrayList<>();
>> list.add("Object one");
>> list.add("NotObject two");
>> list.add("NotObject three");
>> 
>> int index1 = list.indexOf(s -> s.contains("ct t"));
>> System.out.println(index1); // Expected output: 1
>> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
>> System.out.println(index2); // Expected output: 2
>> 
>> 
>> Currently, to achieve the same result, we would have to use a more verbose 
>> approach:
>> 
>> int index1 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).contains("ct t"))
>>  .findFirst()
>>  .orElse(-1);
>> System.out.println(index1); // Output: 1
>> int index2 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).startsWith("NotObject"))
>>  .reduce((first, second) -> second)
>>  .orElse(-1);
>> System.out.println(index2); // Output: 2
>> 
>> 
>> I believe these additions would greatly enhance the functionality and 
>> flexibility of the `List` interface, making it more powerful and 
>> user-friendly. I look forward to your feedback and am open to making any 
>> necessary changes bas...
>
> Newly added methods to existing widely‑implemented non‑sealed and non‑preview 
> interfaces in `java.base` must be `default` to avoid source incompatibilities 
> and runtime errors, so move the implementations from `AbstractList` to `List`:

@ExE-Boss Commited changes. Also, i see you have added not-null assertion at 
the beginning of methods inside List. If this is a desired behaviour, I could 
also add this to other impls

@ExE-Boss removed unused import

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2042094028
PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2042910322


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface

2024-04-18 Thread Evemose
On Fri, 5 Apr 2024 00:31:22 GMT, Evemose  wrote:

>> **Subject**
>> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
>> `java.util.List`
>> 
>> **Motivation**
>> The motivation behind this proposal is to enhance the functionality of the 
>> `List` interface by providing a more flexible way to find the index of an 
>> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
>> object as a parameter. This limits the flexibility of these methods as they 
>> can only find the index of exact object matches.
>> 
>> The proposed methods would accept a `Predicate` as a parameter, allowing 
>> users to define a condition that the desired element must meet. This would 
>> provide a more flexible and powerful way to find the index of an element in 
>> a list.
>> 
>> Here is a brief overview of the changes made in this pull request:
>> 
>> 1. Added the `indexOf(Predicate filter)` method to the `List` 
>> interface.
>> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
>> interface.
>> 3. Implemented these methods in all non-abstract classes that implement the 
>> `List` interface.
>> 
>> The changes have been thoroughly tested to ensure they work as expected and 
>> do not introduce any regressions. The test cases cover a variety of 
>> scenarios to ensure the robustness of the implementation.
>> 
>> For example, consider the following test case:
>> 
>> List list = new ArrayList<>();
>> list.add("Object one");
>> list.add("NotObject two");
>> list.add("NotObject three");
>> 
>> int index1 = list.indexOf(s -> s.contains("ct t"));
>> System.out.println(index1); // Expected output: 1
>> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
>> System.out.println(index2); // Expected output: 2
>> 
>> 
>> Currently, to achieve the same result, we would have to use a more verbose 
>> approach:
>> 
>> int index1 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).contains("ct t"))
>>  .findFirst()
>>  .orElse(-1);
>> System.out.println(index1); // Output: 1
>> int index2 = IntStream.range(0, list.size())
>>  .filter(i -> list.get(i).startsWith("NotObject"))
>>  .reduce((first, second) -> second)
>>  .orElse(-1);
>> System.out.println(index2); // Output: 2
>> 
>> 
>> I believe these additions would greatly enhance the functionality and 
>> flexibility of the `List` interface, making it more powerful and 
>> user-friendly. I look forward to your feedback and am open to making any 
>> necessary changes bas...
>
> side note: looks like this code have been reformated and some unused imports 
> has been reformated. jdk compiles and works just fine, so i guess its not a 
> big deal

> Hello @Evemose, if we add an API we should also consider if implementation 
> can efficiently implement it. How is this new API better than using a 
> ListIterator directly so it's worth the additional methods?

Hi, @liach ! The implementations i provided in this pull requests are pretty 
much imitating behaviour of indexOf(Object). Every class that has overriden 
indexOf(Object) recieved implementation of indexOf(Predicate) that works the 
same way except for search is based on predicate and not equality. Therefore, 
the effectiveness of implementation is straight up depends on effectiveness of 
indexOf(Object) for each separate java.util.List impl.

As for ListIterator, where suitable, it has already been used in 
implementations in classes where it was considered suitable for indexOf(Object) 
(to be more precise, in AbstractList). The main goal of this pull requst is to 
provide shorthand for developers as search for index of element that match 
predicate is very common task and providing way to do it as comfortable as 
possible should vastly enhance development expirience.

For ListIterator specifically: the main downside of its direct usage for 
developer is inability to use it fluently (as method call argument, for 
example), which forces to either implement method to find index separately or 
find it in same method as invocation but before invocation explicitly. Both 
cases are pretty frustraiting and, in my opinion, shouldn`t be neccessary for 
high-level language like Java.

Summarizing, its not that in current stdlib there are no ways to search for 
index of element based on condition, but this addition would be a great way to 
make Java development more comfortable and fast.

PS:
Also implementing indexOf with predicate is a common practice for many high 
level languages: C#/.NET has FindIndex, Kotlin has indexOfFirst, Swift has 
firstIndex etc.

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2040025647


RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface

2024-04-18 Thread Evemose
**Subject**
Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
`java.util.List`

**Motivation**
The motivation behind this proposal is to enhance the functionality of the 
`List` interface by providing a more flexible way to find the index of an 
element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
object as a parameter. This limits the flexibility of these methods as they can 
only find the index of exact object matches.

The proposed methods would accept a `Predicate` as a parameter, allowing users 
to define a condition that the desired element must meet. This would provide a 
more flexible and powerful way to find the index of an element in a list.

Here is a brief overview of the changes made in this pull request:

1. Added the `indexOf(Predicate filter)` method to the `List` 
interface.
2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
interface.
3. Implemented these methods in all non-abstract classes that implement the 
`List` interface.

The changes have been thoroughly tested to ensure they work as expected and do 
not introduce any regressions. The test cases cover a variety of scenarios to 
ensure the robustness of the implementation.

For example, consider the following test case:

List list = new ArrayList<>();
list.add("Object one");
list.add("NotObject two");
list.add("NotObject three");

int index1 = list.indexOf(s -> s.contains("ct t"));
System.out.println(index1); // Expected output: 1
int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
System.out.println(index2); // Expected output: 2


Currently, to achieve the same result, we would have to use a more verbose 
approach:

int index1 = IntStream.range(0, list.size())
 .filter(i -> list.get(i).contains("ct t"))
 .findFirst()
 .orElse(-1);
System.out.println(index1); // Output: 1
int index2 = IntStream.range(0, list.size())
 .filter(i -> list.get(i).startsWith("NotObject"))
 .reduce((first, second) -> second)
 .orElse(-1);
System.out.println(index2); // Output: 2


I believe these additions would greatly enhance the functionality and 
flexibility of the `List` interface, making it more powerful and user-friendly. 
I look forward to your feedback and am open to making any necessary changes 
based on your suggestions.

Thank you for considering this proposal.

Best regards

-

Commit messages:
 - did some renaming of internal methods utilized by findIndex
 - fixed ReverseOrderLinkedListView
 - fixed javadocs in List and ArrayList
 - Merge remote-tracking branch 'origin/feature/indexOf-with-predicate' into 
feature/indexOf-with-predicate
 - Removed unused import in AbstractList
 - Also moved to List interface
 - Moved from AbstractList
 - Removed implementation from AbstractList, moving it to List
 - Renamed indexOf(Predicate) and lastIndexOf(Predicate) to 
findIndex(Predicate) and findLastIndex(Predicate) respectively
 - Merge remote-tracking branch 'origin/feature/indexOf-with-predicate' into 
feature/indexOf-with-predicate
 - ... and 25 more: https://git.openjdk.org/jdk/compare/16576b87...025bcf39

Changes: https://git.openjdk.org/jdk/pull/18639/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk=18639=00
  Issue: https://bugs.openjdk.org/browse/JDK-8329760
  Stats: 882 lines in 13 files changed: 570 ins; 47 del; 265 mod
  Patch: https://git.openjdk.org/jdk/pull/18639.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18639/head:pull/18639

PR: https://git.openjdk.org/jdk/pull/18639


Re: RFR: 8329760: Add indexOf(Predicate filter) to java..util.List interface

2024-04-18 Thread Evemose
On Fri, 5 Apr 2024 00:00:58 GMT, Evemose  wrote:

> **Subject**
> Addition of Predicate-based `indexOf` and `lastIndexOf` methods to 
> `java.util.List`
> 
> **Motivation**
> The motivation behind this proposal is to enhance the functionality of the 
> `List` interface by providing a more flexible way to find the index of an 
> element. Currently, the `indexOf` and `lastIndexOf` methods only accept an 
> object as a parameter. This limits the flexibility of these methods as they 
> can only find the index of exact object matches.
> 
> The proposed methods would accept a `Predicate` as a parameter, allowing 
> users to define a condition that the desired element must meet. This would 
> provide a more flexible and powerful way to find the index of an element in a 
> list.
> 
> Here is a brief overview of the changes made in this pull request:
> 
> 1. Added the `indexOf(Predicate filter)` method to the `List` 
> interface.
> 2. Added the `lastIndexOf(Predicate filter)` method to the `List` 
> interface.
> 3. Implemented these methods in all non-abstract classes that implement the 
> `List` interface.
> 
> The changes have been thoroughly tested to ensure they work as expected and 
> do not introduce any regressions. The test cases cover a variety of scenarios 
> to ensure the robustness of the implementation.
> 
> For example, consider the following test case:
> 
> List list = new ArrayList<>();
> list.add("Object one");
> list.add("NotObject two");
> list.add("NotObject three");
> 
> int index1 = list.indexOf(s -> s.contains("ct t"));
> System.out.println(index1); // Expected output: 1
> int index2 = list.lastIndexOf(s -> s.startsWith("NotObject"));
> System.out.println(index2); // Expected output: 2
> 
> 
> Currently, to achieve the same result, we would have to use a more verbose 
> approach:
> 
> int index1 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).contains("ct t"))
>  .findFirst()
>  .orElse(-1);
> System.out.println(index1); // Output: 1
> int index2 = IntStream.range(0, list.size())
>  .filter(i -> list.get(i).startsWith("NotObject"))
>  .reduce((first, second) -> second)
>  .orElse(-1);
> System.out.println(index2); // Output: 2
> 
> 
> I believe these additions would greatly enhance the functionality and 
> flexibility of the `List` interface, making it more powerful and 
> user-friendly. I look forward to your feedback and am open to making any 
> necessary changes based on your suggestions.
> 
> Thank you for considering this proposal.
> 
> Best regards

currently awaiting for initial issue triage to complete

side note: looks like this code have been reformated and some unused imports 
has been reformated. jdk compiles and works just fine, so i guess its not a big 
deal

> Won't this make some calls ambiguous? For example, passing `null`:
> 
> ```java
> List l;
> l.indexOf(""); // Fine
> l.indexOf(null); // Now fails to compile
> ```
> 
> Edit: I'm not a reviewer, but I decided to point this out.

I`ve tested it. Now calling indexOf with null as literal calls 
indexOf(Predicate) instead, as Predicate is lower in class hierarchy than 
Object (ofc it does not apply to varibles that store null, those works just as 
usual)

If you want to call indexOf(Object) instead, you will have to cast null to 
desired type manually

> ```java
> List l;
> l.indexOf(""); // Fine
> l.indexOf((String)null); // Will invoke indexOf(Object)
> ```

Question to reviewers: what do you think would be the best way to handle issue 
discussed above?

PS: converted PR to draft untill the issue is resolved

PPS: The idea I came up with is to possibly rename indexOf(Predicate) to 
something like findIndex(Predicate) or indexOfMatching(Predicate) as a way to 
both avoid unexpected behaviour and preserve source compatibility

-

PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2038490998
PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2038506989
PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2045522079
PR Comment: https://git.openjdk.org/jdk/pull/18639#issuecomment-2046196342