5748 |
19 Sep 11 |
nicklas |
1 |
/** |
5748 |
19 Sep 11 |
nicklas |
$Id $ |
5748 |
19 Sep 11 |
nicklas |
3 |
|
5748 |
19 Sep 11 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
5748 |
19 Sep 11 |
nicklas |
5 |
|
5748 |
19 Sep 11 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5748 |
19 Sep 11 |
nicklas |
Available at http://base.thep.lu.se/ |
5748 |
19 Sep 11 |
nicklas |
8 |
|
5748 |
19 Sep 11 |
nicklas |
BASE is free software; you can redistribute it and/or |
5748 |
19 Sep 11 |
nicklas |
modify it under the terms of the GNU General Public License |
5748 |
19 Sep 11 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5748 |
19 Sep 11 |
nicklas |
of the License, or (at your option) any later version. |
5748 |
19 Sep 11 |
nicklas |
13 |
|
5748 |
19 Sep 11 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5748 |
19 Sep 11 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5748 |
19 Sep 11 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5748 |
19 Sep 11 |
nicklas |
GNU General Public License for more details. |
5748 |
19 Sep 11 |
nicklas |
18 |
|
5748 |
19 Sep 11 |
nicklas |
You should have received a copy of the GNU General Public License |
5748 |
19 Sep 11 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5748 |
19 Sep 11 |
nicklas |
21 |
*/ |
5748 |
19 Sep 11 |
nicklas |
22 |
package net.sf.basedb.util.overview.filter; |
5748 |
19 Sep 11 |
nicklas |
23 |
|
5748 |
19 Sep 11 |
nicklas |
24 |
import net.sf.basedb.util.filter.Filter; |
5748 |
19 Sep 11 |
nicklas |
25 |
import net.sf.basedb.util.overview.Node; |
5748 |
19 Sep 11 |
nicklas |
26 |
import net.sf.basedb.util.overview.NodeAttribute; |
5748 |
19 Sep 11 |
nicklas |
27 |
|
5748 |
19 Sep 11 |
nicklas |
28 |
/** |
5748 |
19 Sep 11 |
nicklas |
A filter implementation that checks if a value for a given attribute |
6455 |
09 May 14 |
nicklas |
exists on a node. It will evaluate to true for all {@link Node}:s that |
5748 |
19 Sep 11 |
nicklas |
has a value for a specific attribute. |
5748 |
19 Sep 11 |
nicklas |
32 |
|
5748 |
19 Sep 11 |
nicklas |
@author Nicklas |
5748 |
19 Sep 11 |
nicklas |
@since 3.0 |
5748 |
19 Sep 11 |
nicklas |
@base.modified $Date $ |
5748 |
19 Sep 11 |
nicklas |
36 |
*/ |
5748 |
19 Sep 11 |
nicklas |
37 |
public class HasAttributeFilter |
5748 |
19 Sep 11 |
nicklas |
38 |
implements Filter<Node> |
5748 |
19 Sep 11 |
nicklas |
39 |
{ |
5748 |
19 Sep 11 |
nicklas |
40 |
|
5748 |
19 Sep 11 |
nicklas |
41 |
private final NodeAttribute<?> attribute; |
6455 |
09 May 14 |
nicklas |
42 |
private final Object value; |
5748 |
19 Sep 11 |
nicklas |
43 |
|
5748 |
19 Sep 11 |
nicklas |
44 |
/** |
5748 |
19 Sep 11 |
nicklas |
Create a filter that finds nodes that has value for the given |
5748 |
19 Sep 11 |
nicklas |
attribute. |
5748 |
19 Sep 11 |
nicklas |
@param attribute The attribute to check |
5748 |
19 Sep 11 |
nicklas |
48 |
*/ |
5748 |
19 Sep 11 |
nicklas |
49 |
public HasAttributeFilter(NodeAttribute<?> attribute) |
5748 |
19 Sep 11 |
nicklas |
50 |
{ |
6455 |
09 May 14 |
nicklas |
51 |
this(attribute, null); |
6455 |
09 May 14 |
nicklas |
52 |
} |
6455 |
09 May 14 |
nicklas |
53 |
|
6455 |
09 May 14 |
nicklas |
54 |
/** |
6455 |
09 May 14 |
nicklas |
Create a filter that finds nodes that has a specific value for the given |
6455 |
09 May 14 |
nicklas |
attribute. |
6455 |
09 May 14 |
nicklas |
@param attribute The attribute to check |
6455 |
09 May 14 |
nicklas |
@param value The value that must match |
6455 |
09 May 14 |
nicklas |
@since 3.3 |
6455 |
09 May 14 |
nicklas |
60 |
*/ |
6455 |
09 May 14 |
nicklas |
61 |
public HasAttributeFilter(NodeAttribute<?> attribute, Object value) |
6455 |
09 May 14 |
nicklas |
62 |
{ |
5748 |
19 Sep 11 |
nicklas |
63 |
this.attribute = attribute; |
6455 |
09 May 14 |
nicklas |
64 |
this.value = value; |
5748 |
19 Sep 11 |
nicklas |
65 |
} |
5748 |
19 Sep 11 |
nicklas |
66 |
|
5748 |
19 Sep 11 |
nicklas |
67 |
/* |
5748 |
19 Sep 11 |
nicklas |
From the Filter interface |
5748 |
19 Sep 11 |
nicklas |
69 |
------------------------- |
5748 |
19 Sep 11 |
nicklas |
70 |
*/ |
5748 |
19 Sep 11 |
nicklas |
71 |
@Override |
5748 |
19 Sep 11 |
nicklas |
72 |
public boolean evaluate(Node node) |
5748 |
19 Sep 11 |
nicklas |
73 |
{ |
6455 |
09 May 14 |
nicklas |
74 |
if (value == null) |
6455 |
09 May 14 |
nicklas |
75 |
{ |
6455 |
09 May 14 |
nicklas |
76 |
return node.hasAttribute(attribute); |
6455 |
09 May 14 |
nicklas |
77 |
} |
6455 |
09 May 14 |
nicklas |
78 |
else |
6455 |
09 May 14 |
nicklas |
79 |
{ |
6455 |
09 May 14 |
nicklas |
80 |
return value.equals(node.getAttribute(attribute)); |
6455 |
09 May 14 |
nicklas |
81 |
} |
5748 |
19 Sep 11 |
nicklas |
82 |
} |
5748 |
19 Sep 11 |
nicklas |
83 |
// ----------------------------- |
5748 |
19 Sep 11 |
nicklas |
84 |
} |