View Javadoc
1   package fr.ifremer.tutti.service.sampling;
2   
3   /*
4    * #%L
5    * Tutti :: Service
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2016 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.MoreObjects;
28  import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
29  import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
30  import fr.ifremer.tutti.persistence.entities.referential.Species;
31  
32  import java.util.Objects;
33  
34  /**
35   * Définit une requète sur le cache des échantillons.
36   *
37   * Created on 20/04/16.
38   *
39   * @author Tony Chemit - chemit@codelutin.com
40   * @since 4.5
41   */
42  public class IndividualObservationSamplingCacheRequest {
43  
44      private final FishingOperation fishingOperation;
45      private final Species species;
46      private final Integer lengthClass;
47      private Boolean forcedMaturity;
48      private CaracteristicQualitativeValue maturity;
49      private CaracteristicQualitativeValue gender;
50      private final String samplingCode;
51  
52      public IndividualObservationSamplingCacheRequest(FishingOperation fishingOperation,
53                                                       Species species,
54                                                       Integer lengthClass,
55                                                       CaracteristicQualitativeValue maturity,
56                                                       CaracteristicQualitativeValue gender,
57                                                       String samplingCode) {
58          this.fishingOperation = fishingOperation;
59          Objects.requireNonNull(species);
60          this.species = species;
61          this.lengthClass = lengthClass;
62          this.maturity = maturity;
63          this.gender = gender;
64          this.samplingCode = samplingCode;
65          this.forcedMaturity = null;
66      }
67  
68      public FishingOperation getFishingOperation() {
69          return fishingOperation;
70      }
71  
72      public Species getSpecies() {
73          return species;
74      }
75  
76      /**
77       * Pouvoir modifier le sexe est utile pour pouvoir sommer toutes les observations
78       * quelque soit le sexe
79       * @param gender
80       */
81      public void setGender(CaracteristicQualitativeValue gender) {
82          this.gender = gender;
83      }
84  
85      public Boolean getForcedMaturity() {
86          return forcedMaturity;
87      }
88  
89      /**
90       * Pouvoir modifier la maturite est utile pour pouvoir sommer toutes les observations
91       * quelque soit la maturite
92       * @param forcedMaturity true pour les matures, false pour les immature
93       */
94      public void setForcedMaturity(Boolean forcedMaturity) {
95          this.forcedMaturity = forcedMaturity;
96          this.maturity = null;
97      }
98  
99      public Integer getLengthClass() {
100         return lengthClass;
101     }
102 
103     public CaracteristicQualitativeValue getMaturity() {
104         return maturity;
105     }
106 
107     public CaracteristicQualitativeValue getGender() {
108         return gender;
109     }
110 
111     public String getSamplingCode() {
112         return samplingCode;
113     }
114 
115     public boolean withMaturity() {
116         return maturity != null;
117     }
118 
119     public boolean withGender() {
120         return gender != null;
121     }
122 
123     public boolean withLengthClass() {
124         return lengthClass != null;
125     }
126 
127     public boolean withSamplingCode() {
128         return samplingCode != null;
129     }
130 
131     @Override
132     public String toString() {
133 
134         MoreObjects.ToStringHelper toStringHelper = MoreObjects.toStringHelper(this)
135                                                                .add("fishingOperation", fishingOperation)
136                                                                .add("species", species);
137         if (withLengthClass()) {
138             toStringHelper.add("lengthClass", lengthClass);
139         }
140         if (withMaturity()) {
141             toStringHelper.add("maturity", maturity);
142         }
143         if (withGender()) {
144             toStringHelper.add("gender", gender);
145         }
146         if (withSamplingCode()) {
147             toStringHelper.add("samplingCode", samplingCode);
148         }
149 
150         return toStringHelper.toString();
151 
152     }
153 }