1 package fr.ifremer.tutti.service.pupitri;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import com.google.common.collect.ListMultimap;
28 import com.google.common.collect.Lists;
29 import fr.ifremer.tutti.persistence.entities.referential.Species;
30 import org.apache.commons.lang3.mutable.MutableFloat;
31
32 import java.util.LinkedHashSet;
33 import java.util.List;
34 import java.util.Set;
35
36
37
38
39
40
41
42 public class CarrouselImportRequestResult {
43
44 private final ListMultimap<String, Species> speciesByCode;
45
46
47
48
49 private int nbCarrousselImported;
50
51
52
53
54 private MutableFloat carrouselSortedWeight;
55
56
57
58
59 private MutableFloat carrouselUnsortedWeight;
60
61
62
63
64 private final Set<String> notImportedSpeciesIds;
65
66
67
68
69 private final List<PupitriSpeciesContext> catches;
70
71 public CarrouselImportRequestResult(ListMultimap<String, Species> speciesByCode) {
72
73 this.speciesByCode = speciesByCode;
74 this.notImportedSpeciesIds = new LinkedHashSet<>();
75 this.catches = Lists.newArrayList();
76 }
77
78 public void incrementNbCarrousselImported() {
79 nbCarrousselImported++;
80 }
81
82 public void addCarrouselSortedWeight(Float beanWeight) {
83 if (carrouselSortedWeight == null) {
84 carrouselSortedWeight = new MutableFloat();
85 }
86 if (beanWeight != null) {
87
88 carrouselSortedWeight.add(beanWeight);
89 }
90 }
91
92 public void addCarrouselUnsortedWeight(Float beanWeight) {
93 if (carrouselUnsortedWeight == null) {
94 carrouselUnsortedWeight = new MutableFloat();
95 }
96 if (beanWeight != null) {
97
98 carrouselUnsortedWeight.add(beanWeight);
99 }
100 }
101
102 public List<Species> getSpecies(String speciesId) {
103 return speciesByCode.get(speciesId);
104 }
105
106 public void addNotImportedSpeciesId(String speciesId) {
107 notImportedSpeciesIds.add(speciesId);
108 }
109
110 public PupitriSpeciesContext getOrCreateCatch(List<Species> speciesList,
111 boolean createMissingSigns,
112 boolean sorted) {
113
114
115
116 Species species = speciesList.get(0);
117 PupitriSpeciesContext pupitriSpeciesContext = new PupitriSpeciesContext(species,
118 createMissingSigns,
119 sorted);
120 int catchIndex = catches.indexOf(pupitriSpeciesContext);
121 if (catchIndex >= 0) {
122 pupitriSpeciesContext = catches.get(catchIndex);
123 } else {
124 catches.add(pupitriSpeciesContext);
125 }
126 return pupitriSpeciesContext;
127
128 }
129
130 public float getCarrouselSortedWeight() {
131 return carrouselSortedWeight == null ? 0f : carrouselSortedWeight.floatValue();
132 }
133
134 public float getCarrouselUnsortedWeight() {
135 return carrouselUnsortedWeight == null ? 0f : carrouselUnsortedWeight.floatValue();
136 }
137
138 public int getNbCarrousselImported() {
139 return nbCarrousselImported;
140 }
141
142 public Set<String> getNotImportedSpeciesIds() {
143 return notImportedSpeciesIds;
144 }
145
146 public List<PupitriSpeciesContext> getCatches() {
147 return catches;
148 }
149 }