Skip to content

chore: more java 21 idiomatic code #2143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2025
Merged

Conversation

robfrank
Copy link
Collaborator

@robfrank robfrank commented Apr 8, 2025

What does this PR do?

Propose more Jaba 21 idiomatic code

  • use getFirst(), getLast() and removeFirst() on collections
  • more switch expression
  • adds RID/CAT/TYPE_PROPERTY constants for @rid, @cat and @type

Motivation

Clean up the code base

Checklist

  • I have run the build using mvn clean package command
  • My unit tests cover both failure and success scenarios

Copy link

codacy-production bot commented Apr 8, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.75% 33.01%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (8ec8c2b) 69890 43915 62.83%
Head commit (eebc4a1) 69891 (+1) 44442 (+527) 63.59% (+0.75%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#2143) 1224 404 33.01%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@robfrank robfrank force-pushed the improvement/0000-chore-java-21 branch 4 times, most recently from 31ed06e to 433252c Compare April 14, 2025 08:37
@robfrank robfrank requested a review from Copilot April 14, 2025 08:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 134 out of 134 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (5)

engine/src/main/java/com/arcadedb/index/TypeIndex.java:499

  • Ensure that 'indexesOnBuckets' is of a type that supports getFirst() (e.g. LinkedList) as replacing get(0) may cause incompatibility if it remains an ArrayList.
return indexesOnBuckets.getFirst();

engine/src/main/java/com/arcadedb/engine/PageManagerFlushThread.java:52

  • Ensure that the 'pages' list is of a type that supports getFirst(); otherwise, consider using pages.get(0) if pages is an ArrayList.
this.database = pages == null || pages.isEmpty() ? null : pages.getFirst().pageId.getDatabase();

engine/src/main/java/com/arcadedb/engine/LocalBucket.java:1719

  • Verify that 'orderedRecordContentInPage' supports getLast(); if it is an ArrayList, this call will not compile. Consider using get(orderedRecordContentInPage.size()-1) if necessary.
final int[] lastRecord = orderedRecordContentInPage.getLast();

engine/src/main/java/com/arcadedb/database/TransactionContext.java:194

  • Confirm that the 'transactions' list supports removeLast(); if it is an ArrayList, this will fail at runtime. Consider using an appropriate collection type (e.g. Deque or LinkedList).
return transactions.removeLast();

console/src/test/java/com/arcadedb/console/TerminalParser.java:91

  • Verify that the 'words' collection’s implementation supports getLast(); if it is an ArrayList, use get(words.size() - 1).
wordCursor = words.getLast().length();

@robfrank robfrank force-pushed the improvement/0000-chore-java-21 branch from 433252c to 15b830b Compare April 22, 2025 15:43
@robfrank robfrank added the enhancement New feature or request label Apr 22, 2025
@robfrank robfrank added this to the 25.5.1 milestone Apr 22, 2025
@robfrank robfrank marked this pull request as ready for review April 22, 2025 16:07
@robfrank robfrank requested a review from Copilot April 22, 2025 21:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates various parts of the codebase to use Java 21 idiomatic features for list handling and to standardize the usage of metadata property constants. It replaces index‐based list access (e.g. get(0), get(size()-1), add(0)) with the newer getFirst(), getLast(), and addFirst() methods, and also updates hard-coded metadata keys to use defined constants.

  • Updated list element retrieval and insertion throughout the code.
  • Replaced string literals for metadata keys with constants.

Reviewed Changes

Copilot reviewed 134 out of 134 changed files in this pull request and generated no comments.

Show a summary per file
File Description
engine/src/main/java/com/arcadedb/index/vector/HnswVectorIndex.java Replaces index‐based insertion with addFirst() for improved clarity.
engine/src/main/java/com/arcadedb/index/TypeIndex.java Uses getFirst() to retrieve the initial index element.
engine/src/main/java/com/arcadedb/index/MultiIndexCursor.java Updates list accesses from get(0) to getFirst() for several lists.
engine/src/main/java/com/arcadedb/graph/MutableEdgeSegment.java Updates metadata key usage to reference RID_PROPERTY.
engine/src/main/java/com/arcadedb/engine/PageManagerFlushThread.java Replaces pages.get(0) with getFirst() for accessing the first page.
engine/src/main/java/com/arcadedb/engine/LocalBucket.java Replaces access to the last element using get(size()-1) with getLast().
engine/src/main/java/com/arcadedb/engine/Dictionary.java Uses getFirst() instead of get(0) for dictionary key indexing.
engine/src/main/java/com/arcadedb/database/RID.java Updates list access for bucketId and integer checking with getFirst().
engine/src/main/java/com/arcadedb/database/MutableDocument.java Replaces metadata keys with constant-based keys.
engine/src/main/java/com/arcadedb/database/ImmutableDocument.java Replaces metadata keys with constants.
engine/src/main/java/com/arcadedb/database/DetachedDocument.java Uses RID_PROPERTY constant instead of hard-coded '@Rid'.
engine/src/main/java/com/arcadedb/database/DatabaseContext.java Replaces list operations on transactions with getFirst(), getLast(), and removeLast().
engine/src/main/java/com/arcadedb/Profiler.java Updates the method call for CPU load retrieval.
engine/src/main/java/com/arcadedb/GlobalConfiguration.java Uses Set.of() with a simplified array initializer syntax.
e2e/src/test/java/com/arcadedb/e2e/RemoteDatabaseJavaApiTest.java Modifies test annotations and minor formatting.
e2e/src/test/java/com/arcadedb/e2e/JdbcQueriesTest.java Uses the new string formatting style with .formatted().
console/src/test/java/com/arcadedb/console/ConsoleAsyncInsertTest.java Uses constant-based keys and streamlined lambda expressions.
console/src/test/java/com/arcadedb/console/TerminalParser.java Updates list access to use getLast().
Comments suppressed due to low confidence (1)

engine/src/main/java/com/arcadedb/index/vector/HnswVectorIndex.java:560

  • The list 'results' is instantiated as an ArrayList, which does not support the addFirst() method. Consider changing the declaration to a LinkedList (or a Deque) so that addFirst() is available, or revert to using results.add(0, ...) if appropriate.
results.addFirst(new SearchResult<>(loadVertexFromRID(pair.nodeId), pair.distance, maxValueDistanceComparator));

@robfrank robfrank requested a review from lvca April 22, 2025 22:16
@lvca lvca merged commit e281005 into main Apr 24, 2025
10 of 11 checks passed
@robfrank robfrank deleted the improvement/0000-chore-java-21 branch June 20, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants