Interface Extractor<A>
- Type Parameters:
A- the type of extracted data
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
An extractor is a view on a pattern which can be used to extract data after a successful match.
Patterns and extractors are dual concepts: Whereas patterns serve as consumers of target objects, extractors serve as suppliers of the extracted data.
-
Method Summary
Modifier and TypeMethodDescriptiondefault <B> Pattern<B> Returns a pattern that effectively substitutes a subpattern for this extractor in a given root pattern.eagerBindings(Pattern<B> root, B target) Returns a collection of values bound to this extractor by all matches of a patterns for a target.getValue()Returns the extracted data value.lazyBindings(Pattern<? super B> root, B target) Returns a lazy enumeration of values bound to this extractor by all matches of a patterns for a target.Returns a stream of values bound to this extractor by all matches of a patterns for a target.
-
Method Details
-
getValue
A getValue()Returns the extracted data value.The result is unspecified if the pattern viewed by this extractor is not in the state after a successful match.
- Returns:
- the extracted data value
-
eagerBindings
Returns a collection of values bound to this extractor by all matches of a patterns for a target.In contrast to
lazyBindings(Pattern, Object), the alternative successful matches are exhausted before this method returns.- Type Parameters:
B- the target type of objects to match against- Parameters:
root- the pattern to matchtarget- the object to match against- Returns:
- the values bound by this extractor on all successive matching
attempts of
rootagainsttarget, in order. The resultingListobject is not shared, and may be used and modified freely by the caller. - Throws:
NullPointerException- ifrootis null- See Also:
-
lazyBindings
Returns a lazy enumeration of values bound to this extractor by all matches of a patterns for a target.In contrast to
eagerBindings(Pattern, Object), the alternative successful matches are effected lazily on demand.- Type Parameters:
B- the target type of objects to match against- Parameters:
root- the pattern to matchtarget- the object to match against- Returns:
- the values bound by this extractor on all successive matching
attempts of
rootagainsttarget, in order. - Throws:
NullPointerException- ifrootis null- See Also:
-
stream
Returns a stream of values bound to this extractor by all matches of a patterns for a target.- Type Parameters:
B- the target type of objects to match against- Parameters:
root- the pattern to matchtarget- the object to match against- Returns:
- the stream of values bound by this extractor on all successive
matching attempts of
rootagainsttarget, in order. - Throws:
NullPointerException- ifrootis null- See Also:
-
bind
Returns a pattern that effectively substitutes a subpattern for this extractor in a given root pattern.The structure of the
rootpattern is not analyzed. Instead, its bindings to this extractor are enumerated (as inlazyBindings(Pattern, Object)) and matched successively with thesubpattern.- Type Parameters:
B- the target type of objects to match against- Parameters:
root- the root pattern to substitute in. Substitution has unspecified effect ifrootdoes not bind this extractor.sub- the subpattern to substitute- Returns:
- a pattern that effectively substitutes
subfor this extractor inroot - Throws:
NullPointerException- ifrootorsubis null- See Also:
-