Class TypeHolder<T extends Unifiable>

java.lang.Object
org.jfuncmachine.util.unification.TypeHolder<T>
Type Parameters:
T - The type of types that the holder can hold

public class TypeHolder<T extends Unifiable> extends Object
A type holder for unification A TypeHolder holds a type for unification. It can hold a concrete type, which means that it is not expected to change any more, or it can be empty, and when it is unified with a TypeHolder that contains a concrete type, it is given to hold that type, and any other empty TypeHolders it was previously unified with also are given that concrete type.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The type held by this holder, null if there isn't one yet
    The TypeHolders that this holder has been linked with
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new TypeHolder
    TypeHolder(T concreteType)
    Create a new TypeHolder already filled with a type
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Tests whether this TypeHolder already has a type
    void
    link(TypeHolder<T> other)
    Link this TypeHolder to another TypeHolder, and link them both together with all the other TypeHolders they were each linked with
    void
    setType(T concreteType)
    Set the type for this TypeHolder.
    void
    unify(TypeHolder<T> other)
    Try to unify this TypeHolder with another.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • concreteType

      public T extends Unifiable concreteType
      The type held by this holder, null if there isn't one yet
    • linked

      public Set<TypeHolder<T extends Unifiable>> linked
      The TypeHolders that this holder has been linked with
  • Constructor Details

    • TypeHolder

      public TypeHolder()
      Create a new TypeHolder
    • TypeHolder

      public TypeHolder(T concreteType)
      Create a new TypeHolder already filled with a type
      Parameters:
      concreteType - The type to fill the holder with
  • Method Details

    • isFull

      public boolean isFull()
      Tests whether this TypeHolder already has a type
      Returns:
      True if this holder has a type
    • setType

      public void setType(T concreteType)
      Set the type for this TypeHolder. This will cause any empty holders linked to this type to be populated as well.
      Parameters:
      concreteType - The type the holder should contain
    • link

      public void link(TypeHolder<T> other)
      Link this TypeHolder to another TypeHolder, and link them both together with all the other TypeHolders they were each linked with
      Parameters:
      other - The other TypeHolder to link with
    • unify

      public void unify(TypeHolder<T> other) throws UnificationException
      Try to unify this TypeHolder with another.
      • If this TypeHolder is empty and the other is full, this TypeHolder and the other TypeHolders it is linked to are populated with the value in other.
      • If this TypeHolder is full and the other is empty, the other TypeHolder and the TypeHolders it is linked to are all populated with the type in this TypeHolder.
      • If both TypeHolders are empty, they are linked together, along with any TypeHolders they are already linked to.
      • If both TypeHolders are full, their types are unified to ensure that they match
      Parameters:
      other - The TypeHolder to unify with
      Throws:
      UnificationException - If there is an error unifying the types