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