~keheliya-gallaba/gephi/maven-build

« back to all changes in this revision

Viewing changes to filters/src/main/java/org/gephi/filters/FilterQueryImpl.java

  • Committer: Keheliya Gallaba
  • Date: 2011-08-01 13:01:30 UTC
  • Revision ID: keheliya.gallaba@gmail.com-20110801130130-0u2qgcufi8bvqwxv
Adding Export Plugin, Export Plugin UI, Filters Impl

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2008-2010 Gephi
 
3
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
 
4
Website : http://www.gephi.org
 
5
 
 
6
This file is part of Gephi.
 
7
 
 
8
Gephi is free software: you can redistribute it and/or modify
 
9
it under the terms of the GNU Affero General Public License as
 
10
published by the Free Software Foundation, either version 3 of the
 
11
License, or (at your option) any later version.
 
12
 
 
13
Gephi is distributed in the hope that it will be useful,
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
GNU Affero General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU Affero General Public License
 
19
along with Gephi.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
package org.gephi.filters;
 
22
 
 
23
import org.gephi.filters.spi.Filter;
 
24
import org.gephi.filters.spi.FilterProperty;
 
25
 
 
26
/**
 
27
 *
 
28
 * @author Mathieu Bastian
 
29
 */
 
30
public class FilterQueryImpl extends AbstractQueryImpl {
 
31
 
 
32
    private Parameters[] parameters;
 
33
    private Filter filter;
 
34
    private String name;
 
35
 
 
36
    public FilterQueryImpl(Filter filter) {
 
37
        this.filter = filter;
 
38
        this.name = filter.getName();
 
39
        updateParameters();
 
40
    }
 
41
 
 
42
    public final void updateParameters() {
 
43
        FilterProperty[] properties = filter.getProperties();
 
44
        parameters = new Parameters[properties == null ? 0 : properties.length];
 
45
        if (properties != null) {
 
46
            for (int i = 0; i < properties.length; i++) {
 
47
                parameters[i] = new Parameters(i, properties[i].getValue());
 
48
            }
 
49
        }
 
50
    }
 
51
 
 
52
    @Override
 
53
    public int getChildrenSlotsCount() {
 
54
        return 1;
 
55
    }
 
56
 
 
57
    @Override
 
58
    public String getName() {
 
59
        return name;
 
60
    }
 
61
 
 
62
    @Override
 
63
    public void setName(String name) {
 
64
        this.name = name;
 
65
    }
 
66
 
 
67
    public int getPropertiesCount() {
 
68
        return parameters.length;
 
69
    }
 
70
 
 
71
    public String getPropertyName(int index) {
 
72
        return parameters[index].getKey();
 
73
    }
 
74
 
 
75
    public Object getPropertyValue(int index) {
 
76
        return parameters[index].getValue();
 
77
    }
 
78
 
 
79
    public Filter getFilter() {
 
80
        return filter;
 
81
    }
 
82
 
 
83
    private class Parameters {
 
84
 
 
85
        private int index;
 
86
        private Object value;
 
87
 
 
88
        public Parameters(int index, Object value) {
 
89
            this.index = index;
 
90
            this.value = value;
 
91
        }
 
92
 
 
93
        public String getKey() {
 
94
            return filter.getProperties()[index].getName();
 
95
        }
 
96
 
 
97
        public Object getValue() {
 
98
            return value;
 
99
        }
 
100
    }
 
101
}