Project

General

Profile

Download (2.72 KB) Statistics
| Branch: | Tag: | Revision:
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.filter;
11

    
12
import java.io.Serializable;
13
import java.util.UUID;
14

    
15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.cdm.model.common.ITreeNode;
17

    
18
/**
19
 * Preliminary class which represents a filter for an export on a CdmBase object, combined
20
 * with a logical operation.
21
 * Added to an existing filter it may e.g. allow operations like "filter1 or filter(TaxonNode:123)"
22
 * It includes the logical operators as enums.
23
 *
24
 * @author a.mueller
25
 *
26
 */
27
public class LogicFilter<T extends CdmBase> implements Serializable{
28

    
29
    public enum Op{
30
        OR, AND, NOT;
31
//      OR(" OR "), AND(" AND "), NOT(" NOT ");
32
//          String str;
33
//
34
//      private Op(String opStr){
35
//          str = opStr;
36
//      }
37
    }
38

    
39
    private static final Op defaultOperator = Op.OR;
40

    
41
    private Op operator = defaultOperator;
42

    
43
    private UUID uuid;
44
    private String treeIndex;
45
    private Class<? extends T> clazz;
46

    
47
//  private boolean hasUncheckedUuid = false;
48

    
49

    
50

    
51
    public LogicFilter(T cdmBase){
52
        this(cdmBase, defaultOperator);
53
    }
54

    
55
    public LogicFilter(Class<? extends T> clazz, UUID uuid, Op operator) {
56
//        hasUncheckedUuid = true;
57
        if (uuid == null){
58
            throw new IllegalArgumentException("Null uuid not allowed as filter criteria");
59
        }
60
        if (operator == null){
61
            operator = defaultOperator;
62
        }
63

    
64
        this.uuid = uuid;
65
        this.operator = operator;
66
        this.clazz = clazz;
67

    
68
    }
69

    
70
    public <S extends T> LogicFilter(S cdmBase, Op operator){
71
        if (cdmBase == null){
72
            throw new IllegalArgumentException("Null object not allowed as filter criteria");
73
        }
74
        if (operator == null){
75
            operator = defaultOperator;
76
        }
77
        cdmBase = CdmBase.deproxy(cdmBase);
78

    
79
        this.uuid = cdmBase.getUuid();
80
        this.operator = operator;
81
        this.clazz = (Class)cdmBase.getClass();
82
        if (cdmBase instanceof ITreeNode){
83
            this.treeIndex = ((ITreeNode<?>)cdmBase).treeIndex();
84
        }
85
    }
86

    
87

    
88

    
89
    public Op getOperator() {
90
        return operator;
91
    }
92

    
93
    public UUID getUuid() {
94
        return uuid;
95
    }
96

    
97
    public String getTreeIndex() {
98
        return treeIndex;
99
    }
100

    
101
    public Class<? extends T> getClazz() {
102
        return clazz;
103
    }
104

    
105
    /**
106
     * TODO try to remove public setter
107
     * @deprecated for internal use only
108
     */
109

    
110
    @Deprecated
111
    public void setTreeIndex(String treeIndex) {
112
        this.treeIndex = treeIndex;
113
    }
114

    
115
}
116

    
(1-1/2)