Skip to content

Commit 05fbcfc

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Adding a Builder for EventsCompactionConfig
PiperOrigin-RevId: 878430680
1 parent 6001b44 commit 05fbcfc

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

core/src/main/java/com/google/adk/summarizer/EventsCompactionConfig.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.adk.summarizer;
1818

19+
import com.google.auto.value.AutoBuilder;
20+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
1921
import javax.annotation.Nullable;
2022

2123
/**
@@ -39,6 +41,35 @@ public record EventsCompactionConfig(
3941
@Nullable Integer tokenThreshold,
4042
@Nullable Integer eventRetentionSize) {
4143

44+
public static Builder builder() {
45+
return new AutoBuilder_EventsCompactionConfig_Builder();
46+
}
47+
48+
public Builder toBuilder() {
49+
return new AutoBuilder_EventsCompactionConfig_Builder(this);
50+
}
51+
52+
/** Builder for {@link EventsCompactionConfig}. */
53+
@AutoBuilder
54+
public abstract static class Builder {
55+
@CanIgnoreReturnValue
56+
public abstract Builder compactionInterval(@Nullable Integer compactionInterval);
57+
58+
@CanIgnoreReturnValue
59+
public abstract Builder overlapSize(@Nullable Integer overlapSize);
60+
61+
@CanIgnoreReturnValue
62+
public abstract Builder summarizer(@Nullable BaseEventSummarizer summarizer);
63+
64+
@CanIgnoreReturnValue
65+
public abstract Builder tokenThreshold(@Nullable Integer tokenThreshold);
66+
67+
@CanIgnoreReturnValue
68+
public abstract Builder eventRetentionSize(@Nullable Integer eventRetentionSize);
69+
70+
public abstract EventsCompactionConfig build();
71+
}
72+
4273
public EventsCompactionConfig(int compactionInterval, int overlapSize) {
4374
this(compactionInterval, overlapSize, null, null, null);
4475
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.adk.summarizer;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import org.junit.Test;
22+
import org.junit.runner.RunWith;
23+
import org.junit.runners.JUnit4;
24+
25+
@RunWith(JUnit4.class)
26+
public final class EventsCompactionConfigTest {
27+
28+
@Test
29+
public void builder_buildsConfig() {
30+
EventsCompactionConfig config =
31+
EventsCompactionConfig.builder()
32+
.compactionInterval(10)
33+
.overlapSize(2)
34+
.tokenThreshold(100)
35+
.eventRetentionSize(5)
36+
.build();
37+
38+
assertThat(config.compactionInterval()).isEqualTo(10);
39+
assertThat(config.overlapSize()).isEqualTo(2);
40+
assertThat(config.tokenThreshold()).isEqualTo(100);
41+
assertThat(config.eventRetentionSize()).isEqualTo(5);
42+
assertThat(config.summarizer()).isNull();
43+
}
44+
45+
@Test
46+
public void toBuilder_rebuildsConfig() {
47+
EventsCompactionConfig config =
48+
EventsCompactionConfig.builder().compactionInterval(10).overlapSize(2).build();
49+
50+
EventsCompactionConfig rebuilt = config.toBuilder().compactionInterval(20).build();
51+
52+
assertThat(rebuilt.compactionInterval()).isEqualTo(20);
53+
assertThat(rebuilt.overlapSize()).isEqualTo(2);
54+
}
55+
}

0 commit comments

Comments
 (0)