@@ -10,49 +10,53 @@ public final class TaskOptions {
1010 private final RetryHandler retryHandler ;
1111 private final String appID ;
1212
13- public TaskOptions (RetryPolicy retryPolicy , RetryHandler retryHandler , String appID ) {
14- this .retryPolicy = retryPolicy ;
15- this .retryHandler = retryHandler ;
16- this .appID = appID ;
13+ private TaskOptions (Builder builder ) {
14+ this .retryPolicy = builder . retryPolicy ;
15+ this .retryHandler = builder . retryHandler ;
16+ this .appID = builder . appID ;
1717 }
1818
19- public TaskOptions (RetryPolicy retryPolicy , RetryHandler retryHandler ) {
20- this .retryPolicy = retryPolicy ;
21- this .retryHandler = retryHandler ;
22- this .appID = null ;
19+ /**
20+ * Creates a new builder for {@code TaskOptions}.
21+ * @return a new builder instance
22+ */
23+ public static Builder builder () {
24+ return new Builder ();
25+ }
26+
27+ /**
28+ * Creates a new {@code TaskOptions} object with default values.
29+ * @return a new TaskOptions instance with no configuration
30+ */
31+ public static TaskOptions create () {
32+ return new Builder ().build ();
2333 }
2434
2535 /**
2636 * Creates a new {@code TaskOptions} object from a {@link RetryPolicy}.
2737 * @param retryPolicy the retry policy to use in the new {@code TaskOptions} object.
38+ * @return a new TaskOptions instance with the specified retry policy
2839 */
29- public TaskOptions (RetryPolicy retryPolicy ) {
30- this ( retryPolicy , null , null );
40+ public static TaskOptions withRetryPolicy (RetryPolicy retryPolicy ) {
41+ return new Builder (). retryPolicy ( retryPolicy ). build ( );
3142 }
3243
3344 /**
3445 * Creates a new {@code TaskOptions} object from a {@link RetryHandler}.
3546 * @param retryHandler the retry handler to use in the new {@code TaskOptions} object.
47+ * @return a new TaskOptions instance with the specified retry handler
3648 */
37- public TaskOptions (RetryHandler retryHandler ) {
38- this ( null , retryHandler , null );
49+ public static TaskOptions withRetryHandler (RetryHandler retryHandler ) {
50+ return new Builder (). retryHandler ( retryHandler ). build ( );
3951 }
4052
4153 /**
4254 * Creates a new {@code TaskOptions} object with the specified app ID.
4355 * @param appID the app ID to use for cross-app workflow routing
56+ * @return a new TaskOptions instance with the specified app ID
4457 */
45- public TaskOptions (String appID ) {
46- this (null , null , appID );
47- }
48-
49- /**
50- * Creates a new {@code TaskOptions} object with the specified retry policy and app ID.
51- * @param retryPolicy the retry policy to use
52- * @param appID the app ID to use for cross-app workflow routing
53- */
54- public TaskOptions (RetryPolicy retryPolicy , String appID ) {
55- this (retryPolicy , null , appID );
58+ public static TaskOptions withAppID (String appID ) {
59+ return new Builder ().appID (appID ).build ();
5660 }
5761
5862 boolean hasRetryPolicy () {
@@ -90,4 +94,55 @@ public String getAppID() {
9094 boolean hasAppID () {
9195 return this .appID != null && !this .appID .isEmpty ();
9296 }
97+
98+ /**
99+ * Builder for creating {@code TaskOptions} instances.
100+ */
101+ public static final class Builder {
102+ private RetryPolicy retryPolicy ;
103+ private RetryHandler retryHandler ;
104+ private String appID ;
105+
106+ private Builder () {
107+ // Private constructor -enforces using TaskOptions.builder()
108+ }
109+
110+ /**
111+ * Sets the retry policy for the task options.
112+ * @param retryPolicy the retry policy to use
113+ * @return this builder instance for method chaining
114+ */
115+ public Builder retryPolicy (RetryPolicy retryPolicy ) {
116+ this .retryPolicy = retryPolicy ;
117+ return this ;
118+ }
119+
120+ /**
121+ * Sets the retry handler for the task options.
122+ * @param retryHandler the retry handler to use
123+ * @return this builder instance for method chaining
124+ */
125+ public Builder retryHandler (RetryHandler retryHandler ) {
126+ this .retryHandler = retryHandler ;
127+ return this ;
128+ }
129+
130+ /**
131+ * Sets the app ID for cross-app workflow routing.
132+ * @param appID the app ID to use
133+ * @return this builder instance for method chaining
134+ */
135+ public Builder appID (String appID ) {
136+ this .appID = appID ;
137+ return this ;
138+ }
139+
140+ /**
141+ * Builds a new {@code TaskOptions} instance with the configured values.
142+ * @return a new TaskOptions instance
143+ */
144+ public TaskOptions build () {
145+ return new TaskOptions (this );
146+ }
147+ }
93148}
0 commit comments