Orbital library

orbital.logic.sign
Class SignatureBase

java.lang.Object
  extended by orbital.util.DelegateCollection
      extended by orbital.util.DelegateSet
          extended by orbital.util.DelegateSortedSet
              extended by orbital.logic.sign.SignatureBase
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable, java.util.Collection, java.util.Set, java.util.SortedSet, Signature

public class SignatureBase
extends DelegateSortedSet
implements Signature

A basic signature implementation.

Author:
André Platzer
See Also:
ExpressionSyntax.scanSignature(java.lang.String), Serialized Form
Invariants:
sub classes support nullary constructor (for virtual new instance)
Structure:
implements java.util.SortedSet, delegates super:java.util.SortedSet, inherits orbital.util.DelegateSortedSet

Field Summary
static SignatureBase EMPTY
          Empty signature ∅.
 
Constructor Summary
SignatureBase()
          Construct an empty signature ∅.
SignatureBase(java.util.Collection symbols)
          Construct a new signature with the given set of symbols.
SignatureBase(java.util.SortedSet symbols)
           
 
Method Summary
 boolean add(java.lang.Object o)
          Ensures that this collection contains the specified element (optional operation).
 boolean contains(java.lang.String signifier, java.lang.Object[] arg)
          Deprecated. Since Orbital1.1 use get(String,Object[])≠null instead.
 Signature difference(Signature sigma2)
          Returns the difference to another signature.
 boolean equals(java.lang.Object o)
          Compares the specified object with this collection for equality.
 Symbol get(java.lang.String signifier, java.lang.Object[] arg)
          Returns the symbol with the specified signifier of a functor.
 Symbol get(java.lang.String signifier, Type maxType)
          Returns the symbol with the specified signifier.
 java.util.SortedSet getSymbols()
          Get the set of symbols in this signature.
 int hashCode()
          Returns the hash code value for this collection.
 Signature intersection(Signature sigma2)
          Returns the intersection of two signatures.
 void setSymbols(java.util.SortedSet symbols)
          Set the set of symbols in this signature.
 Signature symmetricDifference(Signature sigma2)
          Returns the difference to another signature.
 java.lang.String toString()
          Returns a string representation of the object.
 Signature union(Signature sigma2)
          Returns the union of two signatures.
static Signature unmodifiableSignature(Signature s)
          Returns an unmodifiable view of the specified signature.
 
Methods inherited from class orbital.util.DelegateSortedSet
comparator, first, headSet, last, setDelegatee, setDelegatee, subSet, tailSet
 
Methods inherited from class orbital.util.DelegateSet
setDelegatee
 
Methods inherited from class orbital.util.DelegateCollection
addAll, clear, contains, containsAll, getDelegatee, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.SortedSet
comparator, first, headSet, last, subSet, tailSet
 
Methods inherited from interface java.util.Set
addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Field Detail

EMPTY

public static final SignatureBase EMPTY
Empty signature ∅.

Attributes:
immutable
Constructor Detail

SignatureBase

public SignatureBase(java.util.Collection symbols)
Construct a new signature with the given set of symbols.

The argument is a collection as per general contract of the interface java.util.Set, but will be transformed into this signature set with the call to this constructor.

Parameters:
symbols - the set of symbols in the signature.
Preconditions:
∀s∈symbols: s instanceof orbital.logic.imp.Symbol

SignatureBase

public SignatureBase(java.util.SortedSet symbols)

SignatureBase

public SignatureBase()
Construct an empty signature ∅.

Method Detail

equals

public boolean equals(java.lang.Object o)
Description copied from class: DelegateCollection
Compares the specified object with this collection for equality.

While the Collection interface adds no stipulations to the general contract for the Object.equals, programmers who implement the Collection interface "directly" (in other words, create a class that is a Collection but is not a Set or a List) must exercise care if they choose to override the Object.equals. It is not necessary to do so, and the simplest course of action is to rely on Object's implementation, but the implementer may wish to implement a "value comparison" in place of the default "reference comparison." (The List and Set interfaces mandate such value comparisons.)

The general contract for the Object.equals method states that equals must be symmetric (in other words, a.equals(b) if and only if b.equals(a)). The contracts for List.equals and Set.equals state that lists are only equal to other lists, and sets to other sets. Thus, a custom equals method for a collection class that implements neither the List nor Set interface must return false when this collection is compared to any list or set. (By the same logic, it is not possible to write a class that correctly implements both the Set and List interfaces.)

Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.Set
Specified by:
equals in interface Signature
Overrides:
equals in class DelegateCollection
Parameters:
o - Object to be compared for equality with this collection.
Returns:
true if the specified object is equal to this collection
See Also:
Object.equals(Object), Set.equals(Object), List.equals(Object)

