-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b53ba40
commit 58aad0b
Showing
9 changed files
with
161 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
java/src/main/java/io/cucumber/query/LineageCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.cucumber.query; | ||
|
||
import io.cucumber.messages.types.Examples; | ||
import io.cucumber.messages.types.Feature; | ||
import io.cucumber.messages.types.GherkinDocument; | ||
import io.cucumber.messages.types.Pickle; | ||
import io.cucumber.messages.types.Rule; | ||
import io.cucumber.messages.types.Scenario; | ||
import io.cucumber.messages.types.TableRow; | ||
|
||
/** | ||
* Visit the members of {@link Lineage} of a gherkin document element or | ||
* {@link Pickle} and collect these into a single result. | ||
* <p> | ||
* Because we are using messages we can not express the hierarchy of elements in | ||
* a {@link GherkinDocument} programmatically as a tree of nodes. But we can | ||
* still express the operations that would be typically done with a tree as | ||
* operations on that elements lineage. | ||
* | ||
* @param <T> the type reduced to. | ||
*/ | ||
interface LineageCollector<T> { | ||
default void add(GherkinDocument document) { | ||
|
||
} | ||
|
||
default void add(Feature feature) { | ||
|
||
} | ||
|
||
default void add(Rule rule) { | ||
|
||
} | ||
|
||
default void add(Scenario scenario) { | ||
|
||
} | ||
|
||
default void add(Examples examples, int index) { | ||
} | ||
|
||
default void add(TableRow example, int index) { | ||
} | ||
|
||
default void add(Pickle pickle) { | ||
} | ||
|
||
T finish(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,24 @@ | ||
package io.cucumber.query; | ||
|
||
import io.cucumber.messages.types.Examples; | ||
import io.cucumber.messages.types.Feature; | ||
import io.cucumber.messages.types.GherkinDocument; | ||
import io.cucumber.messages.types.Pickle; | ||
import io.cucumber.messages.types.Rule; | ||
import io.cucumber.messages.types.Scenario; | ||
import io.cucumber.messages.types.TableRow; | ||
|
||
interface LineageReducer<T> { | ||
default void add(GherkinDocument document) { | ||
|
||
} | ||
default void add(Feature feature) { | ||
|
||
} | ||
|
||
default void add(Rule rule) { | ||
import java.util.function.Supplier; | ||
|
||
} | ||
|
||
default void add(Scenario scenario) { | ||
import static java.util.Objects.requireNonNull; | ||
|
||
} | ||
/** | ||
* S | ||
* | ||
* @param <T> | ||
*/ | ||
interface LineageReducer<T> { | ||
|
||
default void add(Examples examples, int index) { | ||
static <T> LineageReducer<T> descending(Supplier<? extends LineageCollector<T>> collector){ | ||
return new LineageReducerDescending<>(collector); | ||
} | ||
|
||
default void add(TableRow example, int index) { | ||
} | ||
T reduce(Lineage lineage); | ||
|
||
default void add(Pickle pickle) { | ||
} | ||
T reduce(Lineage lineage, Pickle pickle); | ||
|
||
T finish(); | ||
} |
45 changes: 45 additions & 0 deletions
45
java/src/main/java/io/cucumber/query/LineageReducerDescending.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.cucumber.query; | ||
|
||
import io.cucumber.messages.types.Pickle; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Reduces the lineage of a Gherkin document element in descending order. | ||
* | ||
* @param <T> type to which the lineage is reduced. | ||
*/ | ||
class LineageReducerDescending<T> implements LineageReducer<T> { | ||
|
||
private final Supplier<? extends LineageCollector<T>> reducerSupplier; | ||
|
||
LineageReducerDescending(Supplier<? extends LineageCollector<T>> reducerSupplier) { | ||
this.reducerSupplier = requireNonNull(reducerSupplier); | ||
} | ||
|
||
@Override | ||
public T reduce(Lineage lineage) { | ||
LineageCollector<T> reducer = reducerSupplier.get(); | ||
reduceAddLineage(reducer, lineage); | ||
return reducer.finish(); | ||
} | ||
|
||
@Override | ||
public T reduce(Lineage lineage, Pickle pickle) { | ||
LineageCollector<T> reducer = reducerSupplier.get(); | ||
reduceAddLineage(reducer, lineage); | ||
reducer.add(pickle); | ||
return reducer.finish(); | ||
} | ||
|
||
private static <T> void reduceAddLineage(LineageCollector<T> reducer, Lineage lineage) { | ||
reducer.add(lineage.document()); | ||
lineage.feature().ifPresent(reducer::add); | ||
lineage.rule().ifPresent(reducer::add); | ||
lineage.scenario().ifPresent(reducer::add); | ||
lineage.examples().ifPresent(examples -> reducer.add(examples, lineage.examplesIndex().orElse(0))); | ||
lineage.example().ifPresent(example -> reducer.add(example, lineage.exampleIndex().orElse(0))); | ||
} | ||
} |
51 changes: 0 additions & 51 deletions
51
java/src/main/java/io/cucumber/query/LineageReducerStrategy.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.