1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.persistence.fetch;
|
11
|
|
12
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
13
|
|
14
|
|
15
|
/**
|
16
|
* @author a.mueller
|
17
|
* @since 30.04.2008
|
18
|
* @version 1.0
|
19
|
*/
|
20
|
public class CdmFetch {
|
21
|
private static final Logger logger = LogManager.getLogger(CdmFetch.class);
|
22
|
|
23
|
public static CdmFetch NO_FETCH() {return new CdmFetch(0);}
|
24
|
public static CdmFetch FETCH_NOTHING() {return new CdmFetch(0);}
|
25
|
|
26
|
public static CdmFetch FETCH_DESCRIPTIONS() {return new CdmFetch(1);}
|
27
|
public static CdmFetch FETCH_CHILDTAXA() {return new CdmFetch(2);}
|
28
|
public static CdmFetch FETCH_PARENT_TAXA() {return new CdmFetch(3);}
|
29
|
public static CdmFetch FETCH_ANNOTATIONS_ALL() {return new CdmFetch(4);}
|
30
|
public static CdmFetch FETCH_MARKER_ALL() {return new CdmFetch(5);}
|
31
|
public static CdmFetch FETCH_SYNONYMS() {return new CdmFetch(6);}
|
32
|
|
33
|
protected int fetchSum;
|
34
|
|
35
|
private CdmFetch(int fetchId) {
|
36
|
this.fetchSum = (int)Math.pow(2, fetchId);
|
37
|
}
|
38
|
|
39
|
public void add(CdmFetch cdmFetch) {
|
40
|
this.fetchSum = (this.fetchSum | cdmFetch.fetchSum);
|
41
|
}
|
42
|
|
43
|
public boolean includes(CdmFetch cdmFetch){
|
44
|
int andFetch = cdmFetch.fetchSum & this.fetchSum;
|
45
|
if (andFetch == cdmFetch.fetchSum){
|
46
|
return true;
|
47
|
}else{
|
48
|
return false;
|
49
|
}
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* @param args
|
54
|
*/
|
55
|
public static void main(String[] args) {
|
56
|
CdmFetch fetch1 = FETCH_DESCRIPTIONS();
|
57
|
CdmFetch fetch2 = FETCH_MARKER_ALL();
|
58
|
CdmFetch fetch3 = FETCH_SYNONYMS();
|
59
|
CdmFetch fetch4 = FETCH_DESCRIPTIONS();
|
60
|
|
61
|
fetch1.add(fetch2);
|
62
|
logger.warn(fetch3.includes(fetch1));
|
63
|
logger.warn(fetch1.includes(fetch2));
|
64
|
logger.warn(fetch2.includes(fetch1));
|
65
|
fetch2.add(fetch3);
|
66
|
logger.warn(fetch2.includes(fetch1));
|
67
|
fetch2.add(fetch3);
|
68
|
logger.warn(fetch1.includes(fetch4));
|
69
|
}
|
70
|
|
71
|
}
|