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.torg.model.actors;
19  
20  import de.kaiserpfalzedv.rpg.torg.model.MapperEnum;
21  import lombok.AllArgsConstructor;
22  import lombok.Getter;
23  
24  import jakarta.validation.constraints.NotNull;
25  import java.util.List;
26  import java.util.Optional;
27  import java.util.stream.Collectors;
28  
29  /**
30   * Attribute -- The attributes defined in Torg.
31   *
32   * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
33   * @since 0.3.0  2021-05-23
34   */
35  @AllArgsConstructor
36  @Getter
37  public enum Attribute implements MapperEnum<Attribute> {
38      CHARISMA("CHA", "charisma", "attr_CHA", "charisma"),
39      DEXTERITY("DEX", "dexterity", "attr_DEX", "dexterity"),
40      MIND("MIN", "mind", "attr_MIN", "mind"),
41      SPIRIT("SPI", "spirit", "attr_SPI", "spirit"),
42      STRENGTH("STR", "strength", "attr_STR", "strength");
43  
44      private final String shortName;
45      private final String name;
46      private final String roll20;
47      private final String foundry;
48  
49      public Optional<Attribute> mapFromFoundry(@NotNull final String name) {
50          return Optional.ofNullable(
51                  allAttributes().stream()
52                          .filter(e -> e.foundry.equals(name)).distinct()
53                          .collect(Collectors.toList()).get(0)
54          );
55      }
56  
57      public Optional<Attribute> mapFromRoll20(@NotNull final String name) {
58          return Optional.ofNullable(
59                  allAttributes().stream()
60                          .filter(e -> e.roll20.equals(name)).distinct()
61                          .collect(Collectors.toList()).get(0)
62          );
63      }
64  
65      public List<Attribute> allAttributes() {
66          return List.of(
67                  CHARISMA,
68                  DEXTERITY,
69                  MIND,
70                  SPIRIT,
71                  STRENGTH
72          );
73      }
74  }