View Javadoc
1   package fr.ifremer.tutti.service.bigfin.signs;
2   
3   /*
4    * #%L
5    * Tutti :: Service
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
25   */
26  
27  import com.google.common.base.Function;
28  import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId;
29  import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId;
30  import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
31  import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
32  import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValues;
33  import fr.ifremer.tutti.service.bigfin.csv.BigfinDataRow;
34  
35  import java.util.Map;
36  
37  /**
38   * Created on 2/3/15.
39   *
40   * @author Tony Chemit - chemit@codelutin.com
41   * @since 3.13
42   */
43  public enum Size implements Sign {
44  
45      //    classe de taille, 1 = petit ; 2 = gros ; 0 = pas de classe de taille (saisie libre donc risque fort de mauvaise saisie)
46      NOT_SIZED("0") {
47          @Override
48          public Integer getCategory() {
49              return PmfmId.SIZE_CATEGORY.getValue();
50          }
51  
52          @Override
53          public Integer getQualitativeValueId() {
54              return QualitativeValueId.UNSORTED.getValue();
55          }
56  
57          @Override
58          public boolean isNullEquivalent(int parentSignChildrenNb) {
59              return true;
60          }
61  
62      },
63      SMALL("1") {
64          @Override
65          public Integer getCategory() {
66              return PmfmId.SIZE_CATEGORY.getValue();
67          }
68  
69          @Override
70          public Integer getQualitativeValueId() {
71              return QualitativeValueId.SIZE_SMALL.getValue();
72          }
73  
74          @Override
75          public boolean isNullEquivalent(int parentSignChildrenNb) {
76              return false;
77          }
78      },
79      BIG("2") {
80          @Override
81          public Integer getCategory() {
82              return PmfmId.SIZE_CATEGORY.getValue();
83          }
84  
85          @Override
86          public Integer getQualitativeValueId() {
87              return QualitativeValueId.SIZE_BIG.getValue();
88          }
89  
90          @Override
91          public boolean isNullEquivalent(int parentSignChildrenNb) {
92              return false;
93          }
94      };
95  
96      private String sign;
97  
98      Size(String sign) {
99          this.sign = sign;
100     }
101 
102     @Override
103     public String getSign() {
104         return sign;
105     }
106 
107     @Override
108     public void registerSign(Caracteristic caracteristic, Map<Sign, CaracteristicQualitativeValue> map) {
109         Integer valueId = getQualitativeValueId();
110         CaracteristicQualitativeValue result = CaracteristicQualitativeValues.getQualitativeValue(caracteristic, valueId);
111         map.put(this, result);
112     }
113 
114     public static Size getValue(String sign) {
115         Size result = null;
116         for (Size s : values()) {
117             if (s.sign.equals(sign)) {
118                 result = s;
119                 break;
120             }
121         }
122         return result;
123     }
124 
125     public static Function<BigfinDataRow, Sign> newExtractValueFunction() {
126         return BigfinDataRow::getSize;
127     }
128 
129 }