Interface IPatternMatch

All Superinterfaces:
Cloneable
All Known Implementing Classes:
BasePatternMatch, GenericPatternMatch

public interface IPatternMatch extends Cloneable
Generic interface for a single match of a pattern. Each instance is a (partial) substitution of pattern parameters, essentially a parameter to value mapping.

Can also represent a partial match; unsubstituted parameters are assigned to null. Pattern matchers must never return a partial match, but they accept partial matches as method parameters.

  • Method Summary

    Modifier and Type
    Method
    Description
    get(int position)
    Returns the value of the parameter at the given position, or null if position is invalid.
    get(String parameterName)
    Returns the value of the parameter with the given name, or null if name is invalid.
    boolean
    Checks that this match is compatible with the given other match.
    boolean
    Returns whether the match object can be further modified after its creation.
    Returns the list of symbolic parameter names.
    Identifies the name of the pattern for which this is a match.
    Prints the list of parameter-value pairs.
    boolean
    set(int position, Object newValue)
    Sets the parameter at the given position to the given value.
    boolean
    set(String parameterName, Object newValue)
    Sets the parameter with the given name to the given value.
     
    Converts the match to an array representation, with each pattern parameter at their respective position.
    Takes an immutable snapshot of this match.
  • Method Details

    • specification

      IQuerySpecification<? extends InterpreterMatcher<? extends IPatternMatch>> specification()
      Returns:
      the pattern for which this is a match.
    • patternName

      String patternName()
      Identifies the name of the pattern for which this is a match.
    • parameterNames

      List<String> parameterNames()
      Returns the list of symbolic parameter names.
    • get

      Object get(String parameterName)
      Returns the value of the parameter with the given name, or null if name is invalid.
    • get

      Object get(int position)
      Returns the value of the parameter at the given position, or null if position is invalid.
    • set

      boolean set(String parameterName, Object newValue)
      Sets the parameter with the given name to the given value.

      Works only if match is mutable. See isMutable().

      Throws:
      UnsupportedOperationException - if match is not mutable.
    • set

      boolean set(int position, Object newValue)
      Sets the parameter at the given position to the given value.

      Works only if match is mutable. See isMutable().

      Throws:
      UnsupportedOperationException - if match is not mutable.
    • isMutable

      boolean isMutable()
      Returns whether the match object can be further modified after its creation. Setters work only if the match is mutable.

      Matches computed by the pattern matchers are not mutable, so that the match set cannot be modified externally. Partial matches used as matcher input, however, can be mutable; such match objects can be created using InterpreterMatcher.newEmptyMatch().

      Returns:
      whether the match can be modified
    • toArray

      Object[] toArray()
      Converts the match to an array representation, with each pattern parameter at their respective position. In case of a partial match, unsubstituted parameters will be represented as null elements in the array.
      Returns:
      a newly constructed array containing each parameter substitution of the match in order.
    • toImmutable

      IPatternMatch toImmutable()
      Takes an immutable snapshot of this match.
      Returns:
      the match itself in case of immutable matches, an immutable copy in case of mutable ones.
    • prettyPrint

      String prettyPrint()
      Prints the list of parameter-value pairs.
    • isCompatibleWith

      boolean isCompatibleWith(IPatternMatch other)
      Checks that this match is compatible with the given other match. This is used for filtering the match set of a matcher.

      Two non-null matches are compatible if and only if:

      • They share the same pattern.
      • For each parameter, where they are set (non-null) in both matches, their values are equal.

      Furthermore, all matches are considered compatible with null matches (e.g. empty filter).

      Parameters:
      other -
      Returns:
      true, if this is compatible with other, or other is null