Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.interpreter
Class BinaryExpression<T,E>

java.lang.Object
  extended by dk.rode.thesis.interpreter.AbstractExpression<E>
      extended by dk.rode.thesis.interpreter.BinaryExpression<T,E>
Type Parameters:
T - The type of value the evaluation of the expression operands produces. Normally, but not required to be, identical with E.
E - The type of value the evaluation of this expression produces.
All Implemented Interfaces:
Expression<E>, NonTerminalExpression<E>, Copyable<Expression<E>>, StrictCopyable<Expression<E>>
Direct Known Subclasses:
AndExpression, CompareExpression, ConditionalExpression, EqualExpression, OrExpression

public abstract class BinaryExpression<T,E>
extends AbstractExpression<E>
implements NonTerminalExpression<E>

A binary expression represents any expression that involves (at least) two sub-expressions as operands.

The evaluation of a binary expression is not guaranteed to be commutative.

Author:
Gunni Rode / rode.dk

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.interpreter.Expression
Expression.SymbolIdiom
 
Field Summary
protected  Expression<? extends T> first
          The first operand.
protected  Expression<? extends T> second
          The second operand.
 
Constructor Summary
protected BinaryExpression(BinaryExpression<? extends T,E> expression)
          Copy constructor.
protected BinaryExpression(Expression<? extends T> first, Expression<? extends T> second)
          Constructor.
 
Method Summary
protected  String asSymbol(Context context, String separator)
          Returns x separator y, where x is the symbolic representation of the first expression operand and y of the the second.
protected  StringBuilder asSymbol(Context context, String separator, StringBuilder sb)
          Returns x separator y, where x is the symbolic representation of the first expression operand and y of the the second.
 List<Expression<?>> operands()
          Returns the expression operands used by this expression, in order.
 String toString()
          Returns the string representation of this expression.
 
Methods inherited from class dk.rode.thesis.interpreter.AbstractExpression
contains, equals, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface dk.rode.thesis.interpreter.Expression
asSymbol, contains, copy, evaluate, name
 

Field Detail

first

protected final Expression<? extends T> first
The first operand.

Never null.


second

protected final Expression<? extends T> second
The second operand.

Never null.

Constructor Detail

BinaryExpression

protected BinaryExpression(BinaryExpression<? extends T,E> expression)
Copy constructor.

Parameters:
expression - The expression to copy; cannot be null.
Throws:
NullPointerException - If expression is null.

BinaryExpression

protected BinaryExpression(Expression<? extends T> first,
                           Expression<? extends T> second)
Constructor.

Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Throws:
NullPointerException - If either expression is null.
Method Detail

asSymbol

protected String asSymbol(Context context,
                          String separator)
                   throws ExpressionException
Returns x separator y, where x is the symbolic representation of the first expression operand and y of the the second.

Parameters:
context - The context to use; cannot be null.
separator - The operand separator; cannot be null.
Returns:
A formatted symbol string; never null.
Throws:
NullPointerException - If either argument is null.
ExpressionException - If the symbol cannot be generated.

asSymbol

protected StringBuilder asSymbol(Context context,
                                 String separator,
                                 StringBuilder sb)
                          throws ExpressionException
Returns x separator y, where x is the symbolic representation of the first expression operand and y of the the second.

Parameters:
context - The context to use; cannot be null.
separator - The operand separator; cannot be null.
sb - The string builder to use and return; cannot be null.
Returns:
sb; never null.
Throws:
NullPointerException - If either argument is null.
ExpressionException - If the symbol cannot be generated.

operands

public List<Expression<?>> operands()
Description copied from interface: Expression
Returns the expression operands used by this expression, in order.

Modifying the returned list will not affect this expression.

Specified by:
operands in interface Expression<E>
Returns:
The operands; never null, but can be empty.

toString

public String toString()
Description copied from class: AbstractExpression
Returns the string representation of this expression.

Specified by:
toString in interface Expression<E>
Overrides:
toString in class AbstractExpression<E>
Returns:
The string representation; never null.

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.