Skip to content

Commit 742a10e

Browse files
committed
feat!: Replace public Builder constructors with static factory methods
1 parent ec0ef92 commit 742a10e

34 files changed

+510
-37
lines changed

spec/src/main/java/io/a2a/spec/APIKeySecurityScheme.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,21 @@ public String getType() {
148148
return type;
149149
}
150150

151+
/**
152+
* Create a new Builder
153+
*
154+
* @return the builder
155+
*/
156+
public static Builder builder() {
157+
return new Builder();
158+
}
159+
151160
/**
152161
* Builder for constructing immutable {@link APIKeySecurityScheme} instances.
153162
* <p>
154163
* Example usage:
155164
* <pre>{@code
156-
* APIKeySecurityScheme scheme = new APIKeySecurityScheme.Builder()
165+
* APIKeySecurityScheme scheme = APIKeySecurityScheme.builder()
157166
* .location(Location.HEADER)
158167
* .name("X-API-Key")
159168
* .description("API key authentication")
@@ -165,6 +174,12 @@ public static class Builder {
165174
private String name;
166175
private String description;
167176

177+
/**
178+
* Creates a new Builder with all fields unset.
179+
*/
180+
private Builder() {
181+
}
182+
168183
/**
169184
* Sets the location where the API key should be sent.
170185
*

spec/src/main/java/io/a2a/spec/AgentCapabilities.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
public record AgentCapabilities(boolean streaming, boolean pushNotifications, boolean stateTransitionHistory,
3535
List<AgentExtension> extensions) {
3636

37+
/**
38+
* Create a new Builder
39+
*
40+
* @return the builder
41+
*/
42+
public static Builder builder() {
43+
return new Builder();
44+
}
3745
/**
3846
* Builder for constructing immutable {@link AgentCapabilities} instances.
3947
* <p>
@@ -42,7 +50,7 @@ public record AgentCapabilities(boolean streaming, boolean pushNotifications, bo
4250
* <p>
4351
* Example usage:
4452
* <pre>{@code
45-
* AgentCapabilities capabilities = new AgentCapabilities.Builder()
53+
* AgentCapabilities capabilities = AgentCapabilities.builder()
4654
* .streaming(true)
4755
* .pushNotifications(false)
4856
* .stateTransitionHistory(false)
@@ -59,7 +67,7 @@ public static class Builder {
5967
/**
6068
* Creates a new Builder with all capabilities set to false by default.
6169
*/
62-
public Builder() {
70+
private Builder() {
6371
}
6472

6573
/**

spec/src/main/java/io/a2a/spec/AgentCard.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,29 @@ public List<AgentInterface> additionalInterfaces() {
8989
return supportedInterfaces;
9090
}
9191

92+
/**
93+
* Create a new Builder
94+
*
95+
* @return the builder
96+
*/
97+
public static Builder builder() {
98+
return new Builder();
99+
}
100+
101+
/**
102+
* Create a new Builder initialized with values from an existing AgentCard.
103+
* <p>
104+
* This builder creates defensive copies of mutable collections to ensure
105+
* that modifications to the builder do not affect the original AgentCard.
106+
*
107+
* @param card the AgentCard to copy values from
108+
* @return the builder
109+
*/
110+
public static Builder builder(AgentCard card) {
111+
return new Builder(card);
112+
}
113+
114+
92115
/**
93116
* Builder for constructing immutable {@link AgentCard} instances.
94117
* <p>
@@ -99,7 +122,7 @@ public List<AgentInterface> additionalInterfaces() {
99122
* <p>
100123
* Example usage:
101124
* <pre>{@code
102-
* AgentCard card = new AgentCard.Builder()
125+
* AgentCard card = AgentCard.builder()
103126
* .name("Weather Agent")
104127
* .description("Provides weather information")
105128
* .supportedInterfaces(List.of(
@@ -140,7 +163,7 @@ public static class Builder {
140163
/**
141164
* Creates a new Builder with all fields unset.
142165
*/
143-
public Builder() {
166+
private Builder() {
144167

145168
}
146169

@@ -152,7 +175,7 @@ public Builder() {
152175
*
153176
* @param card the AgentCard to copy values from
154177
*/
155-
public Builder(AgentCard card) {
178+
private Builder(AgentCard card) {
156179
this.name = card.name;
157180
this.description = card.description;
158181
this.provider = card.provider;

spec/src/main/java/io/a2a/spec/AgentCardSignature.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,21 @@ public record AgentCardSignature(Map<String, Object> header, @SerializedName("pr
4444
Assert.checkNotNullParam("signature", signature);
4545
}
4646

47+
/**
48+
* Create a new Builder
49+
*
50+
* @return the builder
51+
*/
52+
public static Builder builder() {
53+
return new Builder();
54+
}
55+
4756
/**
4857
* Builder for constructing immutable {@link AgentCardSignature} instances.
4958
* <p>
5059
* Example usage:
5160
* <pre>{@code
52-
* AgentCardSignature sig = new AgentCardSignature.Builder()
61+
* AgentCardSignature sig = AgentCardSignature.builder()
5362
* .protectedHeader("eyJhbGciOiJFUzI1NiJ9")
5463
* .signature("DtEhU3ljbEg8L38VWAfUAqOyKAM6...")
5564
* .header(Map.of("kid", "2024-01"))
@@ -64,7 +73,7 @@ public static class Builder {
6473
/**
6574
* Creates a new Builder with all fields unset.
6675
*/
67-
public Builder() {
76+
private Builder() {
6877
}
6978

7079
/**

spec/src/main/java/io/a2a/spec/AgentExtension.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,21 @@ public record AgentExtension (String description, Map<String, Object> params, bo
3434
Assert.checkNotNullParam("uri", uri);
3535
}
3636

37+
/**
38+
* Create a new Builder
39+
*
40+
* @return the builder
41+
*/
42+
public static Builder builder() {
43+
return new Builder();
44+
}
45+
3746
/**
3847
* Builder for constructing immutable {@link AgentExtension} instances.
3948
* <p>
4049
* Example usage:
4150
* <pre>{@code
42-
* AgentExtension ext = new AgentExtension.Builder()
51+
* AgentExtension ext = AgentExtension.builder()
4352
* .uri("https://example.com/extensions/custom-auth")
4453
* .description("Custom authentication extension")
4554
* .required(true)
@@ -56,7 +65,7 @@ public static class Builder {
5665
/**
5766
* Creates a new Builder with all fields unset.
5867
*/
59-
public Builder() {
68+
private Builder() {
6069
}
6170

6271
/**

spec/src/main/java/io/a2a/spec/AgentSkill.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public record AgentSkill(String id, String name, String description, List<String
5555
Assert.checkNotNullParam("tags", tags);
5656
}
5757

58+
/**
59+
* Create a new Builder
60+
*
61+
* @return the builder
62+
*/
63+
public static Builder builder() {
64+
return new Builder();
65+
}
66+
5867
/**
5968
* Builder for constructing immutable {@link AgentSkill} instances.
6069
* <p>
@@ -64,7 +73,7 @@ public record AgentSkill(String id, String name, String description, List<String
6473
* <p>
6574
* Example usage:
6675
* <pre>{@code
67-
* AgentSkill skill = new AgentSkill.Builder()
76+
* AgentSkill skill = AgentSkill.builder()
6877
* .id("weather_query")
6978
* .name("Weather Queries")
7079
* .description("Get current weather conditions for any location")
@@ -92,7 +101,7 @@ public static class Builder {
92101
/**
93102
* Creates a new Builder with all fields unset.
94103
*/
95-
public Builder() {
104+
private Builder() {
96105
}
97106

98107
/**

spec/src/main/java/io/a2a/spec/Artifact.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ public record Artifact(String artifactId, String name, String description, List<
4545
}
4646
}
4747

48+
/**
49+
* Create a new Builder
50+
*
51+
* @return the builder
52+
*/
53+
public static Builder builder() {
54+
return new Builder();
55+
}
56+
57+
/**
58+
* Create a new Builder initialized with values from an existing Artifact.
59+
* <p>
60+
* This builder creates defensive copies of mutable collections to ensure
61+
* that modifications to the builder do not affect the original Artifact.
62+
*
63+
* @param artifact the Artifact to copy values from
64+
* @return the builder
65+
*/
66+
public static Builder builder(Artifact artifact) {
67+
return new Builder(artifact);
68+
}
69+
4870
/**
4971
* Builder for constructing immutable {@link Artifact} instances.
5072
* <p>
@@ -53,7 +75,7 @@ public record Artifact(String artifactId, String name, String description, List<
5375
* <p>
5476
* Example usage:
5577
* <pre>{@code
56-
* Artifact result = new Artifact.Builder()
78+
* Artifact result = Artifact.builder()
5779
* .artifactId("artifact-123")
5880
* .name("Analysis Report")
5981
* .description("Detailed analysis of user data")
@@ -72,15 +94,15 @@ public static class Builder {
7294
/**
7395
* Creates a new Builder with all fields unset.
7496
*/
75-
public Builder(){
97+
private Builder(){
7698
}
7799

78100
/**
79101
* Creates a new Builder initialized with values from an existing Artifact.
80102
*
81103
* @param existingArtifact the Artifact to copy values from
82104
*/
83-
public Builder(Artifact existingArtifact) {
105+
private Builder(Artifact existingArtifact) {
84106
artifactId = existingArtifact.artifactId;
85107
name = existingArtifact.name;
86108
description = existingArtifact.description;

spec/src/main/java/io/a2a/spec/CancelTaskRequest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ public CancelTaskRequest(Object id, TaskIdParams params) {
4747
this(null, id, params);
4848
}
4949

50+
/**
51+
* Create a new Builder
52+
*
53+
* @return the builder
54+
*/
55+
public static Builder builder() {
56+
return new Builder();
57+
}
58+
5059
/**
5160
* Builder for constructing {@link CancelTaskRequest} instances.
5261
* <p>
@@ -58,6 +67,12 @@ public static class Builder {
5867
private Object id;
5968
private TaskIdParams params;
6069

70+
/**
71+
* Creates a new Builder with all fields unset.
72+
*/
73+
private Builder() {
74+
}
75+
6176
/**
6277
* Sets the JSON-RPC protocol version.
6378
*

spec/src/main/java/io/a2a/spec/DeleteTaskPushNotificationConfigParams.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public DeleteTaskPushNotificationConfigParams(String id, String pushNotification
4040
this(id, pushNotificationConfigId, null);
4141
}
4242

43+
/**
44+
* Create a new Builder
45+
*
46+
* @return the builder
47+
*/
48+
public static Builder builder() {
49+
return new Builder();
50+
}
51+
4352
/**
4453
* Builder for constructing {@link DeleteTaskPushNotificationConfigParams} instances.
4554
* <p>
@@ -50,6 +59,12 @@ public static class Builder {
5059
String pushNotificationConfigId;
5160
Map<String, Object> metadata;
5261

62+
/**
63+
* Creates a new Builder with all fields unset.
64+
*/
65+
private Builder() {
66+
}
67+
5368
/**
5469
* Sets the task identifier.
5570
*

spec/src/main/java/io/a2a/spec/DeleteTaskPushNotificationConfigRequest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ public DeleteTaskPushNotificationConfigRequest(String id, DeleteTaskPushNotifica
4343
this(null, id, params);
4444
}
4545

46+
/**
47+
* Create a new Builder
48+
*
49+
* @return the builder
50+
*/
51+
public static Builder builder() {
52+
return new Builder();
53+
}
54+
4655
/**
4756
* Builder for constructing {@link DeleteTaskPushNotificationConfigRequest} instances.
4857
* <p>
@@ -54,6 +63,12 @@ public static class Builder {
5463
private Object id;
5564
private DeleteTaskPushNotificationConfigParams params;
5665

66+
/**
67+
* Creates a new Builder with all fields unset.
68+
*/
69+
private Builder() {
70+
}
71+
5772
/**
5873
* Sets the JSON-RPC protocol version.
5974
*

0 commit comments

Comments
 (0)