1 package fr.ifremer.tutti.service.sampling;
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 java.util.Objects;
28
29
30
31
32
33 public class SamplingCodePrefix {
34
35 public static final String SEPARATOR = "#";
36 public static final String NO_SURVEY_CODE_LABEL = "~";
37
38 protected final String prefix;
39 protected final String species;
40
41 public SamplingCodePrefix(String prefix, String species) {
42 this.prefix = prefix;
43 if (SEPARATOR.equals(species)) {
44 species = NO_SURVEY_CODE_LABEL;
45 }
46 this.species = species;
47 }
48
49 public SamplingCodePrefix(String samplingCode) {
50 String[] codeParts = samplingCode.split(SEPARATOR);
51 prefix = codeParts[0];
52 species = codeParts[1];
53 }
54
55 public String getPrefix() {
56 return prefix;
57 }
58
59 public String getSpecies() {
60 return species;
61 }
62
63 @Override
64 public String toString() {
65 return prefix + SEPARATOR + species + SEPARATOR;
66 }
67
68 public String toSamplingCode(int samplingCodeId) {
69 return toString() + samplingCodeId;
70 }
71
72 public String toSpeciesOnlySamplingCode(int samplingCodeId) {
73 return species + SEPARATOR + samplingCodeId;
74 }
75
76
77
78
79
80
81 public static int extractSamplingCodeIdFromSamplingCode(String samplingCode) {
82 Objects.requireNonNull(samplingCode);
83 String[] codeParts = samplingCode.split(SEPARATOR);
84 return Integer.parseInt(codeParts[codeParts.length - 1]);
85 }
86
87 }