TransactionBuilder.java

  1. /*
  2.  * Copyright 2005-2025 the original author or authors.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  * http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.openwms.common.spi.transactions;

  17. import java.util.Map;

  18. /**
  19.  * A TransactionBuilder.
  20.  *
  21.  * @author Heiko Scherrer
  22.  */
  23. public final class TransactionBuilder {

  24.     private TransactionVO transactionVO;

  25.     private TransactionBuilder() {
  26.         transactionVO = new TransactionVO();
  27.     }

  28.     public static TransactionBuilder aTransactionVO() {
  29.         return new TransactionBuilder();
  30.     }

  31.     public TransactionBuilder withDescription(String description) {
  32.         transactionVO.setDescription(description);
  33.         return this;
  34.     }

  35.     public TransactionBuilder withType(String type) {
  36.         transactionVO.setType(type);
  37.         return this;
  38.     }

  39.     public TransactionBuilder withCreatedByUser(String createdByUser) {
  40.         transactionVO.setCreatedByUser(createdByUser);
  41.         return this;
  42.     }

  43.     public TransactionBuilder withSender(String sender) {
  44.         transactionVO.setSender(sender);
  45.         return this;
  46.     }

  47.     public TransactionBuilder withDetail(String key, String value) {
  48.         transactionVO.addDetail(key, value);
  49.         return this;
  50.     }

  51.     public TransactionBuilder withDetails(Map<String, String> details) {
  52.         transactionVO.setDetails(details);
  53.         return this;
  54.     }

  55.     public TransactionBuilder but() {
  56.         return aTransactionVO().withDescription(transactionVO.getDescription()).withType(transactionVO.getType()).withCreatedByUser(transactionVO.getCreatedByUser()).withSender(transactionVO.getSender()).withDetails(transactionVO.getDetails());
  57.     }

  58.     public TransactionVO build() {
  59.         return transactionVO;
  60.     }
  61. }