1
|
/**
|
2
|
* Copyright (C) 2019 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.model.term;
|
10
|
|
11
|
/**
|
12
|
* @author a.mueller
|
13
|
* @since 22.01.2019
|
14
|
*
|
15
|
*/
|
16
|
public interface IHasTermType {
|
17
|
|
18
|
public TermType getTermType();
|
19
|
|
20
|
/**
|
21
|
* Checks if term type of term1 is not <code>null</code>.
|
22
|
* @param term any instance implementing {@link IHasTermType}
|
23
|
* @throws IllegalStateException if term typeis <code>null</code>
|
24
|
*/
|
25
|
public static void checkTermTypeNull(IHasTermType term) {
|
26
|
if (term.getTermType()== null){
|
27
|
throw new IllegalStateException("Term types must not be null");
|
28
|
}
|
29
|
}
|
30
|
/**
|
31
|
* Checks if term types of term1 and term2 are equal
|
32
|
* and both term types are not <code>null</code>.
|
33
|
* If term1 or term2 is null nothing happens.
|
34
|
* @param term1 any instance implementing {@link IHasTermType}
|
35
|
* @param term2 any instance implementing {@link IHasTermType}
|
36
|
* @throws IllegalStateException if term types are either null or not equal
|
37
|
*/
|
38
|
public static void checkTermTypes(IHasTermType term1, IHasTermType term2) {
|
39
|
if (term1 != null && term2 != null){
|
40
|
checkTermTypeNull(term1);
|
41
|
checkTermTypeNull(term2);
|
42
|
if (term1.getTermType()!= term2.getTermType()){
|
43
|
throw new IllegalStateException("Term types must match");
|
44
|
}
|
45
|
}
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* Checks if term types of term1 and term2 are either equal
|
50
|
* term type of descendant is kind of term type of ancestor.
|
51
|
* Also both term types must not be null <code>null</code> and
|
52
|
* If ancestor or descendant is null nothing happens.
|
53
|
* @param ancestor
|
54
|
* @param descendant
|
55
|
* @throws IllegalStateException if any of the checks are not successful
|
56
|
* @see #checkTermTypes(IHasTermType, IHasTermType)
|
57
|
*/
|
58
|
public static void checkTermTypeEqualOrDescendant(IHasTermType ancestor, IHasTermType descendant){
|
59
|
if(ancestor != null && descendant != null){
|
60
|
checkTermTypeNull(ancestor);
|
61
|
checkTermTypeNull(descendant);
|
62
|
if (ancestor.getTermType()!= descendant.getTermType() && !descendant.getTermType().isKindOf(ancestor.getTermType())){
|
63
|
throw new IllegalStateException("Term types must match ");
|
64
|
}
|
65
|
}
|
66
|
}
|
67
|
}
|