blob: deb1419fcc07e029abd0f89021e80ddb8b57ebe0 (
plain)
1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package ATCCodes;
import java.util.Objects;
/**
* ATC-Code as used in WHO XML file
*
* @author Paul-Christian Volkmer
* @since 0.1.0
*/
public class AtcCode implements AgentCode {
private final String code;
private final String name;
public AtcCode(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
public CodeSystem getSystem() {
return CodeSystem.ATC;
}
@Override
public int compareTo(final AgentCode agentCode) {
return this.name.toLowerCase().compareTo(agentCode.getName().toLowerCase());
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AgentCode otherAgentCode = (AgentCode) o;
return Objects.equals(code.toLowerCase(), otherAgentCode.getCode().toLowerCase())
&& Objects.equals(name.toLowerCase(), otherAgentCode.getName().toLowerCase());
}
@Override
public int hashCode() {
return Objects.hash(code.toLowerCase(), name.toLowerCase());
}
/**
* Prüft auf gültiges ATCCode-Schema ab Ebene 2
* @param code Der zu prüfende Code
* @return Gibt <code>true</code> zurück, wenn der angegebene Code dem ATCCode-Schema entspricht
*/
public static boolean isAtcCode(String code) {
return null != code
&& ! code.isBlank()
&& code.matches("[ABCDGHJLMNPRSV][0-2][1-9]([A-Z]([A-Z]([0-9]{2})?)?)?");
}
}
|