Skip to content

Commit b8316b1

Browse files
tilgalascopybara-github
authored andcommitted
feat!: Remove Optional parameters in EventActions
PiperOrigin-RevId: 881410767
1 parent d1d5539 commit b8316b1

1 file changed

Lines changed: 28 additions & 56 deletions

File tree

core/src/main/java/com/google/adk/events/EventActions.java

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,32 @@
2828
import java.util.Set;
2929
import java.util.concurrent.ConcurrentHashMap;
3030
import java.util.concurrent.ConcurrentMap;
31-
import javax.annotation.Nullable;
31+
import org.jspecify.annotations.Nullable;
3232

3333
/** Represents the actions attached to an event. */
3434
// TODO - b/414081262 make json wire camelCase
3535
@JsonDeserialize(builder = EventActions.Builder.class)
3636
public class EventActions extends JsonBaseModel {
3737

38-
private Optional<Boolean> skipSummarization;
38+
private @Nullable Boolean skipSummarization;
3939
private ConcurrentMap<String, Object> stateDelta;
4040
private ConcurrentMap<String, Integer> artifactDelta;
4141
private Set<String> deletedArtifactIds;
42-
private Optional<String> transferToAgent;
43-
private Optional<Boolean> escalate;
42+
private @Nullable String transferToAgent;
43+
private @Nullable Boolean escalate;
4444
private ConcurrentMap<String, ConcurrentMap<String, Object>> requestedAuthConfigs;
4545
private ConcurrentMap<String, ToolConfirmation> requestedToolConfirmations;
4646
private boolean endOfAgent;
47-
private Optional<EventCompaction> compaction;
47+
private @Nullable EventCompaction compaction;
4848

4949
/** Default constructor for Jackson. */
5050
public EventActions() {
51-
this.skipSummarization = Optional.empty();
5251
this.stateDelta = new ConcurrentHashMap<>();
5352
this.artifactDelta = new ConcurrentHashMap<>();
5453
this.deletedArtifactIds = new HashSet<>();
55-
this.transferToAgent = Optional.empty();
56-
this.escalate = Optional.empty();
5754
this.requestedAuthConfigs = new ConcurrentHashMap<>();
5855
this.requestedToolConfirmations = new ConcurrentHashMap<>();
5956
this.endOfAgent = false;
60-
this.compaction = Optional.empty();
6157
}
6258

6359
private EventActions(Builder builder) {
@@ -75,19 +71,15 @@ private EventActions(Builder builder) {
7571

7672
@JsonProperty("skipSummarization")
7773
public Optional<Boolean> skipSummarization() {
78-
return skipSummarization;
74+
return Optional.ofNullable(skipSummarization);
7975
}
8076

8177
public void setSkipSummarization(@Nullable Boolean skipSummarization) {
82-
this.skipSummarization = Optional.ofNullable(skipSummarization);
83-
}
84-
85-
public void setSkipSummarization(Optional<Boolean> skipSummarization) {
8678
this.skipSummarization = skipSummarization;
8779
}
8880

8981
public void setSkipSummarization(boolean skipSummarization) {
90-
this.skipSummarization = Optional.of(skipSummarization);
82+
this.skipSummarization = skipSummarization;
9183
}
9284

9385
@JsonProperty("stateDelta")
@@ -130,30 +122,22 @@ public void setDeletedArtifactIds(Set<String> deletedArtifactIds) {
130122

131123
@JsonProperty("transferToAgent")
132124
public Optional<String> transferToAgent() {
133-
return transferToAgent;
125+
return Optional.ofNullable(transferToAgent);
134126
}
135127

136-
public void setTransferToAgent(Optional<String> transferToAgent) {
128+
public void setTransferToAgent(@Nullable String transferToAgent) {
137129
this.transferToAgent = transferToAgent;
138130
}
139131

140-
public void setTransferToAgent(String transferToAgent) {
141-
this.transferToAgent = Optional.ofNullable(transferToAgent);
142-
}
143-
144132
@JsonProperty("escalate")
145133
public Optional<Boolean> escalate() {
146-
return escalate;
134+
return Optional.ofNullable(escalate);
147135
}
148136

149-
public void setEscalate(Optional<Boolean> escalate) {
137+
public void setEscalate(@Nullable Boolean escalate) {
150138
this.escalate = escalate;
151139
}
152140

153-
public void setEscalate(boolean escalate) {
154-
this.escalate = Optional.of(escalate);
155-
}
156-
157141
@JsonProperty("requestedAuthConfigs")
158142
public ConcurrentMap<String, ConcurrentMap<String, Object>> requestedAuthConfigs() {
159143
return requestedAuthConfigs;
@@ -199,14 +183,6 @@ public Optional<Boolean> endInvocation() {
199183
return endOfAgent ? Optional.of(true) : Optional.empty();
200184
}
201185

202-
/**
203-
* @deprecated Use {@link #setEndOfAgent(boolean)} instead.
204-
*/
205-
@Deprecated
206-
public void setEndInvocation(Optional<Boolean> endInvocation) {
207-
this.endOfAgent = endInvocation.orElse(false);
208-
}
209-
210186
/**
211187
* @deprecated Use {@link #setEndOfAgent(boolean)} instead.
212188
*/
@@ -217,10 +193,10 @@ public void setEndInvocation(boolean endInvocation) {
217193

218194
@JsonProperty("compaction")
219195
public Optional<EventCompaction> compaction() {
220-
return compaction;
196+
return Optional.ofNullable(compaction);
221197
}
222198

223-
public void setCompaction(Optional<EventCompaction> compaction) {
199+
public void setCompaction(@Nullable EventCompaction compaction) {
224200
this.compaction = compaction;
225201
}
226202

@@ -269,47 +245,43 @@ public int hashCode() {
269245

270246
/** Builder for {@link EventActions}. */
271247
public static class Builder {
272-
private Optional<Boolean> skipSummarization;
248+
private @Nullable Boolean skipSummarization;
273249
private ConcurrentMap<String, Object> stateDelta;
274250
private ConcurrentMap<String, Integer> artifactDelta;
275251
private Set<String> deletedArtifactIds;
276-
private Optional<String> transferToAgent;
277-
private Optional<Boolean> escalate;
252+
private @Nullable String transferToAgent;
253+
private @Nullable Boolean escalate;
278254
private ConcurrentMap<String, ConcurrentMap<String, Object>> requestedAuthConfigs;
279255
private ConcurrentMap<String, ToolConfirmation> requestedToolConfirmations;
280256
private boolean endOfAgent = false;
281-
private Optional<EventCompaction> compaction;
257+
private @Nullable EventCompaction compaction;
282258

283259
public Builder() {
284-
this.skipSummarization = Optional.empty();
285260
this.stateDelta = new ConcurrentHashMap<>();
286261
this.artifactDelta = new ConcurrentHashMap<>();
287262
this.deletedArtifactIds = new HashSet<>();
288-
this.transferToAgent = Optional.empty();
289-
this.escalate = Optional.empty();
290263
this.requestedAuthConfigs = new ConcurrentHashMap<>();
291264
this.requestedToolConfirmations = new ConcurrentHashMap<>();
292-
this.compaction = Optional.empty();
293265
}
294266

295267
private Builder(EventActions eventActions) {
296-
this.skipSummarization = eventActions.skipSummarization();
268+
this.skipSummarization = eventActions.skipSummarization;
297269
this.stateDelta = new ConcurrentHashMap<>(eventActions.stateDelta());
298270
this.artifactDelta = new ConcurrentHashMap<>(eventActions.artifactDelta());
299271
this.deletedArtifactIds = new HashSet<>(eventActions.deletedArtifactIds());
300-
this.transferToAgent = eventActions.transferToAgent();
301-
this.escalate = eventActions.escalate();
272+
this.transferToAgent = eventActions.transferToAgent;
273+
this.escalate = eventActions.escalate;
302274
this.requestedAuthConfigs = new ConcurrentHashMap<>(eventActions.requestedAuthConfigs());
303275
this.requestedToolConfirmations =
304276
new ConcurrentHashMap<>(eventActions.requestedToolConfirmations());
305-
this.endOfAgent = eventActions.endOfAgent();
306-
this.compaction = eventActions.compaction();
277+
this.endOfAgent = eventActions.endOfAgent;
278+
this.compaction = eventActions.compaction;
307279
}
308280

309281
@CanIgnoreReturnValue
310282
@JsonProperty("skipSummarization")
311283
public Builder skipSummarization(boolean skipSummarization) {
312-
this.skipSummarization = Optional.of(skipSummarization);
284+
this.skipSummarization = skipSummarization;
313285
return this;
314286
}
315287

@@ -336,15 +308,15 @@ public Builder deletedArtifactIds(Set<String> value) {
336308

337309
@CanIgnoreReturnValue
338310
@JsonProperty("transferToAgent")
339-
public Builder transferToAgent(String agentId) {
340-
this.transferToAgent = Optional.ofNullable(agentId);
311+
public Builder transferToAgent(@Nullable String agentId) {
312+
this.transferToAgent = agentId;
341313
return this;
342314
}
343315

344316
@CanIgnoreReturnValue
345317
@JsonProperty("escalate")
346318
public Builder escalate(boolean escalate) {
347-
this.escalate = Optional.of(escalate);
319+
this.escalate = escalate;
348320
return this;
349321
}
350322

@@ -391,8 +363,8 @@ public Builder endInvocation(boolean endInvocation) {
391363

392364
@CanIgnoreReturnValue
393365
@JsonProperty("compaction")
394-
public Builder compaction(EventCompaction value) {
395-
this.compaction = Optional.ofNullable(value);
366+
public Builder compaction(@Nullable EventCompaction value) {
367+
this.compaction = value;
396368
return this;
397369
}
398370

0 commit comments

Comments
 (0)