001 002package com.commercetools.history.models.change_history; 003 004import java.util.*; 005import java.util.function.Function; 006 007import io.vrap.rmf.base.client.Builder; 008import io.vrap.rmf.base.client.utils.Generated; 009 010/** 011 * RecordBuilder 012 * <hr> 013 * Example to create an instance using the builder pattern 014 * <div class=code-example> 015 * <pre><code class='java'> 016 * Record record = Record.builder() 017 * .version(1) 018 * .previousVersion(1) 019 * .type("{type}") 020 * .modifiedBy(modifiedByBuilder -> modifiedByBuilder) 021 * .modifiedAt("{modifiedAt}") 022 * .label(labelBuilder -> labelBuilder) 023 * .previousLabel(previousLabelBuilder -> previousLabelBuilder) 024 * .plusChanges(changesBuilder -> changesBuilder) 025 * .resource(resourceBuilder -> resourceBuilder) 026 * .plusStores(storesBuilder -> storesBuilder) 027 * .withoutChanges(true) 028 * .build() 029 * </code></pre> 030 * </div> 031 */ 032@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 033public class RecordBuilder implements Builder<Record> { 034 035 private Integer version; 036 037 private Integer previousVersion; 038 039 private String type; 040 041 private com.commercetools.history.models.change_history.ModifiedBy modifiedBy; 042 043 private String modifiedAt; 044 045 private com.commercetools.history.models.label.Label label; 046 047 private com.commercetools.history.models.label.Label previousLabel; 048 049 private java.util.List<com.commercetools.history.models.change.Change> changes; 050 051 private com.commercetools.history.models.common.ResourceIdentifier resource; 052 053 private java.util.List<com.commercetools.history.models.common.KeyReference> stores; 054 055 private Boolean withoutChanges; 056 057 /** 058 * <p>Version of the resource after the change.</p> 059 * <p>For more information on how the version is incremented, see Optimistic Concurrency Control.</p> 060 * @param version value to be set 061 * @return Builder 062 */ 063 064 public RecordBuilder version(final Integer version) { 065 this.version = version; 066 return this; 067 } 068 069 /** 070 * <p>Version of the resource before the change.</p> 071 * @param previousVersion value to be set 072 * @return Builder 073 */ 074 075 public RecordBuilder previousVersion(final Integer previousVersion) { 076 this.previousVersion = previousVersion; 077 return this; 078 } 079 080 /** 081 * <p>Indicates the type of change. For creation, update, or deletion, the value is <code>"ResourceCreated"</code>, <code>"ResourceUpdated"</code>, or <code>"ResourceDeleted"</code> respectively.</p> 082 * @param type value to be set 083 * @return Builder 084 */ 085 086 public RecordBuilder type(final String type) { 087 this.type = type; 088 return this; 089 } 090 091 /** 092 * <p>Information about the user or API Client who performed the change.</p> 093 * @param builder function to build the modifiedBy value 094 * @return Builder 095 */ 096 097 public RecordBuilder modifiedBy( 098 Function<com.commercetools.history.models.change_history.ModifiedByBuilder, com.commercetools.history.models.change_history.ModifiedByBuilder> builder) { 099 this.modifiedBy = builder.apply(com.commercetools.history.models.change_history.ModifiedByBuilder.of()).build(); 100 return this; 101 } 102 103 /** 104 * <p>Information about the user or API Client who performed the change.</p> 105 * @param builder function to build the modifiedBy value 106 * @return Builder 107 */ 108 109 public RecordBuilder withModifiedBy( 110 Function<com.commercetools.history.models.change_history.ModifiedByBuilder, com.commercetools.history.models.change_history.ModifiedBy> builder) { 111 this.modifiedBy = builder.apply(com.commercetools.history.models.change_history.ModifiedByBuilder.of()); 112 return this; 113 } 114 115 /** 116 * <p>Information about the user or API Client who performed the change.</p> 117 * @param modifiedBy value to be set 118 * @return Builder 119 */ 120 121 public RecordBuilder modifiedBy(final com.commercetools.history.models.change_history.ModifiedBy modifiedBy) { 122 this.modifiedBy = modifiedBy; 123 return this; 124 } 125 126 /** 127 * <p>Date and time (UTC) when the change was made.</p> 128 * @param modifiedAt value to be set 129 * @return Builder 130 */ 131 132 public RecordBuilder modifiedAt(final String modifiedAt) { 133 this.modifiedAt = modifiedAt; 134 return this; 135 } 136 137 /** 138 * <p>Information that describes the resource after the change.</p> 139 * @param label value to be set 140 * @return Builder 141 */ 142 143 public RecordBuilder label(final com.commercetools.history.models.label.Label label) { 144 this.label = label; 145 return this; 146 } 147 148 /** 149 * <p>Information that describes the resource after the change.</p> 150 * @param builder function to build the label value 151 * @return Builder 152 */ 153 154 public RecordBuilder label( 155 Function<com.commercetools.history.models.label.LabelBuilder, Builder<? extends com.commercetools.history.models.label.Label>> builder) { 156 this.label = builder.apply(com.commercetools.history.models.label.LabelBuilder.of()).build(); 157 return this; 158 } 159 160 /** 161 * <p>Information that describes the resource before the change.</p> 162 * @param previousLabel value to be set 163 * @return Builder 164 */ 165 166 public RecordBuilder previousLabel(final com.commercetools.history.models.label.Label previousLabel) { 167 this.previousLabel = previousLabel; 168 return this; 169 } 170 171 /** 172 * <p>Information that describes the resource before the change.</p> 173 * @param builder function to build the previousLabel value 174 * @return Builder 175 */ 176 177 public RecordBuilder previousLabel( 178 Function<com.commercetools.history.models.label.LabelBuilder, Builder<? extends com.commercetools.history.models.label.Label>> builder) { 179 this.previousLabel = builder.apply(com.commercetools.history.models.label.LabelBuilder.of()).build(); 180 return this; 181 } 182 183 /** 184 * <p>Shows the differences in the resource between <code>previousVersion</code> and <code>version</code>.</p> 185 * <p>The value is not identical to the actual array of update actions sent and is not limited to update actions (see, for example, Optimistic Concurrency Control).</p> 186 * @param changes value to be set 187 * @return Builder 188 */ 189 190 public RecordBuilder changes(final com.commercetools.history.models.change.Change... changes) { 191 this.changes = new ArrayList<>(Arrays.asList(changes)); 192 return this; 193 } 194 195 /** 196 * <p>Shows the differences in the resource between <code>previousVersion</code> and <code>version</code>.</p> 197 * <p>The value is not identical to the actual array of update actions sent and is not limited to update actions (see, for example, Optimistic Concurrency Control).</p> 198 * @param changes value to be set 199 * @return Builder 200 */ 201 202 public RecordBuilder changes(final java.util.List<com.commercetools.history.models.change.Change> changes) { 203 this.changes = changes; 204 return this; 205 } 206 207 /** 208 * <p>Shows the differences in the resource between <code>previousVersion</code> and <code>version</code>.</p> 209 * <p>The value is not identical to the actual array of update actions sent and is not limited to update actions (see, for example, Optimistic Concurrency Control).</p> 210 * @param changes value to be set 211 * @return Builder 212 */ 213 214 public RecordBuilder plusChanges(final com.commercetools.history.models.change.Change... changes) { 215 if (this.changes == null) { 216 this.changes = new ArrayList<>(); 217 } 218 this.changes.addAll(Arrays.asList(changes)); 219 return this; 220 } 221 222 /** 223 * <p>Shows the differences in the resource between <code>previousVersion</code> and <code>version</code>.</p> 224 * <p>The value is not identical to the actual array of update actions sent and is not limited to update actions (see, for example, Optimistic Concurrency Control).</p> 225 * @param builder function to build the changes value 226 * @return Builder 227 */ 228 229 public RecordBuilder plusChanges( 230 Function<com.commercetools.history.models.change.ChangeBuilder, Builder<? extends com.commercetools.history.models.change.Change>> builder) { 231 if (this.changes == null) { 232 this.changes = new ArrayList<>(); 233 } 234 this.changes.add(builder.apply(com.commercetools.history.models.change.ChangeBuilder.of()).build()); 235 return this; 236 } 237 238 /** 239 * <p>Shows the differences in the resource between <code>previousVersion</code> and <code>version</code>.</p> 240 * <p>The value is not identical to the actual array of update actions sent and is not limited to update actions (see, for example, Optimistic Concurrency Control).</p> 241 * @param builder function to build the changes value 242 * @return Builder 243 */ 244 245 public RecordBuilder withChanges( 246 Function<com.commercetools.history.models.change.ChangeBuilder, Builder<? extends com.commercetools.history.models.change.Change>> builder) { 247 this.changes = new ArrayList<>(); 248 this.changes.add(builder.apply(com.commercetools.history.models.change.ChangeBuilder.of()).build()); 249 return this; 250 } 251 252 /** 253 * <p>ResourceIdentifier of the changed resource.</p> 254 * @param builder function to build the resource value 255 * @return Builder 256 */ 257 258 public RecordBuilder resource( 259 Function<com.commercetools.history.models.common.ResourceIdentifierBuilder, com.commercetools.history.models.common.ResourceIdentifierBuilder> builder) { 260 this.resource = builder.apply(com.commercetools.history.models.common.ResourceIdentifierBuilder.of()).build(); 261 return this; 262 } 263 264 /** 265 * <p>ResourceIdentifier of the changed resource.</p> 266 * @param builder function to build the resource value 267 * @return Builder 268 */ 269 270 public RecordBuilder withResource( 271 Function<com.commercetools.history.models.common.ResourceIdentifierBuilder, com.commercetools.history.models.common.ResourceIdentifier> builder) { 272 this.resource = builder.apply(com.commercetools.history.models.common.ResourceIdentifierBuilder.of()); 273 return this; 274 } 275 276 /** 277 * <p>ResourceIdentifier of the changed resource.</p> 278 * @param resource value to be set 279 * @return Builder 280 */ 281 282 public RecordBuilder resource(final com.commercetools.history.models.common.ResourceIdentifier resource) { 283 this.resource = resource; 284 return this; 285 } 286 287 /** 288 * <p>References to the Stores associated with the Change.</p> 289 * @param stores value to be set 290 * @return Builder 291 */ 292 293 public RecordBuilder stores(final com.commercetools.history.models.common.KeyReference... stores) { 294 this.stores = new ArrayList<>(Arrays.asList(stores)); 295 return this; 296 } 297 298 /** 299 * <p>References to the Stores associated with the Change.</p> 300 * @param stores value to be set 301 * @return Builder 302 */ 303 304 public RecordBuilder stores(final java.util.List<com.commercetools.history.models.common.KeyReference> stores) { 305 this.stores = stores; 306 return this; 307 } 308 309 /** 310 * <p>References to the Stores associated with the Change.</p> 311 * @param stores value to be set 312 * @return Builder 313 */ 314 315 public RecordBuilder plusStores(final com.commercetools.history.models.common.KeyReference... stores) { 316 if (this.stores == null) { 317 this.stores = new ArrayList<>(); 318 } 319 this.stores.addAll(Arrays.asList(stores)); 320 return this; 321 } 322 323 /** 324 * <p>References to the Stores associated with the Change.</p> 325 * @param builder function to build the stores value 326 * @return Builder 327 */ 328 329 public RecordBuilder plusStores( 330 Function<com.commercetools.history.models.common.KeyReferenceBuilder, com.commercetools.history.models.common.KeyReferenceBuilder> builder) { 331 if (this.stores == null) { 332 this.stores = new ArrayList<>(); 333 } 334 this.stores.add(builder.apply(com.commercetools.history.models.common.KeyReferenceBuilder.of()).build()); 335 return this; 336 } 337 338 /** 339 * <p>References to the Stores associated with the Change.</p> 340 * @param builder function to build the stores value 341 * @return Builder 342 */ 343 344 public RecordBuilder withStores( 345 Function<com.commercetools.history.models.common.KeyReferenceBuilder, com.commercetools.history.models.common.KeyReferenceBuilder> builder) { 346 this.stores = new ArrayList<>(); 347 this.stores.add(builder.apply(com.commercetools.history.models.common.KeyReferenceBuilder.of()).build()); 348 return this; 349 } 350 351 /** 352 * <p>References to the Stores associated with the Change.</p> 353 * @param builder function to build the stores value 354 * @return Builder 355 */ 356 357 public RecordBuilder addStores( 358 Function<com.commercetools.history.models.common.KeyReferenceBuilder, com.commercetools.history.models.common.KeyReference> builder) { 359 return plusStores(builder.apply(com.commercetools.history.models.common.KeyReferenceBuilder.of())); 360 } 361 362 /** 363 * <p>References to the Stores associated with the Change.</p> 364 * @param builder function to build the stores value 365 * @return Builder 366 */ 367 368 public RecordBuilder setStores( 369 Function<com.commercetools.history.models.common.KeyReferenceBuilder, com.commercetools.history.models.common.KeyReference> builder) { 370 return stores(builder.apply(com.commercetools.history.models.common.KeyReferenceBuilder.of())); 371 } 372 373 /** 374 * <p><code>true</code> if no change was detected.</p> 375 * <p>The version number of the resource can be increased even without any change in the resource.</p> 376 * @param withoutChanges value to be set 377 * @return Builder 378 */ 379 380 public RecordBuilder withoutChanges(final Boolean withoutChanges) { 381 this.withoutChanges = withoutChanges; 382 return this; 383 } 384 385 /** 386 * <p>Version of the resource after the change.</p> 387 * <p>For more information on how the version is incremented, see Optimistic Concurrency Control.</p> 388 * @return version 389 */ 390 391 public Integer getVersion() { 392 return this.version; 393 } 394 395 /** 396 * <p>Version of the resource before the change.</p> 397 * @return previousVersion 398 */ 399 400 public Integer getPreviousVersion() { 401 return this.previousVersion; 402 } 403 404 /** 405 * <p>Indicates the type of change. For creation, update, or deletion, the value is <code>"ResourceCreated"</code>, <code>"ResourceUpdated"</code>, or <code>"ResourceDeleted"</code> respectively.</p> 406 * @return type 407 */ 408 409 public String getType() { 410 return this.type; 411 } 412 413 /** 414 * <p>Information about the user or API Client who performed the change.</p> 415 * @return modifiedBy 416 */ 417 418 public com.commercetools.history.models.change_history.ModifiedBy getModifiedBy() { 419 return this.modifiedBy; 420 } 421 422 /** 423 * <p>Date and time (UTC) when the change was made.</p> 424 * @return modifiedAt 425 */ 426 427 public String getModifiedAt() { 428 return this.modifiedAt; 429 } 430 431 /** 432 * <p>Information that describes the resource after the change.</p> 433 * @return label 434 */ 435 436 public com.commercetools.history.models.label.Label getLabel() { 437 return this.label; 438 } 439 440 /** 441 * <p>Information that describes the resource before the change.</p> 442 * @return previousLabel 443 */ 444 445 public com.commercetools.history.models.label.Label getPreviousLabel() { 446 return this.previousLabel; 447 } 448 449 /** 450 * <p>Shows the differences in the resource between <code>previousVersion</code> and <code>version</code>.</p> 451 * <p>The value is not identical to the actual array of update actions sent and is not limited to update actions (see, for example, Optimistic Concurrency Control).</p> 452 * @return changes 453 */ 454 455 public java.util.List<com.commercetools.history.models.change.Change> getChanges() { 456 return this.changes; 457 } 458 459 /** 460 * <p>ResourceIdentifier of the changed resource.</p> 461 * @return resource 462 */ 463 464 public com.commercetools.history.models.common.ResourceIdentifier getResource() { 465 return this.resource; 466 } 467 468 /** 469 * <p>References to the Stores associated with the Change.</p> 470 * @return stores 471 */ 472 473 public java.util.List<com.commercetools.history.models.common.KeyReference> getStores() { 474 return this.stores; 475 } 476 477 /** 478 * <p><code>true</code> if no change was detected.</p> 479 * <p>The version number of the resource can be increased even without any change in the resource.</p> 480 * @return withoutChanges 481 */ 482 483 public Boolean getWithoutChanges() { 484 return this.withoutChanges; 485 } 486 487 /** 488 * builds Record with checking for non-null required values 489 * @return Record 490 */ 491 public Record build() { 492 Objects.requireNonNull(version, Record.class + ": version is missing"); 493 Objects.requireNonNull(previousVersion, Record.class + ": previousVersion is missing"); 494 Objects.requireNonNull(type, Record.class + ": type is missing"); 495 Objects.requireNonNull(modifiedBy, Record.class + ": modifiedBy is missing"); 496 Objects.requireNonNull(modifiedAt, Record.class + ": modifiedAt is missing"); 497 Objects.requireNonNull(label, Record.class + ": label is missing"); 498 Objects.requireNonNull(previousLabel, Record.class + ": previousLabel is missing"); 499 Objects.requireNonNull(changes, Record.class + ": changes is missing"); 500 Objects.requireNonNull(resource, Record.class + ": resource is missing"); 501 Objects.requireNonNull(stores, Record.class + ": stores is missing"); 502 Objects.requireNonNull(withoutChanges, Record.class + ": withoutChanges is missing"); 503 return new RecordImpl(version, previousVersion, type, modifiedBy, modifiedAt, label, previousLabel, changes, 504 resource, stores, withoutChanges); 505 } 506 507 /** 508 * builds Record without checking for non-null required values 509 * @return Record 510 */ 511 public Record buildUnchecked() { 512 return new RecordImpl(version, previousVersion, type, modifiedBy, modifiedAt, label, previousLabel, changes, 513 resource, stores, withoutChanges); 514 } 515 516 /** 517 * factory method for an instance of RecordBuilder 518 * @return builder 519 */ 520 public static RecordBuilder of() { 521 return new RecordBuilder(); 522 } 523 524 /** 525 * create builder for Record instance 526 * @param template instance with prefilled values for the builder 527 * @return builder 528 */ 529 public static RecordBuilder of(final Record template) { 530 RecordBuilder builder = new RecordBuilder(); 531 builder.version = template.getVersion(); 532 builder.previousVersion = template.getPreviousVersion(); 533 builder.type = template.getType(); 534 builder.modifiedBy = template.getModifiedBy(); 535 builder.modifiedAt = template.getModifiedAt(); 536 builder.label = template.getLabel(); 537 builder.previousLabel = template.getPreviousLabel(); 538 builder.changes = template.getChanges(); 539 builder.resource = template.getResource(); 540 builder.stores = template.getStores(); 541 builder.withoutChanges = template.getWithoutChanges(); 542 return builder; 543 } 544 545}