hashCode

public int hashCode()
Description copied from class: DelegateCollection
Returns the hash code value for this collection. While the Collection interface adds no stipulations to the general contract for the Object.hashCode method, programmers should take note that any class that overrides the Object.equals method must also override the Object.hashCode method in order to satisfy the general contract for the Object.hashCodemethod. In particular, c1.equals(c2) implies that c1.hashCode()==c2.hashCode().

Specified by:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.Set
Specified by:
hashCode in interface Signature
Overrides:
hashCode in class DelegateCollection
Returns:
the hash code value for this collection
See Also:
Object.hashCode(), Object.equals(Object)

getSymbols

public java.util.SortedSet getSymbols()
Get the set of symbols in this signature.


setSymbols

public void setSymbols(java.util.SortedSet symbols)
Set the set of symbols in this signature.

Parameters:
symbols - the new set of symbols in this signature.
Preconditions:
∀s∈symbols: s instanceof orbital.logic.imp.Symbol

contains

public boolean contains(java.lang.String signifier,
                        java.lang.Object[] arg)
Deprecated. Since Orbital1.1 use get(String,Object[])≠null instead.


get

public Symbol get(java.lang.String signifier,
                  java.lang.Object[] arg)
Description copied from interface: Signature
Returns the symbol with the specified signifier of a functor. Will only return symbols that are applicable to the specified arguments.

The most usual use of the arguments array is to check for its length to distinguish unary minus '-' from binary subtraction '-'. But in principle, type checking could be required as well.

Note: if there are multiple symbols that match the given signifier and arguments, which symbol will be selected is unspecified.

This method equals get(signifier, typeOf(args)→⊤).

Specified by:
get in interface Signature
Parameters:
signifier - the signifier of the symbol.
arg - the arguments that the functor belonging to the signifier is called with. null, or an array of length 0 can be used for zero arguments.
Returns:
the symbol that has the specified signifier and is applicable to arg, if exists. Returns null otherwise.
See Also:
Signature.get(String,Type)

get

public Symbol get(java.lang.String signifier,
                  Type maxType)
Description copied from interface: Signature
Returns the symbol with the specified signifier. Will only return symbols that are compatible with the specified type, i.e. are subtypes of it.

Note: if there are multiple symbols that match the given signifier and type, which symbol will be selected is unspecified.

Specified by:
get in interface Signature
Parameters:
signifier - the signifier of the symbol.
maxType - the maximum type that the symbol can have.
Returns:
the symbol that has the specified signifier and type ≤ maxType, if exists. Returns null otherwise.
See Also:
Signature.get(String,Object[])

union

public Signature union(Signature sigma2)
Description copied from interface: Signature
Returns the union of two signatures.

Specified by:
union in interface Signature
Returns:
sigma ∪ sigma2.
See Also:
Setops.union(java.util.Collection,java.util.Collection)

intersection

public Signature intersection(Signature sigma2)
Description copied from interface: Signature
Returns the intersection of two signatures.

Specified by:
intersection in interface Signature
Returns:
sigma ∩ sigma2.
See Also:
Setops.intersection(java.util.Collection,java.util.Collection)

difference

public Signature difference(Signature sigma2)
Description copied from interface: Signature
Returns the difference to another signature.

Specified by:
difference in interface Signature
Returns:
sigma ∖ sigma2.
See Also:
Setops.difference(java.util.Collection,java.util.Collection)

symmetricDifference

public Signature symmetricDifference(Signature sigma2)
Description copied from interface: Signature
Returns the difference to another signature.

Specified by:
symmetricDifference in interface Signature
Returns:
sigma Δ sigma2.
See Also:
Setops.symmetricDifference(java.util.Collection,java.util.Collection)

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object

add

public boolean add(java.lang.Object o)
Description copied from class: DelegateCollection
Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set
Overrides:
add in class DelegateCollection
Parameters:
o - element whose presence in this collection is to be ensured.
Returns:
true if this collection changed as a result of the call

unmodifiableSignature

public static final Signature unmodifiableSignature(Signature s)
Returns an unmodifiable view of the specified signature. The result is a read only view.


Orbital library
1.3.0: 11 Apr 2009

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