Class SubstitutionImpl

java.lang.Object
fr.inria.rules.integraal.model.logicalElements.impl.SubstitutionImpl
All Implemented Interfaces:
fr.inria.rules.dlgpemodel.api.elems.ISubstitution<Variable,Term>, fr.inria.rules.dlgpemodel.api.sentences.IPrintable, Substitution, Serializable

public class SubstitutionImpl extends Object implements Substitution, Serializable
Default implementation of Substitution using a map
Author:
Florent Tornil, Guillaume Perution-Kihli
See Also:
  • Constructor Details

    • SubstitutionImpl

      public SubstitutionImpl()
      Default constructor using a HashMap
    • SubstitutionImpl

      public SubstitutionImpl(Map<Variable,Term> associations)
      Constructor using a user-given map
      Parameters:
      associations - a map representing a substitution
    • SubstitutionImpl

      public SubstitutionImpl(Substitution s)
      Copy contructor
      Parameters:
      s - another substitution
  • Method Details

    • getImageOfVariable

      public Term getImageOfVariable(Variable variable)
      //////////////////////////////////////////////
      Specified by:
      getImageOfVariable in interface fr.inria.rules.dlgpemodel.api.elems.ISubstitution<Variable,Term>
      Specified by:
      getImageOfVariable in interface Substitution
      Parameters:
      variable - the variable to substitute
      Returns:
      the image of the variable
    • keys

      public Collection<Variable> keys()
      Description copied from interface: Substitution
      Get the domain of this substitution.
      Specified by:
      keys in interface fr.inria.rules.dlgpemodel.api.elems.ISubstitution<Variable,Term>
      Specified by:
      keys in interface Substitution
      Returns:
      the domain of this substitution.
    • add

      public void add(Variable v, Term t)
      Description copied from interface: Substitution
      Adds a mapping from the specified variable into the specified image to this substitution.
      Specified by:
      add in interface Substitution
      Parameters:
      v - the key
      t - the image
    • remove

      public void remove(Variable v)
      Description copied from interface: Substitution
      Remove the given variable affectation from this substitution
      Specified by:
      remove in interface Substitution
      Parameters:
      v - a variable
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Substitution
      Indicates whether this substitution contains no mappings.
      Specified by:
      isEmpty in interface Substitution
      Returns:
      true iff this substitution is empty
    • merged

      public Optional<Substitution> merged(Substitution other)
      Description copied from interface: Substitution
      Two substitutions can be merged iff for each key in common, the image is the same
      Specified by:
      merged in interface Substitution
      Parameters:
      other - a substitution
      Returns:
      a new substitution being the merge of this one and the other one or an empty optional if the substitutions are not compatible
    • mergeInPlace

      public boolean mergeInPlace(Substitution other)
      Description copied from interface: Substitution
      Attempts to merge other into this substitution in-place.

      A merge succeeds iff, for every variable appearing in both substitutions, the two images are equal. – On success : the new (compatible) bindings from other are copied inside this and the method returns true. – On failure : this is left exactly in its original state and the method returns false.

      Side effects : the operation mutates this only when it succeeds.

      Specified by:
      mergeInPlace in interface Substitution
      Parameters:
      other - a substitution to merge
      Returns:
      true on success, false if a conflict is detected
    • aggregated

      public Optional<Substitution> aggregated(Substitution s)
      Description copied from interface: Substitution
      The aggregation of a substitution is more complex that just add a new mapping for a new variable. Especially, it does not conserve the domain and codomain. It chooses a representative term for each connected component by successive application of the mapping. For example, if the current substitution is {X -> Y, Z -> U} and you add a mapping {Y -> 'a', Z -> V}, the result is {Y -> 'a', X -> 'a', Z -> V, U -> V} or {Y -> 'a', X -> 'a', U -> Z, V -> Z} or {Y -> 'a', X -> 'a', Z -> U, V -> U}.
      Specified by:
      aggregated in interface Substitution
      Parameters:
      s - the substitution to aggregate with
      Returns:
      the aggregated substitution or an empty optional if it is not possible
    • limitedTo

      public Substitution limitedTo(Collection<Variable> vars)
      Description copied from interface: Substitution
      Returns a copy of this substitution restricted to the supplied variables.
      Specified by:
      limitedTo in interface Substitution
      Parameters:
      vars - variables to limit to
      Returns:
      a new substitution identical to this one but limited to a subset of variables
    • isExtensionOf

      public boolean isExtensionOf(Substitution other)
      Description copied from interface: Substitution
      Checks whether another substitution is included in this one.
      Specified by:
      isExtensionOf in interface Substitution
      Parameters:
      other - a substitution
      Returns:
      true iff the other substitution is included into this one
    • isInjective

      public boolean isInjective()
      Description copied from interface: Substitution
      Indicates whether this substitution is injective.
      Specified by:
      isInjective in interface Substitution
      Returns:
      true iff this substitution is injective
    • isInvertible

      public boolean isInvertible()
      Description copied from interface: Substitution
      Indicates whether this substitution can be inverted as a substitution.
      Specified by:
      isInvertible in interface Substitution
      Returns:
      true iff the inverse of this substitution is a substitution
    • rangeTerms

      public Set<Term> rangeTerms()
      Description copied from interface: Substitution
      Returns the range terms of this substitution.
      Specified by:
      rangeTerms in interface Substitution
      Returns:
      all range term of the substitution
    • toMap

      public Map<Variable,Term> toMap()
      Description copied from interface: Substitution
      Convert the substitution to a map
      Specified by:
      toMap in interface Substitution
      Returns:
      A map that represents the substitution
    • hashCode

      public int hashCode()
      //////////////////////////////////////////////
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      a string representation of this substitution of the form {v1:t1, ..., vn:tn}