22
33import de .variantsync .evolution .util .Logger ;
44import de .variantsync .evolution .util .list .NonEmptyList ;
5+ import de .variantsync .evolution .variability .sequenceextraction .CleaningEvolutionStepsStream ;
56import org .jetbrains .annotations .NotNull ;
67
78import java .util .*;
8- import java .util .function .Function ;
9+ import java .util .stream .Collectors ;
10+ import java .util .stream .Stream ;
911
1012public class VariabilityDataset {
1113 private final Set <SPLCommit > allCommits ;
@@ -67,9 +69,9 @@ public List<SPLCommit> getPartialSuccessCommits() {
6769 *
6870 * @return All sequences of commits that are usable in our evolution study.
6971 */
70- public VariabilityHistory getVariabilityHistory (final Function < Collection < SPLCommit >, List < NonEmptyList < SPLCommit >>> sequenceExtractor ) {
72+ public VariabilityHistory getVariabilityHistory (final SequenceExtractor sequenceExtractor ) {
7173 // Build a VariabilityHistory instance by applying the provided function to the set of success commits
72- final List <NonEmptyList <SPLCommit >> history = sequenceExtractor .apply (this .successCommits );
74+ final List <NonEmptyList <SPLCommit >> history = sequenceExtractor .extract (this .successCommits );
7375
7476 if (history .isEmpty ()) {
7577 Logger .error ("There is no valid sequence of commits from which a VariabilityHistory can be built!" );
@@ -79,6 +81,33 @@ public VariabilityHistory getVariabilityHistory(final Function<Collection<SPLCom
7981 }
8082 }
8183
84+ /**
85+ * Collects all evolution steps into a set.
86+ * @see #streamEvolutionSteps()
87+ */
88+ public Set <EvolutionStep <SPLCommit >> getEvolutionSteps () {
89+ return streamEvolutionSteps ().collect (Collectors .toSet ());
90+ }
91+
92+
93+ /**
94+ * Streams all valid pairs of success commits of this dataset.
95+ * @see #streamEvolutionSteps(Collection)
96+ */
97+ public Stream <EvolutionStep <SPLCommit >> streamEvolutionSteps () {
98+ return streamEvolutionSteps (successCommits );
99+ }
100+
101+ /**
102+ * Returns a sorted stream of {@link EvolutionStep<SPLCommit>}. Pairs of commits that
103+ * have one commits in common will be returned sequentially (similar to playing domino).
104+ * Visited SPLCommit's will be cleaned via {@link SPLCommit#forget()}.
105+ * @see #streamEvolutionSteps(Collection)
106+ */
107+ public CleaningEvolutionStepsStream <SPLCommit > tidyStreamEvolutionSteps () {
108+ return new CleaningEvolutionStepsStream <>(streamEvolutionSteps ()::iterator );
109+ }
110+
82111 /**
83112 * Return the set of commit pairs (childCommit, parentCommit) for which the following holds:
84113 * <ul>
@@ -95,28 +124,22 @@ public VariabilityHistory getVariabilityHistory(final Function<Collection<SPLCom
95124 *
96125 * @return Set of commit pairs that can be used in a variability evolution study
97126 */
98- public DominoSortedEvolutionSteps <SPLCommit > getCommitPairsForEvolutionStudy () {
99- Logger .debug ("Retrieving commit pairs for study..." );
100- final var steps = new DominoSortedEvolutionSteps <>(
101- successCommits .stream ()
102- .map (c -> {
103- if (c .parents ().isPresent ()) {
104- final SPLCommit [] parents = c .parents ().get ();
105- // We only consider commits that did not process a merge
106- final boolean notAMerge = parents .length == 1 ;
107- final SPLCommit p = parents [0 ];
108- // We only consider commits that processed an SPL commit whose parent was also processed
109- final boolean parentSuccess = successCommits .contains (p );
110- if (notAMerge && parentSuccess ) {
111- return new EvolutionStep <>(p , c );
112- }
113- }
114- return null ;
115- })
116- .filter (Objects ::nonNull )
117- );
118- Logger .debug ("Done." );
119- return steps ;
127+ public static Stream <EvolutionStep <SPLCommit >> streamEvolutionSteps (final Collection <SPLCommit > successCommits ) {
128+ return successCommits .stream ()
129+ .map (c -> {
130+ if (c .parents ().isPresent ()) {
131+ final SPLCommit [] parents = c .parents ().get ();
132+ // We only consider commits that did not process a merge
133+ final boolean notAMerge = parents .length == 1 ;
134+ final SPLCommit p = parents [0 ];
135+ // We only consider commits that processed an SPL commit whose parent was also processed
136+ final boolean parentSuccess = successCommits .contains (p );
137+ if (notAMerge && parentSuccess ) {
138+ return new EvolutionStep <>(p , c );
139+ }
140+ }
141+ return null ;
142+ })
143+ .filter (Objects ::nonNull );
120144 }
121-
122145}
0 commit comments