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