|
Signature.java
|
// FILE. . . . . d:/hak/hlt/src/hlt/fot/Signature.java // EDIT BY . . . Hassan Ait-Kaci // ON MACHINE. . Hak-Laptop // STARTED ON. . Sat Jul 14 07:23:54 2018 package hlt.fot; import hlt.language.util.ArrayList; import java.util.HashMap; import java.util.Iterator;
This is a class containing all the information concerning a
term-constructor signature as a set of Functor objects.
|
public class Signature { protected int size = 0; public int size () { return size; } public boolean isEmpty () { return size == 0; }
| Constructs a new empty signature. |
public Signature () { }
| Contains the functors. |
protected ArrayList functors;
| Returns the functors as an ArrayList of Functor objects. |
public ArrayList functors () { if (functors == null) return functors = new ArrayList(); return functors; }
| Returns the functor at position functorPosition, where 1 ≤ functorPosition ≤ signature.size(). If this signature is empty, returns null. |
public Functor functor (int functorPosition) { return (Functor)functors().get(functorPosition-1); }
| Contains an access-by-name table; |
protected HashMap functorNameTable; protected HashMap functorNameTable () { if (functorNameTable == null) return functorNameTable = new HashMap(); return functorNameTable; }
| Resets this signature to empty. |
public void clear () { functors.clear(); functorNameTable.clear(); }
| Returns the functor called name in this signature if it is not empty; undefined otherwise (returns null). |
public Functor functor (String name) { return (Functor)functorNameTable().get(name); }
| Returns the functor name/arity if it is already defined in this signature, adding it to this signature if not already there. If this functor's name was already defined but with a different arity, throws a BadFunctorArityException. If all ok, returns the functor. |
public Functor functor (String name, int arity) { Functor functor = (Functor)functorNameTable().get(name); if (functor == null) { // this is a new functor: need to create it and add it to this signature functor = new Functor(size++,name,arity,this); functors().add(functor); functorNameTable().put(name,functor); } else if (arity != functor.arity()) throw new BadFunctorArityException(functor,arity); return functor; } /* ************************************************************************ */ public Iterator iterator () { return functors().iterator(); } /* ************************************************************************ */
| Return a string form for this signature. |
public String toString () { return setForm(); } protected String setForm () { StringBuilder form = new StringBuilder("{"); for (int i=0; i<size; i++) { Functor functor = (Functor)functors().get(i); form.append(functor+"/"+functor.arity()+(i<size-1?", ":"")); } form.append("}"); return form.toString(); } }
This file was generated on Sat Aug 25 07:59:54 CEST 2018 from file Signature.java
by the hlt.language.tools.Hilite Java tool written by Hassan Aït-Kaci