01: package prefuse.data.util;
02:
03: import java.util.HashSet;
04:
05: import prefuse.data.column.Column;
06:
07: /**
08: * ColumnProjection instance that includes or excludes columns based on
09: * the column name.
10: *
11: * @author <a href="http://jheer.org">jeffrey heer</a>
12: */
13: public class NamedColumnProjection extends AbstractColumnProjection {
14:
15: private HashSet m_names;
16: private boolean m_include;
17:
18: /**
19: * Create a new NamedColumnProjection.
20: * @param name the name to filter on
21: * @param include true to include the given names (and exclude all others),
22: * false to exclude them (and include all others)
23: */
24: public NamedColumnProjection(String name, boolean include) {
25: m_names = new HashSet();
26: m_names.add(name);
27: m_include = include;
28: }
29:
30: /**
31: * Create a new NamedColumnProjection.
32: * @param names the names to filter on
33: * @param include true to include the given names (and exclude all others),
34: * false to exclude them (and include all others)
35: */
36: public NamedColumnProjection(String[] names, boolean include) {
37: m_names = new HashSet();
38: for (int i = 0; i < names.length; ++i)
39: m_names.add(names[i]);
40: m_include = include;
41: }
42:
43: /**
44: * Add a column name to this projection.
45: * @param name the column name to add
46: */
47: public void addName(String name) {
48: m_names.add(name);
49: }
50:
51: /**
52: * Remove a column name from this projection
53: * @param name the column name to remove
54: * @return true if the name was succesffuly removed, false otherwise
55: */
56: public boolean removeName(String name) {
57: return m_names.remove(name);
58: }
59:
60: /**
61: * @see prefuse.data.util.ColumnProjection#include(prefuse.data.column.Column, java.lang.String)
62: */
63: public boolean include(Column col, String name) {
64: return !(m_include ^ m_names.contains(name));
65: }
66:
67: } // end of class NamedColumnProjection
|