Skip to content

Commit d726f36

Browse files
committed
core: migrate to JDK17 syntax
1 parent d1f4f2b commit d726f36

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

langchain4j-community-core/src/main/java/dev/langchain4j/community/rag/content/aggregator/strategy/GenerateEmbeddings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public List<EmbeddingMatch<Content>> processContents(
5757

5858
private String getEmbeddingId(Content content) {
5959
Object embeddingId = content.metadata().get(ContentMetadata.EMBEDDING_ID);
60-
if (embeddingId instanceof String && !((String) embeddingId).isBlank()) {
61-
return (String) embeddingId;
60+
if (embeddingId instanceof String string && !string.isBlank()) {
61+
return string;
6262
}
6363
return TEMP_EMBEDDING_ID_PREFIX + Math.abs(content.hashCode());
6464
}

langchain4j-community-core/src/main/java/dev/langchain4j/community/rag/content/aggregator/strategy/HybridEmbeddings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ private List<EmbeddingMatch<Content>> generateMissingEmbeddings(
118118

119119
private String getEmbeddingId(Content content) {
120120
Object embeddingId = content.metadata().get(ContentMetadata.EMBEDDING_ID);
121-
if (embeddingId instanceof String && !((String) embeddingId).isBlank()) {
122-
return (String) embeddingId;
121+
if (embeddingId instanceof String string && !string.isBlank()) {
122+
return string;
123123
}
124124
return TEMP_EMBEDDING_ID_PREFIX + Math.abs(content.hashCode());
125125
}

langchain4j-community-core/src/main/java/dev/langchain4j/community/rag/content/aggregator/strategy/UseExistingEmbeddings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ private Embedding extractEmbeddingFromContent(Content content) {
8080

8181
private String getEmbeddingId(Content content) {
8282
Object embeddingId = content.metadata().get(ContentMetadata.EMBEDDING_ID);
83-
if (embeddingId instanceof String && !((String) embeddingId).isBlank()) {
84-
return (String) embeddingId;
83+
if (embeddingId instanceof String string && !string.isBlank()) {
84+
return string;
8585
}
8686
return TEMP_EMBEDDING_ID_PREFIX + Math.abs(content.hashCode());
8787
}

langchain4j-community-core/src/test/java/dev/langchain4j/community/chain/RetrievalQAChainTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ void should_inject_retrieved_segments_when_content_available() {
8282

8383
verify(chatModel).chat(messagesCaptor.capture());
8484
String expectedUserMessage =
85-
"query\n" + "\n" + "Answer using the following information:\n" + "Segment 1\n" + "\n" + "Segment 2";
85+
"""
86+
query
87+
88+
Answer using the following information:
89+
Segment 1
90+
91+
Segment 2""";
8692
assertThat(messagesCaptor.getValue()).isEqualTo(expectedUserMessage);
8793
}
8894

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
<activeRecipes>
292292
<!--<recipe>org.openrewrite.java.OrderImports</recipe>-->
293293
<recipe>org.openrewrite.java.testing.assertj.Assertj</recipe>
294+
<recipe>org.openrewrite.java.migrate.UpgradeToJava17</recipe>
294295
</activeRecipes>
295296
<failOnDryRunResults>true</failOnDryRunResults>
296297
</configuration>
@@ -300,6 +301,11 @@
300301
<artifactId>rewrite-testing-frameworks</artifactId>
301302
<version>3.18.0</version>
302303
</dependency>
304+
<dependency>
305+
<groupId>org.openrewrite.recipe</groupId>
306+
<artifactId>rewrite-migrate-java</artifactId>
307+
<version>3.18.0</version>
308+
</dependency>
303309
</dependencies>
304310
</plugin>
305311
</plugins>

0 commit comments

Comments
 (0)