From 05fbcfc933923ae711cd12e7fc9e587fd8e2685c Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Wed, 4 Mar 2026 05:05:13 -0800 Subject: [PATCH] feat: Adding a Builder for EventsCompactionConfig PiperOrigin-RevId: 878430680 --- .../summarizer/EventsCompactionConfig.java | 31 +++++++++++ .../EventsCompactionConfigTest.java | 55 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 core/src/test/java/com/google/adk/summarizer/EventsCompactionConfigTest.java diff --git a/core/src/main/java/com/google/adk/summarizer/EventsCompactionConfig.java b/core/src/main/java/com/google/adk/summarizer/EventsCompactionConfig.java index b61cd2008..39698c3db 100644 --- a/core/src/main/java/com/google/adk/summarizer/EventsCompactionConfig.java +++ b/core/src/main/java/com/google/adk/summarizer/EventsCompactionConfig.java @@ -16,6 +16,8 @@ package com.google.adk.summarizer; +import com.google.auto.value.AutoBuilder; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import javax.annotation.Nullable; /** @@ -39,6 +41,35 @@ public record EventsCompactionConfig( @Nullable Integer tokenThreshold, @Nullable Integer eventRetentionSize) { + public static Builder builder() { + return new AutoBuilder_EventsCompactionConfig_Builder(); + } + + public Builder toBuilder() { + return new AutoBuilder_EventsCompactionConfig_Builder(this); + } + + /** Builder for {@link EventsCompactionConfig}. */ + @AutoBuilder + public abstract static class Builder { + @CanIgnoreReturnValue + public abstract Builder compactionInterval(@Nullable Integer compactionInterval); + + @CanIgnoreReturnValue + public abstract Builder overlapSize(@Nullable Integer overlapSize); + + @CanIgnoreReturnValue + public abstract Builder summarizer(@Nullable BaseEventSummarizer summarizer); + + @CanIgnoreReturnValue + public abstract Builder tokenThreshold(@Nullable Integer tokenThreshold); + + @CanIgnoreReturnValue + public abstract Builder eventRetentionSize(@Nullable Integer eventRetentionSize); + + public abstract EventsCompactionConfig build(); + } + public EventsCompactionConfig(int compactionInterval, int overlapSize) { this(compactionInterval, overlapSize, null, null, null); } diff --git a/core/src/test/java/com/google/adk/summarizer/EventsCompactionConfigTest.java b/core/src/test/java/com/google/adk/summarizer/EventsCompactionConfigTest.java new file mode 100644 index 000000000..01f59d37a --- /dev/null +++ b/core/src/test/java/com/google/adk/summarizer/EventsCompactionConfigTest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.adk.summarizer; + +import static com.google.common.truth.Truth.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class EventsCompactionConfigTest { + + @Test + public void builder_buildsConfig() { + EventsCompactionConfig config = + EventsCompactionConfig.builder() + .compactionInterval(10) + .overlapSize(2) + .tokenThreshold(100) + .eventRetentionSize(5) + .build(); + + assertThat(config.compactionInterval()).isEqualTo(10); + assertThat(config.overlapSize()).isEqualTo(2); + assertThat(config.tokenThreshold()).isEqualTo(100); + assertThat(config.eventRetentionSize()).isEqualTo(5); + assertThat(config.summarizer()).isNull(); + } + + @Test + public void toBuilder_rebuildsConfig() { + EventsCompactionConfig config = + EventsCompactionConfig.builder().compactionInterval(10).overlapSize(2).build(); + + EventsCompactionConfig rebuilt = config.toBuilder().compactionInterval(20).build(); + + assertThat(rebuilt.compactionInterval()).isEqualTo(20); + assertThat(rebuilt.overlapSize()).isEqualTo(2); + } +}