Skip to content

Commit

Permalink
FactoryBuilderNoDefaults abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
noties committed Nov 15, 2019
1 parent efa3473 commit 00d60e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,11 @@ public interface FactoryBuilder {
FactoryBuilder addDelimiterProcessor(@NonNull DelimiterProcessor processor);

/**
* Indicate if markdown references are enabled. {@code referencesEnabled=true} if {@link #includeDefaults()}
* was called
* Indicate if markdown references are enabled. By default = `true`
*/
@NonNull
FactoryBuilder referencesEnabled(boolean referencesEnabled);

/**
* Includes all default delimiter and inline processors, and sets {@code referencesEnabled=true}.
* Useful with subsequent calls to {@link #excludeInlineProcessor(Class)} or {@link #excludeDelimiterProcessor(Class)}
*/
@NonNull
FactoryBuilder includeDefaults();

@NonNull
FactoryBuilder excludeInlineProcessor(@NonNull Class<? extends InlineProcessor> processor);

Expand All @@ -78,6 +70,15 @@ public interface FactoryBuilder {
InlineParserFactory build();
}

public interface FactoryBuilderNoDefaults extends FactoryBuilder {
/**
* Includes all default delimiter and inline processors, and sets {@code referencesEnabled=true}.
* Useful with subsequent calls to {@link #excludeInlineProcessor(Class)} or {@link #excludeDelimiterProcessor(Class)}
*/
@NonNull
FactoryBuilder includeDefaults();
}

/**
* Creates an instance of {@link FactoryBuilder} and includes all defaults.
*
Expand All @@ -89,12 +90,12 @@ public static FactoryBuilder factoryBuilder() {
}

/**
* NB, this return an <em>empty</em> builder, so if no {@link FactoryBuilder#includeDefaults()}
* NB, this return an <em>empty</em> builder, so if no {@link FactoryBuilderNoDefaults#includeDefaults()}
* is called, it means effectively <strong>no inline parsing</strong> (unless further calls
* to {@link FactoryBuilder#addInlineProcessor(InlineProcessor)} or {@link FactoryBuilder#addDelimiterProcessor(DelimiterProcessor)}).
*/
@NonNull
public static FactoryBuilder factoryBuilderNoDefaults() {
public static FactoryBuilderNoDefaults factoryBuilderNoDefaults() {
return new FactoryBuilderImpl();
}

Expand Down Expand Up @@ -701,7 +702,7 @@ private static class DelimiterData {
}
}

static class FactoryBuilderImpl implements FactoryBuilder {
static class FactoryBuilderImpl implements FactoryBuilder, FactoryBuilderNoDefaults {

private final List<InlineProcessor> inlineProcessors = new ArrayList<>(3);
private final List<DelimiterProcessor> delimiterProcessors = new ArrayList<>(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ private void multiple_edit_spans() {
editText.setMovementMethod(LinkMovementMethod.getInstance());

final InlineParserFactory inlineParserFactory = MarkwonInlineParser.factoryBuilder()
.includeDefaults()
// no inline images will be parsed
.excludeInlineProcessor(BangInlineProcessor.class)
// no html tags will be parsed
Expand Down

0 comments on commit 00d60e2

Please sign in to comment.