com.rubecula.jquantity
Class Operator

java.lang.Object
  extended bycom.rubecula.util.Symbol
      extended bycom.rubecula.jquantity.Operator
All Implemented Interfaces:
Presentable, Replaceable

public class Operator
extends Symbol
implements Replaceable

This class defines operators in the context of SymbolicPresentations and their Presentable counterparts: Expressions. It is not directly related to the Mill operator objects.

Copyright: Copyright (c) 2003

Company: Rubecula Software

Since:
V_0_3 // TODO Combine these operators with the Mill operators. // TODO Needs javadoc doing properly.
Version:
$Revision: 1.6 $
Author:
Robin Hillyard

Field Summary
private  int _Ady
          The -ady of this operator, i.e. the number of operands on which it operates.
static Operator[] $AllOps
           
static Operator $Braces
           
static Operator $Chs
           
static Operator $Comma
           
static Operator $Divide
           
static Operator $E
           
static Operator $Exponent
           
static Operator $Imag
           
static Operator $Minus
           
static Operator $Pi
           
static Operator $Plus
           
static Operator $Times
           
private static java.lang.String S_Braces
           
private static java.lang.String S_Comma
           
private static java.lang.String S_Divide
           
private static java.lang.String S_Exponent
           
private static java.lang.String S_Imag
           
private static java.lang.String S_Minus
           
private static java.lang.String S_Pi
           
private static java.lang.String S_Plus
           
private static java.lang.String S_Times
           
 
Fields inherited from class com.rubecula.util.Symbol
_S
 
Constructor Summary
Operator()
          This empty constructor is necessary for the makePresentableInstance method to have something to work on.
Operator(java.lang.String s)
           
Operator(java.lang.String s, int ady)
           
 
Method Summary
 int getAdy()
           
 Presentable getValue(java.lang.Object context)
          This method takes this Replaceable and returns its logical equivalent as defined by the context.
 Presentable makePresentableInstance(Presentation presentation)
          Instance method to convert a Presentation into a Presentable.
 boolean match(Operator o)
          Method to match this operator to another.
 boolean match(java.lang.String s, int ady)
          Method to match this operator to a String and ady.
static Operator MatchAny(Operator[] ops, java.lang.String s, int ady)
          Method to match a String and ady to one of the operators in array ops.
 java.lang.String toString()
           
static Operator valueOf()
           
static Operator valueOf(java.lang.String operator)
           
static Operator valueOf(java.lang.String operator, int ady)
           
 
Methods inherited from class com.rubecula.util.Symbol
getType, present
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.rubecula.util.Presentable
getType, present
 

Field Detail

S_Plus

private static final java.lang.String S_Plus
See Also:
Constant Field Values

S_Minus

private static final java.lang.String S_Minus
See Also:
Constant Field Values

S_Times

private static final java.lang.String S_Times
See Also:
Constant Field Values

S_Braces

private static final java.lang.String S_Braces
See Also:
Constant Field Values

S_Comma

private static final java.lang.String S_Comma
See Also:
Constant Field Values

S_Divide

private static final java.lang.String S_Divide
See Also:
Constant Field Values

S_Exponent

private static final java.lang.String S_Exponent
See Also:
Constant Field Values

S_Imag

private static final java.lang.String S_Imag
See Also:
Constant Field Values

S_Pi

private static final java.lang.String S_Pi
See Also:
Constant Field Values

$Braces

public static final Operator $Braces

$Chs

public static final Operator $Chs

$Comma

public static final Operator $Comma

$Divide

public static final Operator $Divide

$E

public static final Operator $E

$Exponent

public static final Operator $Exponent

$Imag

public static final Operator $Imag

$Minus

public static final Operator $Minus

$Pi

public static final Operator $Pi

$Plus

public static final Operator $Plus

$Times

public static final Operator $Times

$AllOps

public static final Operator[] $AllOps

_Ady

private final int _Ady
The -ady of this operator, i.e. the number of operands on which it operates. Either 0, 1 or 2.

Constructor Detail

Operator

public Operator(java.lang.String s,
                int ady)

Operator

public Operator(java.lang.String s)

Operator

public Operator()
This empty constructor is necessary for the makePresentableInstance method to have something to work on.

Method Detail

valueOf

public static Operator valueOf(java.lang.String operator,
                               int ady)
                        throws PresentableException
Throws:
PresentableException

valueOf

public static Operator valueOf(java.lang.String operator)
                        throws PresentableException
Throws:
PresentableException

valueOf

public static Operator valueOf()
                        throws PresentableException
Throws:
PresentableException

getAdy

public int getAdy()

toString

public java.lang.String toString()
Overrides:
toString in class Symbol

match

public boolean match(java.lang.String s,
                     int ady)
Method to match this operator to a String and ady.

Parameters:
s - the string to match on.
ady - Either the "ady" (0, 1 or 2), or -1 to signify "don't care".
Returns:
true if s and ady match this Operator.

match

public boolean match(Operator o)
Method to match this operator to another.

Parameters:
o - the operator to match.
Returns:
true if o matches this Operator.

MatchAny

public static Operator MatchAny(Operator[] ops,
                                java.lang.String s,
                                int ady)
Method to match a String and ady to one of the operators in array ops.

Parameters:
ops - an array of operators
s - the string to match on.
ady - Either the "ady" (0, 1 or 2), or -1 to signify "don't care".
Returns:
the first operator (from ops) that makes a match, else null if no match.

getValue

public Presentable getValue(java.lang.Object context)
                     throws PresentableException
This method takes this Replaceable and returns its logical equivalent as defined by the context.

Specified by:
getValue in interface Replaceable
Parameters:
context - an Object which defines the context for the substitution, for example, an operator or variable for a Mill might be evaluated in the context of a current Mill and the result would be the replacement.
Returns:
the value yielded by evaluating this in context
Throws:
PresentableException

makePresentableInstance

public Presentable makePresentableInstance(Presentation presentation)
                                    throws PresentationException
Instance method to convert a Presentation into a Presentable. Ideally, this would be a class method, but such a method cannot be defined in an interface. Nor can it be defined in an abstract class with the intention of overriding it in a subclass. Polymorphism just doesn't work that way.
Therefore, the present value (as in fields) of the instance is essentially ignored - only the methods are important.

Specified by:
makePresentableInstance in interface Presentable
Overrides:
makePresentableInstance in class Symbol
Parameters:
presentation - of a number to be converted into a Presentable number.
Returns:
a number in the form of a Presentable.
Throws:
PresentationException - in case of parsing error.