Interface ExtractingTypePatternMatcher

  • All Superinterfaces:
    TypePatternMatcher

    public interface ExtractingTypePatternMatcher
    extends TypePatternMatcher
    A pattern-matching implementation for generic types that also extracts a type from matching types.

    For example, such a pattern could be described with the expression Collection<T> => T. It would only match against Collection and its subclasses, and would extract the resolved type for parameter T in the event of a match.

    • Method Detail

      • matches

        default boolean matches​(PojoTypeModel<?> typeToInspect)
        Description copied from interface: TypePatternMatcher
        Attempts to match a given type against this pattern, and return the result as a boolean.
        Specified by:
        matches in interface TypePatternMatcher
        Parameters:
        typeToInspect - A type that may, or may not, match the pattern.
        Returns:
        true in the event of a match, false otherwise.
      • extract

        Optional<? extends PojoTypeModel<?>> extract​(PojoTypeModel<?> typeToInspect)
        Attempts to match a given type against this pattern, and if matched, returns an upper bound of the extracted type.
        Parameters:
        typeToInspect - A type that may, or may not, match the pattern.
        Returns:
        The extracted type if there was a match, or an empty Optional otherwise.