View Javadoc
1   package net.sumaris.core.model.referential;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Core
6    * %%
7    * Copyright (C) 2018 SUMARiS Consortium
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import java.util.Arrays;
26  import java.util.Optional;
27  
28  public enum UserProfileEnum {
29  
30      ADMIN(1, "ADMIN"),
31      USER(2, "USER"),
32      SUPERVISOR(3, "SUPERVISOR"),
33      GUEST(4, "GUEST");
34  
35      public static UserProfileEnum valueOf(final int id) {
36          return Arrays.stream(values())
37                  .filter(level -> level.id == id)
38                  .findFirst()
39                  .orElseThrow(() -> new IllegalArgumentException("Unknown UserProfileEnum: " + id));
40      }
41  
42  
43      public static Optional<String> getLabelById(int id) {
44          Optional<UserProfileEnum> enumValue = Arrays.stream(values()).filter(userProfileEnum -> userProfileEnum.id == id).findFirst();
45          return enumValue.map(Enum::toString);
46      }
47  
48      public final int id;
49      public final String label;
50  
51      UserProfileEnum(int id, String label) {
52        this.id = id;
53        this.label = label;
54      }
55  
56  
57      /**
58      * Returns the database row id
59      *
60      * @return int the id
61      */
62      public String getLabel()
63      {
64          return this.label;
65      }
66  
67      /**
68       * Returns the database row id
69       *
70       * @return int the id
71       */
72      public int getId()
73      {
74          return this.id;
75      }
76  }