01: package prefuse.visual.expression;
02:
03: import java.util.logging.Logger;
04:
05: import prefuse.data.Tuple;
06: import prefuse.data.expression.AbstractExpression;
07: import prefuse.data.expression.Expression;
08: import prefuse.data.expression.Function;
09: import prefuse.data.expression.ObjectLiteral;
10:
11: /**
12: * Abstract base class for Expression instances dealing with data groups
13: * within a Visualization. Maintains an Expression that serves as the
14: * paremter to this Function; this Expression should return a valid
15: * group name when evaluated on a given Tuple.
16: *
17: * @author <a href="http://jheer.org">jeffrey heer</a>
18: */
19: public abstract class GroupExpression extends AbstractExpression
20: implements Function {
21: private static final Logger s_logger = Logger
22: .getLogger(GroupExpression.class.getName());
23:
24: protected Expression m_group;
25:
26: /**
27: * Create a new GroupExpression.
28: */
29: protected GroupExpression() {
30: m_group = null;
31: }
32:
33: /**
34: * Create a new GroupExpression over the given group name.
35: * @param group the data group name
36: */
37: protected GroupExpression(String group) {
38: m_group = new ObjectLiteral(group);
39: }
40:
41: /**
42: * Evaluate the group name expression for the given Tuple
43: * @param t the input Tuple to the group name expression
44: * @return the String result of the expression
45: */
46: protected String getGroup(Tuple t) {
47: String group = (String) m_group.get(t);
48: if (group == null) {
49: s_logger.warning("Null group lookup");
50: }
51: return group;
52: }
53:
54: /**
55: * Attempts to add the given expression as the group expression.
56: * @see prefuse.data.expression.Function#addParameter(prefuse.data.expression.Expression)
57: */
58: public void addParameter(Expression e) {
59: if (m_group == null)
60: m_group = e;
61: else
62: throw new IllegalStateException(
63: "This function takes only 1 parameter.");
64: }
65:
66: /**
67: * @see prefuse.data.expression.Function#getParameterCount()
68: */
69: public int getParameterCount() {
70: return 1;
71: }
72:
73: /**
74: * @see java.lang.Object#toString()
75: */
76: public String toString() {
77: return getName() + "(" + m_group + ")";
78: }
79:
80: } // end of class GroupExpression
|