DiffMatchPatch.javaname.fraser.neil.plaintext. Licensed under Apache License 2.0. Provides synchronous text comparison (diff), fuzzy matching (match), and patch application (patch) — the same algorithms that power Google Docs, Etherpad, and Wikipedia's revision comparison. Used by ProjectForge for text change tracking and version comparison.name.fraser.neil.plaintext — the exact package name from the original libraryThe library implements three related algorithms, all operating on plain text:
Computes the minimal set of edits to transform text1 into text2. The core algorithm is Myers' diff algorithm (1986), which finds the shortest edit script using an O(ND) time/space approach where N is the sum of string lengths and D is the number of differences.
DELETE, INSERT, EQUAL — each diff is a linked list of operationsdiff_cleanupSemantic() makes diffs human-readable; diff_cleanupEfficiency() optimizes for machine processing; diff_cleanupMerge() merges adjacent equal/deletion operationsLocates the best approximate match for a pattern within a larger text. Uses the Bitap algorithm (also known as shift-or or Baeza-Yates–Gonnet algorithm) which:
Match_Threshold)Match_Distance) to prefer matches near the expected locationCreates patches (text representations of diffs) that can be serialized, transmitted, and applied to other texts:
@@ -start,length +start,length @@ contextPatch_Margin context for matching)patch_apply() attempts fuzzy matching when exact context doesn't match — uses Match algorithm internally| Field | Default | Purpose |
|---|---|---|
Diff_Timeout | 1.0 seconds | Maximum seconds for a diff computation before returning partial result (0 = infinite) |
Diff_EditCost | 4 | Cost of an empty edit operation — higher values produce cleaner, less fragmented diffs |
Match_Threshold | 0.5 | Fuzzy match threshold (0.0 = exact, 1.0 = very loose) |
Match_Distance | 1000 | Locality bonus — distance in characters from expected match location |
Patch_DeleteThreshold | 0.5 | How closely delete blocks must match expected content to be accepted |
Patch_Margin | 4 | Context character count around patch hunks |
Match_MaxBits | 32 | Bit width for the Bitap algorithm (matches Java int size) |
Diffs are represented as a LinkedList<Diff> where each Diff is an inner static class with:
Operation operation — DELETE, INSERT, or EQUALString text — the text segment for this operationAn optimization for large texts: converts lines to unique Unicode characters, performs the diff on the compressed representation, then reconstructs line-level output. This dramatically reduces the comparison space for line-oriented text (e.g., source code).
java.io.UnsupportedEncodingExceptionjava.net.URLDecoder / URLEncoder — For encoding diff output for URL-safe transmissionjava.util.* — Lists, Maps, ArrayLists, LinkedLists, regex PatternsProjectForge embeds this library rather than depending on it as an external JAR. This was likely done because:
name.fraser.neil.plaintext) is distinct and non-conflictingLinkedList for diff storage because diffs are primarily traversed sequentially (not random-access) and the algorithm frequently prepends/appends elements.48a93dedb Colored console log. UserGroupCache export for debugging and comparing work now. CollectionUtil improved. KotlinStringExtension.shortenMiddle() added.