cetus.hir
Class MinMaxExpression

java.lang.Object
  extended by cetus.hir.Expression
      extended by cetus.hir.MinMaxExpression
All Implemented Interfaces:
Printable, Traversable, java.lang.Cloneable, java.lang.Comparable<Expression>

public class MinMaxExpression
extends Expression

Class for MIN() MAX() expressions - these are equivalent to conditional expressions.


Field Summary
 
Fields inherited from class cetus.hir.Expression
children, needs_parens, object_print_method, parent
 
Constructor Summary
MinMaxExpression(boolean ismin)
          Constructor with predefined min/max operator.
MinMaxExpression(boolean ismin, Expression lhs, Expression rhs)
          Constructor with two operands.
 
Method Summary
 void add(Expression e)
          Adds an operand to the existing expression.
 int compareTo(Expression e)
          Compares MinMaxExpression to another expression.
 java.lang.Integer compareTo(int num)
          Compares MinMaxExpression to an integer value.
static void defaultPrint(MinMaxExpression minmax, java.io.OutputStream stream)
          Prints out MIN/MAX expressions.
 boolean isMin()
          Returns true if this is a MIN expression.
 boolean isNegMin()
          Checks if this expression is a MIN expression having at least one operand with negative value.
 boolean isPosMax()
          Checks if this expression is a MIN expression having at least one operand with positive value.
 Expression negate()
          Negates the expression by switching the operator and the signs of the operands.
 void setMin(boolean ismin)
          Sets the expression type.
 Expression simplify()
          Simplifies a MinMaxExpression as much as possible by removing duplicates and by matching special cases.
 Expression toConditionalExpression()
          Converts MinMaxExpression to an equivalent conditional expression.
 java.lang.String toString()
          Every expression class should override toString method.
 
Methods inherited from class cetus.hir.Expression
clone, equals, equals2, findExpression, getChildren, getParent, getStatement, needsParens, print, printSelf, removeChild, setChild, setParens, setParent, setPrintMethod, swapWith, verify
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MinMaxExpression

public MinMaxExpression(boolean ismin)
Constructor with predefined min/max operator.

Parameters:
ismin - true if the operator is MIN, false otherwise

MinMaxExpression

public MinMaxExpression(boolean ismin,
                        Expression lhs,
                        Expression rhs)
Constructor with two operands.

Parameters:
ismin - true if the operator is MIN, false otherwise
lhs - the first operand
rhs - the second operand
Method Detail

defaultPrint

public static void defaultPrint(MinMaxExpression minmax,
                                java.io.OutputStream stream)
Prints out MIN/MAX expressions.


toString

public java.lang.String toString()
Description copied from class: Expression
Every expression class should override toString method.

Overrides:
toString in class Expression

isMin

public boolean isMin()
Returns true if this is a MIN expression.

Returns:
true if this is a MIN expression, false otherwise

setMin

public void setMin(boolean ismin)
Sets the expression type.

Parameters:
ismin - true for MIN, false for MAX

add

public void add(Expression e)
Adds an operand to the existing expression.

Parameters:
e - the new operand to be appended

negate

public Expression negate()
Negates the expression by switching the operator and the signs of the operands.

Returns:
the negated expression

isPosMax

public boolean isPosMax()
Checks if this expression is a MIN expression having at least one operand with positive value.

Returns:
true/false

isNegMin

public boolean isNegMin()
Checks if this expression is a MIN expression having at least one operand with negative value.

Returns:
true/false

simplify

public Expression simplify()
Simplifies a MinMaxExpression as much as possible by removing duplicates and by matching special cases.

Returns:
A simplified expression

compareTo

public int compareTo(Expression e)
Compares MinMaxExpression to another expression.

Specified by:
compareTo in interface java.lang.Comparable<Expression>
Overrides:
compareTo in class Expression

compareTo

public java.lang.Integer compareTo(int num)
Compares MinMaxExpression to an integer value.

Parameters:
num - an integer value
Returns:
Integer object if comparison is possible, null otherwise

toConditionalExpression

public Expression toConditionalExpression()
Converts MinMaxExpression to an equivalent conditional expression.

Returns:
the converted conditional expression