• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #174

pending completion
#174

push

github-actions

web-flow
Add schedules API (#1776)

Add schedules API

1143 of 1143 new or added lines in 35 files covered. (100.0%)

18101 of 23284 relevant lines covered (77.74%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/temporal-sdk/src/main/java/io/temporal/client/schedules/ScheduleCalendarSpec.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.client.schedules;
22

23
import java.util.Collections;
24
import java.util.List;
25
import java.util.Objects;
26

27
/**
28
 * Specification of when to run an action in relation to calendar time.
29
 *
30
 * <p>A timestamp matches if at least one range of each field matches except for year. If year is
31
 * missing, that means all years match. For all fields besides year, at least one range must be
32
 * present to match anything.
33
 */
34
public final class ScheduleCalendarSpec {
35
  public static ScheduleCalendarSpec.Builder newBuilder() {
36
    return new ScheduleCalendarSpec.Builder();
×
37
  }
38

39
  public static ScheduleCalendarSpec.Builder newBuilder(ScheduleCalendarSpec spec) {
40
    return new ScheduleCalendarSpec.Builder(spec);
×
41
  }
42

43
  public static final class Builder {
44
    private List<ScheduleRange> seconds;
45
    private List<ScheduleRange> minutes;
46
    private List<ScheduleRange> hour;
47
    private List<ScheduleRange> dayOfMonth;
48
    private List<ScheduleRange> month;
49
    private List<ScheduleRange> year;
50
    private List<ScheduleRange> dayOfWeek;
51
    private String comment;
52

53
    private Builder() {}
54

55
    private Builder(ScheduleCalendarSpec spec) {
×
56
      if (spec == null) {
×
57
        return;
×
58
      }
59
      this.seconds = spec.seconds;
×
60
      this.minutes = spec.minutes;
×
61
      this.hour = spec.hour;
×
62
      this.dayOfMonth = spec.dayOfMonth;
×
63
      this.month = spec.month;
×
64
      this.year = spec.year;
×
65
      this.dayOfWeek = spec.dayOfWeek;
×
66
      this.comment = spec.comment;
×
67
    }
×
68

69
    /**
70
     * Set the second ranges to provided values. Values must be within the range 0-59.
71
     *
72
     * <p>Default matches 0.
73
     */
74
    public Builder setSeconds(List<ScheduleRange> seconds) {
75
      this.seconds = seconds;
×
76
      return this;
×
77
    }
78

79
    /**
80
     * Set the minutes ranges to provided values. Values must be within the range 0-59.
81
     *
82
     * <p>Default matches 0.
83
     */
84
    public Builder setMinutes(List<ScheduleRange> minutes) {
85
      this.minutes = minutes;
×
86
      return this;
×
87
    }
88

89
    /**
90
     * Set the hour ranges to provided values. Values must be within the range 0-23.
91
     *
92
     * <p>Default matches 0.
93
     */
94
    public Builder setHour(List<ScheduleRange> hour) {
95
      this.hour = hour;
×
96
      return this;
×
97
    }
98

99
    /**
100
     * Set the day of month ranges to provided values. Values must be within the range 1-31.
101
     *
102
     * <p>Default matches all days.
103
     */
104
    public Builder setDayOfMonth(List<ScheduleRange> dayOfMonth) {
105
      this.dayOfMonth = dayOfMonth;
×
106
      return this;
×
107
    }
108

109
    /**
110
     * Set the month ranges to provided values. Values must be within the range 1-12.
111
     *
112
     * <p>Default matches all months.
113
     */
114
    public Builder setMonth(List<ScheduleRange> month) {
115
      this.month = month;
×
116
      return this;
×
117
    }
118

119
    /**
120
     * Set the optional year ranges to provided values.
121
     *
122
     * <p>Default of empty matches all years.
123
     */
124
    public Builder setYear(List<ScheduleRange> year) {
125
      this.year = year;
×
126
      return this;
×
127
    }
128

129
    /**
130
     * Set the day of week ranges to provided values. Values must be within the range 0-6, 0 is
131
     * Sunday.
132
     *
133
     * <p>Default matches all days.
134
     */
135
    public Builder setDayOfWeek(List<ScheduleRange> dayOfWeek) {
136
      this.dayOfWeek = dayOfWeek;
×
137
      return this;
×
138
    }
139

140
    /** Set the description of this specification. */
141
    public Builder setComment(String comment) {
142
      this.comment = comment;
×
143
      return this;
×
144
    }
145

146
    public ScheduleCalendarSpec build() {
147
      return new ScheduleCalendarSpec(
×
148
          seconds == null ? ScheduleCalendarSpec.BEGINNING : seconds,
×
149
          minutes == null ? ScheduleCalendarSpec.BEGINNING : minutes,
×
150
          hour == null ? ScheduleCalendarSpec.BEGINNING : hour,
×
151
          dayOfMonth == null ? ScheduleCalendarSpec.ALL_MONTH_DAYS : dayOfMonth,
×
152
          month == null ? ScheduleCalendarSpec.ALL_MONTHS : month,
×
153
          year == null ? Collections.EMPTY_LIST : year,
×
154
          dayOfWeek == null ? ScheduleCalendarSpec.ALL_WEEK_DAYS : dayOfWeek,
×
155
          comment == null ? "" : comment);
×
156
    }
157
  }
158

159
  /** Default range set for zero. */
160
  public static final List<ScheduleRange> BEGINNING =
×
161
      Collections.singletonList(new ScheduleRange(0));
×
162

163
  /** Default range set for all days in a month. */
164
  public static final List<ScheduleRange> ALL_MONTH_DAYS =
×
165
      Collections.singletonList(new ScheduleRange(1, 31));
×
166

167
  /** Default range set for all months in a year. */
168
  public static final List<ScheduleRange> ALL_MONTHS =
×
169
      Collections.singletonList(new ScheduleRange(1, 12));
×
170

171
  /** Default range set for all days in a week. */
172
  public static final List<ScheduleRange> ALL_WEEK_DAYS =
×
173
      Collections.singletonList(new ScheduleRange(0, 6));
×
174

175
  private final List<ScheduleRange> seconds;
176
  private final List<ScheduleRange> minutes;
177
  private final List<ScheduleRange> hour;
178
  private final List<ScheduleRange> dayOfMonth;
179
  private final List<ScheduleRange> month;
180
  private final List<ScheduleRange> year;
181
  private final List<ScheduleRange> dayOfWeek;
182
  private final String comment;
183

184
  private ScheduleCalendarSpec(
185
      List<ScheduleRange> seconds,
186
      List<ScheduleRange> minutes,
187
      List<ScheduleRange> hour,
188
      List<ScheduleRange> dayOfMonth,
189
      List<ScheduleRange> month,
190
      List<ScheduleRange> year,
191
      List<ScheduleRange> dayOfWeek,
192
      String comment) {
×
193
    this.seconds = seconds;
×
194
    this.minutes = minutes;
×
195
    this.hour = hour;
×
196
    this.dayOfMonth = dayOfMonth;
×
197
    this.month = month;
×
198
    this.year = year;
×
199
    this.dayOfWeek = dayOfWeek;
×
200
    this.comment = comment;
×
201
  }
×
202

203
  /**
204
   * Gets the second range to match.
205
   *
206
   * @return second ranges
207
   */
208
  public List<ScheduleRange> getSeconds() {
209
    return seconds;
×
210
  }
211

212
  /**
213
   * Gets the minute range to match.
214
   *
215
   * @return minute ranges
216
   */
217
  public List<ScheduleRange> getMinutes() {
218
    return minutes;
×
219
  }
220

221
  /**
222
   * Gets the hour range to match.
223
   *
224
   * @return hour ranges
225
   */
226
  public List<ScheduleRange> getHour() {
227
    return hour;
×
228
  }
229

230
  /**
231
   * Gets the day of month range to match.
232
   *
233
   * @return hour ranges
234
   */
235
  public List<ScheduleRange> getDayOfMonth() {
236
    return dayOfMonth;
×
237
  }
238

239
  /**
240
   * Gets the month range to match.
241
   *
242
   * @return month ranges
243
   */
244
  public List<ScheduleRange> getMonth() {
245
    return month;
×
246
  }
247

248
  /**
249
   * Gets the year range to match.
250
   *
251
   * @return year ranges
252
   */
253
  public List<ScheduleRange> getYear() {
254
    return year;
×
255
  }
256

257
  /**
258
   * Gets the day of the week range to match.
259
   *
260
   * @return day of the week range
261
   */
262
  public List<ScheduleRange> getDayOfWeek() {
263
    return dayOfWeek;
×
264
  }
265

266
  /**
267
   * Gets the description of this specification.
268
   *
269
   * @return specification description
270
   */
271
  public String getComment() {
272
    return comment;
×
273
  }
274

275
  @Override
276
  public boolean equals(Object o) {
277
    if (this == o) return true;
×
278
    if (o == null || getClass() != o.getClass()) return false;
×
279
    ScheduleCalendarSpec that = (ScheduleCalendarSpec) o;
×
280
    return Objects.equals(seconds, that.seconds)
×
281
        && Objects.equals(minutes, that.minutes)
×
282
        && Objects.equals(hour, that.hour)
×
283
        && Objects.equals(dayOfMonth, that.dayOfMonth)
×
284
        && Objects.equals(month, that.month)
×
285
        && Objects.equals(year, that.year)
×
286
        && Objects.equals(dayOfWeek, that.dayOfWeek)
×
287
        && Objects.equals(comment, that.comment);
×
288
  }
289

290
  @Override
291
  public int hashCode() {
292
    return Objects.hash(seconds, minutes, hour, dayOfMonth, month, year, dayOfWeek, comment);
×
293
  }
294

295
  @Override
296
  public String toString() {
297
    return "ScheduleCalendarSpec{"
×
298
        + "seconds="
299
        + seconds
300
        + ", minutes="
301
        + minutes
302
        + ", hour="
303
        + hour
304
        + ", dayOfMonth="
305
        + dayOfMonth
306
        + ", month="
307
        + month
308
        + ", year="
309
        + year
310
        + ", dayOfWeek="
311
        + dayOfWeek
312
        + ", comment='"
313
        + comment
314
        + '\''
315
        + '}';
316
  }
317
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc