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

dk.rode.thesis.interpreter
Class Main

java.lang.Object
  extended by dk.rode.thesis.interpreter.Main
All Implemented Interfaces:
Testable

@Participant(value="Client")
public class Main
extends Object
implements Testable

Interpreter tests.

Author:
Gunni Rode / rode.dk

Constructor Summary
Main()
          No-arg constructor.
 
Method Summary
private
<E extends Comparable<? super E>>
Expression<E>
create1(Sequence<E> sequence, Class<E> type, E value, Context context)
          Creates: next[20], y = current, (reverse[true] ?
private
<E extends Number & Comparable<? super E>>
Expression<E>
create2(Sequence<E> sequence, Class<E> type, E value, Context context)
          Creates: next[value], foo = Integer{next[(boo ?
private
<E extends Comparable<? super E>>
Expression<E>
create3(Sequence<E> sequence, Class<E> type, E value, Context context)
          Creates a loop-structure by using cyclic expression references without intermediate variables: (current < value ?
private
<E extends Number & Comparable<? super E>>
Expression<E>
create4(Sequence<E> sequence, Class<E> type, E value1, E value2, Context context)
          Generates the mother of all sequence expressions: (current < value1 ?
private  Expression<Comparable<?>> create5(Context context, Sequence<String> string, Sequence<Integer> integer, String stringValue, Integer integerValue)
          Creates an expression with a loop having 15 iterations as well as different sequences and types: ((!
private  void log(boolean log)
          True to enable logging per expression type.
static void main(String[] args)
          Executes the Interpreter tests.
 boolean test(Log out, Arguments arguments)
          Accepted argument: -value=n, where n is an integer value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Main

public Main()
No-arg constructor.

Method Detail

create1

private <E extends Comparable<? super E>> Expression<E> create1(Sequence<E> sequence,
                                                                Class<E> type,
                                                                E value,
                                                                Context context)
                                                     throws ExpressionException
Creates:
   next[20], y = current, (reverse[true] ? next[10], x = current, (x < value ? x : break[y]) : current)
 
Where value is the value supplied as the value argument.

Type Parameters:
E - The type of comparable value the evaluation of the returned expression produces.
Parameters:
sequence - The sequence to manipulate; never null.
type - The expression and value type; never null.
value - The value used in the expression; never null.
context - The context to use; never null.
Returns:
The created expression; never null.
Throws:
ExpressionException - If the creation fails.

create2

private <E extends Number & Comparable<? super E>> Expression<E> create2(Sequence<E> sequence,
                                                                        Class<E> type,
                                                                        E value,
                                                                        Context context)
                                                             throws ExpressionException
Creates:
   next[value], foo = Integer{next[(boo ? current : value)]}, (reverse[foo < value] ? next[set[value], next[bar = foo], (foo > value ? bar : break[foo])] : foo)      
 
Where value is the value supplied as the value argument.

Type Parameters:
E - The type of comparable numeric value the evaluation of the returned expression produces.
Parameters:
sequence - The sequence to manipulate; never null.
type - The expression and value type; never null.
value - The value used in the expression; never null.
context - The context to use; never null.
Returns:
The created expression; never null.
Throws:
ExpressionException - If the creation fails.

create3

private <E extends Comparable<? super E>> Expression<E> create3(Sequence<E> sequence,
                                                                Class<E> type,
                                                                E value,
                                                                Context context)
                                                     throws ExpressionException
Creates a loop-structure by using cyclic expression references without intermediate variables:
    (current < value ? next[1], {{flow -> conditional}} : current)
 
Where value is supplied as the argument value.

Type Parameters:
E - The type of comparable value the evaluation of the returned expression produces.
Parameters:
sequence - The sequence to manipulate; never null.
type - The expression and value type; never null.
value - The value used in the expression; never null.
context - The context to use; never null.
Returns:
The created expression; never null.
Throws:
ExpressionException - If the creation fails.

create4

private <E extends Number & Comparable<? super E>> Expression<E> create4(Sequence<E> sequence,
                                                                        Class<E> type,
                                                                        E value1,
                                                                        E value2,
                                                                        Context context)
                                                             throws ExpressionException
Generates the mother of all sequence expressions:
    (current < value1 ? next[20], y = current, (reverse[true] ? next[10], x = current, (x < value2 ? x : break[y]) : current), x = current, (current < value1 ? next[1], {{flow -> flow}} : current), y = current, (reverse[(next[y] > x | (y == x ? break[boo] : false))] ? break[x] : (((!current == next[value1], foo = Integer{next[(boo ? current : value1)]}, (reverse[foo < value1] ? next[set[value1], next[bar = foo], (foo > value1 ? bar : break[foo])] : foo)) && x = bar == (current < value2 ? next[1], {{flow -> flow}} : current)) ? x : foo)) : exit)
 
Where value1 and value2 are the values supplied as arguments to this method.

Type Parameters:
E - The type of comparable value the evaluation of the returned expression produces.
Parameters:
sequence - The sequence to manipulate; never null.
type - The expression and value type; never null.
value1 - The first value used in the expression; never null.
value2 - The second value used in the expression; never null.
context - The context to use; never null.
Returns:
The created expression; never null.
Throws:
ExpressionException - If the creation fails.

create5

private Expression<Comparable<?>> create5(Context context,
                                          Sequence<String> string,
                                          Sequence<Integer> integer,
                                          String stringValue,
                                          Integer integerValue)
                                   throws ExpressionException
Creates an expression with a loop having 15 iterations as well as different sequences and types:
    ((!next[1] == 15) ? Comparable{c} = (Boolean{boo} = (Integer{i} > Integer{current} || (String{s} == String{next[Integer{next[1]}]} ? break[Boolean{boo}] : booboo = (!booboo))) ? Integer{next[1]} : String{current}), {{flow -> conditional}} : Comparable{c})
 
Where stringValue is the initial value of s, and intergerValue of i.

The identity hash codes of the created sequences are listed as well for each terminal expression.

Parameters:
context - The context to use; never null.
string - A sequence delivering strings; never null.
integer - A sequence delivering integers; never null.
stringValue - A string value used in the expression; never null.
integerValue - An integer value used in the expression; never null.
Returns:
The created expression; never null.
Throws:
ExpressionException - If the creation fails.

log

private void log(boolean log)
True to enable logging per expression type.

Parameters:
log - True to enable verbose logging per expression type, false to disable.

main

public static void main(String[] args)
Executes the Interpreter tests.

Parameters:
args - The arguments to supply to test(Log, Arguments), if any; can be null.

test

public boolean test(Log out,
                    Arguments arguments)
Accepted argument: -value=n, where n is an integer value.

Specified by:
test in interface Testable
Parameters:
out - The log to report the test outcome to; cannot be null.
arguments - Additional arguments, if any.
Returns:
True if the tests succeeded, false if not.

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.