KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > data > util > NamedColumnProjection


1 package prefuse.data.util;
2
3 import java.util.HashSet JavaDoc;
4
5 import prefuse.data.column.Column;
6
7 /**
8  * ColumnProjection instance that includes or excludes columns based on
9  * 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 JavaDoc 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 JavaDoc name, boolean include) {
25         m_names = new HashSet JavaDoc();
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 JavaDoc[] names, boolean include) {
37         m_names = new HashSet JavaDoc();
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 JavaDoc 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 JavaDoc 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 JavaDoc name) {
64         return !(m_include ^ m_names.contains(name));
65     }
66
67 } // end of class NamedColumnProjection
68
Popular Tags