View Javadoc
1   /*
2    * Copyright (c) 2021 Kaiserpfalz EDV-Service, Roland T. Lichti.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16   */
17  
18  package de.kaiserpfalzedv.rpg.core.dice.mat;
19  
20  import com.fasterxml.jackson.annotation.JsonInclude;
21  import lombok.*;
22  import lombok.extern.jackson.Jacksonized;
23  import org.eclipse.microprofile.openapi.annotations.media.Schema;
24  
25  import java.io.Serializable;
26  import java.util.ArrayList;
27  import java.util.List;
28  import java.util.Optional;
29  import java.util.StringJoiner;
30  
31  
32  /**
33   * RollTotal -- The result of a numeric die result.
34   *
35   * This is the result of a numeric die roll.
36   */
37  @Jacksonized
38  @Builder(toBuilder = true)
39  @AllArgsConstructor
40  @NoArgsConstructor
41  @Getter
42  @ToString
43  @EqualsAndHashCode
44  @JsonInclude(JsonInclude.Include.NON_ABSENT)
45  @Schema(name = "RollTotal", description = "A generic result of a die roll.")
46  public class RollTotal implements Serializable {
47      @Builder.Default
48      private final List<ExpressionTotal> expressions = new ArrayList<>();
49  
50      @Builder.Default
51      private final Optional<String> comment = Optional.empty();
52  
53      public String getDescription() {
54          StringJoiner result = new StringJoiner(" - ");
55  
56          for (ExpressionTotal r : getExpressions()) {
57              result.add(r.getDescription());
58          }
59  
60          return result.toString();
61      }
62  
63      /**
64       * Checks if there are any results from this roll.
65       *
66       * @return FALSE if there is at least one result, TRUE if there are no results
67       */
68      public boolean isEmpty() {
69          return getExpressions().size() == 0;
70      }
71  }