Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions hamcrest-core/src/main/java/org/hamcrest/FeatureMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,18 @@ public final void describeTo(Description description) {
description.appendText(featureDescription).appendText(" ")
.appendDescriptionOf(subMatcher);
}

public static <T, U> FeatureMatcher<T, U> ofFunction(final Mapper<T, U> mapper, Matcher<? super U> matcher, String featureDescription, String featureName) {
return new FeatureMatcher<T, U>(matcher, featureDescription, featureName) {
@Override
protected U featureValueOf(T actual) {
return mapper.map(actual);
}
};
}

// TODO java 8 @FunctionalInterface
public interface Mapper<T, U> {
U map(T t);
}
}