Skip to content

Commit 9cef813

Browse files
tilgalascopybara-github
authored andcommitted
refactor: modify SessionUtils.toContent method to accept Nullable
PiperOrigin-RevId: 882142571
1 parent d9d84ee commit 9cef813

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

core/src/main/java/com/google/adk/sessions/SessionUtils.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Base64;
2525
import java.util.List;
2626
import java.util.Optional;
27+
import org.jspecify.annotations.Nullable;
2728

2829
/** Utility functions for session service. */
2930
public final class SessionUtils {
@@ -53,7 +54,7 @@ public static Content encodeContent(Content content) {
5354
encodedParts.add(part);
5455
}
5556
}
56-
return toContent(encodedParts, content.role());
57+
return toContent(encodedParts, content.role().orElse(null));
5758
}
5859

5960
/** Decodes Base64-encoded inline blobs in content. */
@@ -79,13 +80,15 @@ public static Content decodeContent(Content content) {
7980
decodedParts.add(part);
8081
}
8182
}
82-
return toContent(decodedParts, content.role());
83+
return toContent(decodedParts, content.role().orElse(null));
8384
}
8485

8586
/** Builds content from parts and optional role. */
86-
private static Content toContent(List<Part> parts, Optional<String> role) {
87+
private static Content toContent(List<Part> parts, @Nullable String role) {
8788
Content.Builder contentBuilder = Content.builder().parts(parts);
88-
role.ifPresent(contentBuilder::role);
89+
if (role != null) {
90+
contentBuilder.role(role);
91+
}
8992
return contentBuilder.build();
9093
}
9194
}

0 commit comments

Comments
 (0)