Orbital library

orbital.logic.sign.concrete
Class Notation

java.lang.Object
  extended by orbital.logic.sign.concrete.Notation
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public abstract class Notation
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

Represents notational variants of compositor applications. Defines the concrete syntax and thus the linearization of symbols.

Author:
André Platzer
See Also:
typesafe enum pattern, Serialized Form
Invariants:
a.equals(b) ⇔ a==b

Nested Class Summary
static class Notation.NotationSpecification
          Contains the specification of the default notation for a compositor.
 
Field Summary
static Notation AUTO
          Specifies automatic compositor-dependant notation as registered.
static Notation BESTFIX
          Specifies best mixed notation "a*(b+f(c)) + d" inserting brackets whenever necessary.
static Notation DEFAULT
          Specifies to use system default notation.
static Notation FULLFIX
          Specifies full-bracket mixed notation "(a*(b+f(c))) + d".
static Notation INFIX
          Specifies infix notation "a f b".
static Notation POSTFIX
          Specifies postfix notation "(a,b) f".
static Notation PREFIX
          Specifies prefix notation "f(a,b)".
 
Constructor Summary
protected Notation(java.lang.String name)
           
 
Method Summary
 int compareTo(java.lang.Object o)
          Order imposed by ordinals according to the order of creation.
 boolean equals(java.lang.Object that)
          Maintains the guarantee that all equal objects of the enumerated type are also identical.
abstract  java.lang.String format(java.lang.Object compositor, java.lang.Object arg)
          Format compositor with arguments in this notation.
static Notation getDefault()
          Get the notation used for the synonym DEFAULT.
static Notation.NotationSpecification getNotation(java.lang.Object compositor)
          Get the default notation specification registered for a compositor.
 int hashCode()
           
static Notation.NotationSpecification removeNotation(java.lang.Object f)
          Remove any default notation specifications for a compositor.
static void setAllNotations(java.lang.Object[][] compositorsAndNotations)
          Sets/registers all notations contained in an array.
static void setDefault(Notation notation)
          Set which notation to use for DEFAULT.
static boolean setNotation(java.lang.Object f, Notation.NotationSpecification spec)
          Sets/registers the default notation specification for a compositor.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT

public static final Notation DEFAULT
Specifies to use system default notation.

Compositors with DEFAULT notation will use the current system default notation.

See Also:
setDefault(Notation)

AUTO

public static final Notation AUTO
Specifies automatic compositor-dependant notation as registered.

Delegates to the registered notation. Compositors with registered default notation like +, -, *, /, ^ have a notation set. All unknown symbols are treated as prefix.

See Also:
PREFIX, INFIX, POSTFIX

PREFIX

public static final Notation PREFIX
Specifies prefix notation "f(a,b)".


INFIX

public static final Notation INFIX
Specifies infix notation "a f b".

n-ary this becomes "a f b f c".

Be aware that formatting a complex compound expression with simple infix only, might not result in a term with usual precedence, so brackets would be required.

See Also:
BESTFIX

BESTFIX

public static final Notation BESTFIX
Specifies best mixed notation "a*(b+f(c)) + d" inserting brackets whenever necessary.

Decomposes compositors into its components whenever possible building a function tree to optimize formatting. This more sophisticated notation is aware of the registered default notation and will only insert brackets when necessary.

See Also:
AUTO

FULLFIX

public static final Notation FULLFIX
Specifies full-bracket mixed notation "(a*(b+f(c))) + d".

Delegates to the registered notation. Compositors with registered default notation like +, -, *, /, ^ have a notation set. All unknown symbols are treated as prefix.

See Also:
AUTO, BESTFIX

POSTFIX

public static final Notation POSTFIX
Specifies postfix notation "(a,b) f".

Constructor Detail

Notation

protected Notation(java.lang.String name)
Method Detail

format

public abstract java.lang.String format(java.lang.Object compositor,
                                        java.lang.Object arg)
Format compositor with arguments in this notation.

Parameters:
compositor - the compositor to apply, or the object describing the compositor to apply.
arg - the argument or array of arguments to apply the compositor on, or the array of objects describing the corresponding arguments.
Returns:
a good format of the compositor applied on the specified arguments.

toString

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

compareTo

public int compareTo(java.lang.Object o)
Order imposed by ordinals according to the order of creation.

Specified by:
compareTo in interface java.lang.Comparable
Postconditions:
consistent with equals

equals

public final boolean equals(java.lang.Object that)
Maintains the guarantee that all equal objects of the enumerated type are also identical.

Overrides:
equals in class java.lang.Object
Postconditions:
a.equals(b) ⇔ if a==b.

hashCode

public final int hashCode()
Overrides:
hashCode in class java.lang.Object

getDefault

public static final Notation getDefault()
Get the notation used for the synonym DEFAULT.


setDefault

public static final void setDefault(Notation notation)
Set which notation to use for DEFAULT.

Call to specify system default notation behaviour.

Parameters:
notation - which notation to use for the case of DEFAULT notation.
Throws:
java.lang.IllegalArgumentException - if notation==DEFAULT since this would result in an infinte recursion at runtime.
Preconditions:
notation != DEFAULT
Postconditions:
getDefault() == notation

getNotation

public static Notation.NotationSpecification getNotation(java.lang.Object compositor)
Get the default notation specification registered for a compositor.

Returns:
the default notation specification of the compositor, or null if not set.
See Also:
setNotation(Object, NotationSpecification)

setNotation

public static boolean setNotation(java.lang.Object f,
                                  Notation.NotationSpecification spec)
Sets/registers the default notation specification for a compositor.

Parameters:
f - the compositor whose notation specification to set.
spec - the notation specification to set as default for the compositor f.
Returns:
true if the default notation specification for the compositor f changed as a result of the call.

removeNotation

public static Notation.NotationSpecification removeNotation(java.lang.Object f)
Remove any default notation specifications for a compositor.

Parameters:
f - the compositor whose notation specification to remove.
Returns:
previous value associated with specified compositor, or null if there was no mapping for compositor.

setAllNotations

public static final void setAllNotations(java.lang.Object[][] compositorsAndNotations)
Sets/registers all notations contained in an array.

Parameters:
compositorsAndNotations - Contains compositors and their notation specifications. Stored as an array of length-2 arrays with compositors[i][0] being the Object, and compositor[i][1] being a Notation.NotationSpecification.
See Also:
Convenience Method, setNotation(Object,Notation.NotationSpecification)

Orbital library
1.3.0: 11 Apr 2009

Copyright © 1996-2009 André Platzer
All Rights Reserved.