001: package prefuse.data.expression;
002:
003: import prefuse.data.Schema;
004: import prefuse.data.Tuple;
005: import prefuse.data.event.ExpressionListener;
006:
007: /**
008: * <p>An Expression is an arbitrary function that takes a single Tuple as an
009: * argument. Expressions support both Object-valued and primitive-valued
010: * (int, long, float, double, boolean) evaluation methods. The appropriate
011: * method to call depends on the particular Expression implementation.
012: * A {@link #getType(Schema)} method provides mechanism for determining the
013: * return type of a given Expression instance. A {@link Predicate} is an
014: * Expression which is guaranteed to support the {@link #getBoolean(Tuple)}
015: * method, is often used to filter tuples.</p>
016: *
017: * <p>Expressions also support a listener interface, allowing clients to
018: * monitor changes to expressions, namely rearrangements or modification
019: * of contained sub-expressions. The Expression interface also supports
020: * visitors, which can be used to visit every sub-expression in an expression
021: * tree.</p>
022: *
023: * <p>Using the various Expression implementations in the
024: * {@link prefuse.data.expression.Expression} package, clients can
025: * programatically construct a tree of expressions for use as complex
026: * query predicates or as functions for computing a derived data column
027: * (see {@link prefuse.data.Table#addColumn(String, Expression)}. Often it is
028: * more convenient to write expressions in the prefuse expression language,
029: * a SQL-like data manipulation language, and compile the Expression tree
030: * using the {@link prefuse.data.expression.parser.ExpressionParser}. The
031: * documentation for the ExpressionParser class includes a full reference
032: * for the textual expression language.</p>
033: *
034: * @author <a href="http://jheer.org">jeffrey heer</a>
035: */
036: public interface Expression {
037:
038: /**
039: * Returns the type that this expression evaluates to when tuples
040: * with the given Schema are provided as input.
041: */
042: public Class getType(Schema s);
043:
044: /**
045: * Passes the visitor through this expression and any sub expressions
046: * @param v the ExpressionVisitor
047: */
048: public void visit(ExpressionVisitor v);
049:
050: /**
051: * Evaluate the Expression on the given input Tuple.
052: * @param t the input Tuple
053: * @return the Expression return value, as an Object
054: */
055: public Object get(Tuple t);
056:
057: /**
058: * Evaluate the Expression on the given input Tuple.
059: * @param t the input Tuple
060: * @return the Expression return value, as an int
061: */
062: public int getInt(Tuple t);
063:
064: /**
065: * Evaluate the Expression on the given input Tuple.
066: * @param t the input Tuple
067: * @return the Expression return value, as a long
068: */
069: public long getLong(Tuple t);
070:
071: /**
072: * Evaluate the Expression on the given input Tuple.
073: * @param t the input Tuple
074: * @return the Expression return value, as a float
075: */
076: public float getFloat(Tuple t);
077:
078: /**
079: * Evaluate the Expression on the given input Tuple.
080: * @param t the input Tuple
081: * @return the Expression return value, as a double
082: */
083: public double getDouble(Tuple t);
084:
085: /**
086: * Evaluate the Expression on the given input Tuple.
087: * @param t the input Tuple
088: * @return the Expression return value, as a boolean
089: */
090: public boolean getBoolean(Tuple t);
091:
092: /**
093: * Add a listener to this Expression.
094: * @param lstnr the expression listener to add
095: */
096: public void addExpressionListener(ExpressionListener lstnr);
097:
098: /**
099: * Remove a listener to this Expression.
100: * @param lstnr the expression listener to remove
101: */
102: public void removeExpressionListener(ExpressionListener lstnr);
103:
104: } // end of interface Expression
|