public class MatcherMapBuilder<I,O>
extends java.lang.Object
MatcherMapConverter.
MatcherMapConvertercodeToMessageConverter = MatcherMapBuilder. create() .setDefaultValue("Unknown error!") .map("200", "Ok") .map(new RegexMatcher("3.."), "Redirect!") .map(new RegexMatcher("4.."), "Client error!") .map(new RegexMatcher("5.."), "Server error!") .build(); String message = codeToMessageConverter.convert(httpStatusCode);
| Constructor and Description |
|---|
MatcherMapBuilder()
MatcherMapBuilder constructor with no mapping and null default value.
|
MatcherMapBuilder(java.util.Map<org.hamcrest.Matcher<I>,O> matcherMap,
O defaultValue)
MatcherMapBuilder constructor with predefined matcher map and specified default value.
|
| Modifier and Type | Method and Description |
|---|---|
MatcherMapConverter<I,O> |
build()
Create
MatcherMapConverter basing on previously specified parameters. |
static <I,O> MatcherMapBuilder<I,O> |
create()
Creates empty mapper.
|
static <I,O> MatcherMapBuilder<I,O> |
create(java.util.Map<I,O> map)
Creates mapper from specified map.
|
MatcherMapBuilder<I,O> |
map(I input,
O output)
Maps specified source value to specified output value.
|
MatcherMapBuilder<I,O> |
map(org.hamcrest.Matcher<I> matcher,
O value)
Maps specified Harcrest matcher to value.
|
MatcherMapBuilder<I,O> |
setDefaultValue(O defaultValue)
Set default value.
|
MatcherMapBuilder<I,O> |
setNoMatchMessagePattern(java.lang.String pattern)
Set message pattern to be used to construct error message when no matches is found.
|
MatcherMapBuilder<I,O> |
throwExceptionOnNoMatch(boolean throwExceptionOnNoMatch)
Specifies whether to throw an exception if no match is found and no default value is specified.
|
public MatcherMapBuilder()
public MatcherMapBuilder(java.util.Map<org.hamcrest.Matcher<I>,O> matcherMap, O defaultValue)
matcherMap - MapdefaultValue - default value objectjava.lang.IllegalArgumentException - if matcherMap is is nullpublic static <I,O> MatcherMapBuilder<I,O> create()
I - source typeO - target typepublic static <I,O> MatcherMapBuilder<I,O> create(java.util.Map<I,O> map)
I - source typeO - target typemap - Map a map to create mapper from.public MatcherMapBuilder<I,O> setDefaultValue(O defaultValue)
Default value is used when no mapping is found for an object.
defaultValue - Object default value.public MatcherMapBuilder<I,O> setNoMatchMessagePattern(java.lang.String pattern)
pattern - String message pattern with single string placeholder '%s'public MatcherMapBuilder<I,O> throwExceptionOnNoMatch(boolean throwExceptionOnNoMatch)
throwExceptionOnNoMatch - boolean a flag. Default value is true.public MatcherMapBuilder<I,O> map(org.hamcrest.Matcher<I> matcher, O value)
This is the most flexible method. It's acceptable to pass any matcher from Harmcrest matcher library.
matcher - Matcher hamcrest matchervalue - value to mappublic MatcherMapBuilder<I,O> map(I input, O output)
input - source valueoutput - target valuepublic MatcherMapConverter<I,O> build()
MatcherMapConverter basing on previously specified parameters.