-
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.
* add project and shift methods to Edit - initial dev, tests pass * bump to 0.2.0 * project method
- Loading branch information
Showing
5 changed files
with
110 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.languagetoys.aligner.edit; | ||
|
||
import java.util.function.Function; | ||
|
||
public class EditShift<T, R> { | ||
|
||
private final EditVisitor.Builder<T, R> visitor; | ||
private final Edit<T> edit; | ||
|
||
EditShift(Edit<T> edit, Function<Edit<T>, R> initial) { | ||
this.edit = edit; | ||
EditVisitor.Builder<T, R> builder = EditVisitor.builder(); | ||
this.visitor = builder | ||
.onDelete(initial) | ||
.onSubstitute(initial) | ||
.onEqual(initial) | ||
.onInsert(initial) | ||
.onTranspose(initial); | ||
} | ||
|
||
public EditShift<T, R> equal(Function<Edit<T>, R> visitor) { | ||
this.visitor.onEqual(visitor); | ||
return this; | ||
} | ||
|
||
public EditShift<T, R> insert(Function<Edit<T>, R> visitor) { | ||
this.visitor.onInsert(visitor); | ||
return this; | ||
} | ||
|
||
public EditShift<T, R> delete(Function<Edit<T>, R> visitor) { | ||
this.visitor.onDelete(visitor); | ||
return this; | ||
} | ||
|
||
public EditShift<T, R> substitute(Function<Edit<T>, R> visitor) { | ||
this.visitor.onSubstitute(visitor); | ||
return this; | ||
} | ||
|
||
public EditShift<T, R> transpose(Function<Edit<T>, R> visitor) { | ||
this.visitor.onTranspose(visitor); | ||
return this; | ||
} | ||
|
||
public R get() { | ||
return edit.accept(visitor.build()); | ||
} | ||
|
||
} |
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