Add requireFactory method to MarkwonSpansFactory

This commit is contained in:
Dimitry Ivanov 2019-03-28 12:54:10 +03:00
parent a7163b8cf8
commit f2e6eaad36
2 changed files with 21 additions and 0 deletions

View File

@ -40,6 +40,17 @@ public interface MarkwonSpansFactory {
@Nullable
<N extends Node> SpanFactory getFactory(@NonNull Class<N> node);
/**
* To obtain current {@link SpanFactory} associated with specified node. Can be used
* when SpanFactory must be present for node. If it\'s not added/registered a runtime
* exception will be thrown
*
* @see #getFactory(Class)
* @since 3.0.1-SNAPSHOT
*/
@NonNull
<N extends Node> SpanFactory requireFactory(@NonNull Class<N> node);
@NonNull
MarkwonSpansFactory build();
}

View File

@ -58,6 +58,16 @@ class MarkwonSpansFactoryImpl implements MarkwonSpansFactory {
return factories.get(node);
}
@NonNull
@Override
public <N extends Node> SpanFactory requireFactory(@NonNull Class<N> node) {
final SpanFactory factory = getFactory(node);
if (factory == null) {
throw new NullPointerException(node.getName());
}
return factory;
}
@NonNull
@Override
public MarkwonSpansFactory build() {