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.referential.pmfm; 24 25 import java.io.Serializable; 26 import java.util.Arrays; 27 28 public enum UnitEnum implements Serializable { 29 30 NONE(0, "None"), 31 MM(1, "mm"), 32 CM(12, "cm") 33 ; 34 35 public static UnitEnum valueOf(final int id) { 36 return Arrays.stream(values()) 37 .filter(level -> level.id == id) 38 .findFirst() 39 .orElseThrow(() -> new IllegalArgumentException("Unknown UnitEnum: " + id)); 40 } 41 42 private int id; 43 private String label; 44 45 UnitEnum(int id, String label) { 46 this.id = id; 47 this.label = label; 48 } 49 50 /** 51 * Returns the database row id 52 * 53 * @return int the id 54 */ 55 public int getId() 56 { 57 return this.id; 58 } 59 60 public String getLabel() 61 { 62 return this.label; 63 } 64 }