View Javadoc
1   package net.sumaris.core.model.referential.location;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Core
6    * %%
7    * Copyright (C) 2018 - 2019 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.io.Serializable;
26  import java.util.Arrays;
27  
28  public enum LocationClassificationEnum implements Serializable {
29  
30  
31      LAND(1, "LAND"),
32      SEA(2, "SEA")
33      ;
34  
35      public static LocationClassificationEnum valueOf(final int id) {
36          return Arrays.stream(values())
37                  .filter(classification -> classification.id == id)
38                  .findFirst()
39                  .orElseThrow(() -> new IllegalArgumentException("Unknown LocationClassificationEnum: " + id));
40      }
41  
42      public static LocationClassificationEnum byLabel(final String label) {
43          return Arrays.stream(values())
44                  .filter(classification -> label.equals(classification.label))
45                  .findFirst()
46                  .orElseThrow(() -> new IllegalArgumentException("Unknown LocationClassificationEnum: " + label));
47      }
48  
49      private int id;
50      private String label;
51  
52      LocationClassificationEnum(int id, String label) {
53          this.id = id;
54          this.label = label;
55      }
56  
57      public int getId() {
58          return id;
59      }
60  
61      public void setId(int id) {
62          this.id = id;
63      }
64  
65      public String getLabel() {
66          return label;
67      }
68  
69      public void setLabel(String label) {
70          this.label = label;
71      }
72  
73  }