View Javadoc
1   /*
2    * Copyright (c) &today.year 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 <http://www.gnu.org/licenses/>.
16   */
17  
18  package de.kaiserpfalzedv.rpg.core.dice.history;
19  
20  import com.fasterxml.jackson.annotation.JsonIgnore;
21  import com.fasterxml.jackson.annotation.JsonInclude;
22  
23  import de.kaiserpfalzedv.commons.api.resources.SerializableList;
24  import de.kaiserpfalzedv.commons.core.resources.ResourceImpl;
25  import lombok.AllArgsConstructor;
26  import lombok.EqualsAndHashCode;
27  import lombok.Getter;
28  import lombok.ToString;
29  import lombok.experimental.SuperBuilder;
30  import lombok.extern.jackson.Jacksonized;
31  import org.eclipse.microprofile.openapi.annotations.media.Schema;
32  
33  import java.util.ArrayList;
34  import java.util.List;
35  import java.util.NoSuchElementException;
36  
37  /**
38   * RollHistory -- The history of rolls for an user in a session.
39   *
40   * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
41   * @since 1.2.0  2021-02-05
42   */
43  @Jacksonized
44  @SuperBuilder(toBuilder = true)
45  @AllArgsConstructor
46  @Getter
47  @ToString(callSuper = true)
48  @EqualsAndHashCode(callSuper = true)
49  @JsonInclude(JsonInclude.Include.NON_ABSENT)
50  @Schema(name = "RollHistory", description = "The roll history of an user in a special channel.")
51  public class RollHistory extends ResourceImpl<SerializableList<RollHistoryEntry>> {
52      public static String KIND = "RollHistory";
53      public static String API_VERSION = "v1";
54  
55      /**
56       * @return The list of history entries.
57       */
58      @JsonIgnore
59      public List<RollHistoryEntry> getList() {
60          try {
61              return getData().orElseThrow();
62          } catch (NoSuchElementException e) {
63              return new ArrayList<>();
64          }
65      }
66  }