View Javadoc
1   package fr.ifremer.tutti.persistence.entities.referential;
2   
3   /*
4    * #%L
5    * Tutti :: Persistence
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
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 com.google.common.base.Predicate;
26  
27  import java.util.Collection;
28  import java.util.Iterator;
29  
30  public class CaracteristicQualitativeValues extends AbstractCaracteristicQualitativeValues {
31  
32      public static CaracteristicQualitativeValue getQualitativeValue(Caracteristic caracteristic, Integer qualitativeValueId) {
33          CaracteristicQualitativeValue value = null;
34          for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) {
35              if (qualitativeValueId.equals(qv.getIdAsInt())) {
36                  value = qv;
37                  break;
38              }
39          }
40          return value;
41      }
42  
43      public static CaracteristicQualitativeValue getQualitativeValue(Caracteristic caracteristic, String qualitativeValueId) {
44          CaracteristicQualitativeValue value = null;
45          for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) {
46              if (qualitativeValueId.equals(qv.getId())) {
47                  value = qv;
48                  break;
49              }
50          }
51          return value;
52      }
53  
54      public static void removeQualitativeValue(Collection<CaracteristicQualitativeValue> values, int id) {
55          Iterator<CaracteristicQualitativeValue> iterator = values.iterator();
56          while (iterator.hasNext()) {
57              CaracteristicQualitativeValue next = iterator.next();
58              if (id == next.getIdAsInt()) {
59                  iterator.remove();
60                  break;
61              }
62          }
63      }
64  
65      protected static class CaracteristicQualitativeValuePredicate implements Predicate<CaracteristicQualitativeValue> {
66  
67          private final Integer id;
68  
69          public CaracteristicQualitativeValuePredicate(Integer id) {
70              this.id = id;
71          }
72  
73          @Override
74          public boolean apply(CaracteristicQualitativeValue input) {
75              return id.equals(input.getIdAsInt());
76          }
77      }
78  }