Skip to content

Instantly share code, notes, and snippets.

@tindzk
Created April 4, 2018 14:21
Show Gist options
  • Save tindzk/527a73a6b280ac30daf5ba1bd182bd07 to your computer and use it in GitHub Desktop.
Save tindzk/527a73a6b280ac30daf5ba1bd182bd07 to your computer and use it in GitHub Desktop.
import scala.collection.mutable
import scala.collection.JavaConverters._
import org.eclipse.jgit.diff.{HistogramDiff, Sequence, SequenceComparator}
val histogramDiff = new HistogramDiff()
histogramDiff.setFallbackAlgorithm(null)
val deltas = histogramDiff.diff(
new DataListComparator[Char],
new DataList(input.toBuffer),
new DataList(output.toBuffer)
).asScala
// ...
class DataListComparator[T] extends SequenceComparator[DataList[T]] {
override def equals(original: DataList[T],
orgIdx: Int,
revised: DataList[T],
revIdx: Int): Boolean =
original.data(orgIdx).equals(revised.data(revIdx))
override def hash(s: DataList[T], i: Int): Int = s.data(i).hashCode()
}
class DataList[T](val data: mutable.Buffer[T]) extends Sequence {
def size(): Int = data.length
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment