Skip to content

Commit c7f4dfb

Browse files
committed
fixes #208 - reformatted source code
1 parent de0e157 commit c7f4dfb

File tree

56 files changed

+6881
-6639
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+6881
-6639
lines changed

java-diff-utils-jgit/pom.xml

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<parent>
5-
<groupId>io.github.java-diff-utils</groupId>
6-
<artifactId>java-diff-utils-parent</artifactId>
7-
<version>4.16-SNAPSHOT</version>
8-
</parent>
9-
<artifactId>java-diff-utils-jgit</artifactId>
10-
<name>java-diff-utils-jgit</name>
11-
<packaging>jar</packaging>
12-
<description>This is an extension of java-diff-utils using jgit to use its implementation of
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>io.github.java-diff-utils</groupId>
6+
<artifactId>java-diff-utils-parent</artifactId>
7+
<version>4.16-SNAPSHOT</version>
8+
</parent>
9+
<artifactId>java-diff-utils-jgit</artifactId>
10+
<packaging>jar</packaging>
11+
<name>java-diff-utils-jgit</name>
12+
<description>This is an extension of java-diff-utils using jgit to use its implementation of
1313
some difference algorithms.</description>
14-
<dependencies>
15-
<dependency>
16-
<groupId>org.junit.jupiter</groupId>
17-
<artifactId>junit-jupiter</artifactId>
18-
<scope>test</scope>
19-
</dependency>
20-
<dependency>
21-
<!-- no upgrade possible till base JDK upgrade to 17 -->
22-
<groupId>org.eclipse.jgit</groupId>
23-
<artifactId>org.eclipse.jgit</artifactId>
24-
<version>5.13.3.202401111512-r</version>
25-
<exclusions>
26-
<exclusion>
27-
<groupId>com.googlecode.javaewah</groupId>
28-
<artifactId>JavaEWAH</artifactId>
29-
</exclusion>
30-
<exclusion>
31-
<groupId>commons-codec</groupId>
32-
<artifactId>commons-codec</artifactId>
33-
</exclusion>
34-
<exclusion>
35-
<groupId>commons-logging</groupId>
36-
<artifactId>commons-logging</artifactId>
37-
</exclusion>
38-
<exclusion>
39-
<groupId>org.apache.httpcomponents</groupId>
40-
<artifactId>httpclient</artifactId>
41-
</exclusion>
42-
<exclusion>
43-
<groupId>com.jcraft</groupId>
44-
<artifactId>jsch</artifactId>
45-
</exclusion>
46-
<exclusion>
47-
<groupId>org.slf4j</groupId>
48-
<artifactId>slf4j-api</artifactId>
49-
</exclusion>
50-
</exclusions>
51-
</dependency>
52-
<dependency>
53-
<groupId>${project.groupId}</groupId>
54-
<artifactId>java-diff-utils</artifactId>
55-
<version>${project.version}</version>
56-
</dependency>
57-
</dependencies>
58-
</project>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.junit.jupiter</groupId>
17+
<artifactId>junit-jupiter</artifactId>
18+
<scope>test</scope>
19+
</dependency>
20+
<dependency>
21+
<!-- no upgrade possible till base JDK upgrade to 17 -->
22+
<groupId>org.eclipse.jgit</groupId>
23+
<artifactId>org.eclipse.jgit</artifactId>
24+
<version>5.13.3.202401111512-r</version>
25+
<exclusions>
26+
<exclusion>
27+
<groupId>com.googlecode.javaewah</groupId>
28+
<artifactId>JavaEWAH</artifactId>
29+
</exclusion>
30+
<exclusion>
31+
<groupId>commons-codec</groupId>
32+
<artifactId>commons-codec</artifactId>
33+
</exclusion>
34+
<exclusion>
35+
<groupId>commons-logging</groupId>
36+
<artifactId>commons-logging</artifactId>
37+
</exclusion>
38+
<exclusion>
39+
<groupId>org.apache.httpcomponents</groupId>
40+
<artifactId>httpclient</artifactId>
41+
</exclusion>
42+
<exclusion>
43+
<groupId>com.jcraft</groupId>
44+
<artifactId>jsch</artifactId>
45+
</exclusion>
46+
<exclusion>
47+
<groupId>org.slf4j</groupId>
48+
<artifactId>slf4j-api</artifactId>
49+
</exclusion>
50+
</exclusions>
51+
</dependency>
52+
<dependency>
53+
<groupId>${project.groupId}</groupId>
54+
<artifactId>java-diff-utils</artifactId>
55+
<version>${project.version}</version>
56+
</dependency>
57+
</dependencies>
58+
</project>

java-diff-utils-jgit/src/main/java/com/github/difflib/algorithm/jgit/HistogramDiff.java

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,71 +35,71 @@
3535
*/
3636
public class HistogramDiff<T> implements DiffAlgorithmI<T> {
3737

38-
@Override
39-
public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) {
40-
Objects.requireNonNull(source, "source list must not be null");
41-
Objects.requireNonNull(target, "target list must not be null");
42-
if (progress != null) {
43-
progress.diffStart();
44-
}
45-
EditList diffList = new EditList();
46-
diffList.addAll(new org.eclipse.jgit.diff.HistogramDiff().diff(new DataListComparator<>(progress), new DataList<>(source), new DataList<>(target)));
47-
List<Change> patch = new ArrayList<>();
48-
for (Edit edit : diffList) {
49-
DeltaType type = DeltaType.EQUAL;
50-
switch (edit.getType()) {
51-
case DELETE:
52-
type = DeltaType.DELETE;
53-
break;
54-
case INSERT:
55-
type = DeltaType.INSERT;
56-
break;
57-
case REPLACE:
58-
type = DeltaType.CHANGE;
59-
break;
60-
}
61-
patch.add(new Change(type, edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB()));
62-
}
63-
if (progress != null) {
64-
progress.diffEnd();
65-
}
66-
return patch;
67-
}
38+
@Override
39+
public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) {
40+
Objects.requireNonNull(source, "source list must not be null");
41+
Objects.requireNonNull(target, "target list must not be null");
42+
if (progress != null) {
43+
progress.diffStart();
44+
}
45+
EditList diffList = new EditList();
46+
diffList.addAll(new org.eclipse.jgit.diff.HistogramDiff()
47+
.diff(new DataListComparator<>(progress), new DataList<>(source), new DataList<>(target)));
48+
List<Change> patch = new ArrayList<>();
49+
for (Edit edit : diffList) {
50+
DeltaType type = DeltaType.EQUAL;
51+
switch (edit.getType()) {
52+
case DELETE:
53+
type = DeltaType.DELETE;
54+
break;
55+
case INSERT:
56+
type = DeltaType.INSERT;
57+
break;
58+
case REPLACE:
59+
type = DeltaType.CHANGE;
60+
break;
61+
}
62+
patch.add(new Change(type, edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB()));
63+
}
64+
if (progress != null) {
65+
progress.diffEnd();
66+
}
67+
return patch;
68+
}
6869
}
6970

7071
class DataListComparator<T> extends SequenceComparator<DataList<T>> {
7172

72-
private final DiffAlgorithmListener progress;
73+
private final DiffAlgorithmListener progress;
7374

74-
public DataListComparator(DiffAlgorithmListener progress) {
75-
this.progress = progress;
76-
}
75+
public DataListComparator(DiffAlgorithmListener progress) {
76+
this.progress = progress;
77+
}
7778

78-
@Override
79-
public boolean equals(DataList<T> original, int orgIdx, DataList<T> revised, int revIdx) {
80-
if (progress != null) {
81-
progress.diffStep(orgIdx + revIdx, original.size() + revised.size());
82-
}
83-
return original.data.get(orgIdx).equals(revised.data.get(revIdx));
84-
}
85-
86-
@Override
87-
public int hash(DataList<T> s, int i) {
88-
return s.data.get(i).hashCode();
89-
}
79+
@Override
80+
public boolean equals(DataList<T> original, int orgIdx, DataList<T> revised, int revIdx) {
81+
if (progress != null) {
82+
progress.diffStep(orgIdx + revIdx, original.size() + revised.size());
83+
}
84+
return original.data.get(orgIdx).equals(revised.data.get(revIdx));
85+
}
9086

87+
@Override
88+
public int hash(DataList<T> s, int i) {
89+
return s.data.get(i).hashCode();
90+
}
9191
}
9292

9393
class DataList<T> extends Sequence {
9494

95-
final List<T> data;
95+
final List<T> data;
9696

97-
public DataList(List<T> data) {
98-
this.data = data;
99-
}
97+
public DataList(List<T> data) {
98+
this.data = data;
99+
}
100100

101-
@Override
102-
public int size() {
103-
return data.size();
104-
}
101+
@Override
102+
public int size() {
103+
return data.size();
104+
}
105105
}

java-diff-utils-jgit/src/test/java/com/github/difflib/algorithm/jgit/HistogramDiffTest.java

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
*/
1616
package com.github.difflib.algorithm.jgit;
1717

18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
1821
import com.github.difflib.algorithm.DiffAlgorithmListener;
1922
import com.github.difflib.patch.Patch;
2023
import com.github.difflib.patch.PatchFailedException;
2124
import java.util.ArrayList;
2225
import java.util.Arrays;
2326
import java.util.List;
24-
import static org.junit.jupiter.api.Assertions.assertEquals;
25-
import static org.junit.jupiter.api.Assertions.assertNotNull;
2627
import org.junit.jupiter.api.Test;
2728

2829
/**
@@ -31,57 +32,64 @@
3132
*/
3233
public class HistogramDiffTest {
3334

34-
public HistogramDiffTest() {
35-
}
35+
public HistogramDiffTest() {}
36+
37+
/**
38+
* Test of diff method, of class HistogramDiff.
39+
*/
40+
@Test
41+
public void testDiff() throws PatchFailedException {
42+
List<String> orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A");
43+
List<String> revList = Arrays.asList("C", "B", "A", "B", "A", "C");
44+
final Patch<String> patch =
45+
Patch.generate(orgList, revList, new HistogramDiff<String>().computeDiff(orgList, revList, null));
46+
System.out.println(patch);
47+
assertNotNull(patch);
48+
assertEquals(3, patch.getDeltas().size());
49+
assertEquals(
50+
"Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [DeleteDelta, position: 3, lines: [A, B]], [InsertDelta, position: 7, lines: [B, A, C]]]}",
51+
patch.toString());
52+
53+
List<String> patched = patch.applyTo(orgList);
54+
assertEquals(revList, patched);
55+
}
56+
57+
@Test
58+
public void testDiffWithListener() throws PatchFailedException {
59+
List<String> orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A");
60+
List<String> revList = Arrays.asList("C", "B", "A", "B", "A", "C");
3661

37-
/**
38-
* Test of diff method, of class HistogramDiff.
39-
*/
40-
@Test
41-
public void testDiff() throws PatchFailedException {
42-
List<String> orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A");
43-
List<String> revList = Arrays.asList("C", "B", "A", "B", "A", "C");
44-
final Patch<String> patch = Patch.generate(orgList, revList, new HistogramDiff<String>().computeDiff(orgList, revList, null));
45-
System.out.println(patch);
46-
assertNotNull(patch);
47-
assertEquals(3, patch.getDeltas().size());
48-
assertEquals("Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [DeleteDelta, position: 3, lines: [A, B]], [InsertDelta, position: 7, lines: [B, A, C]]]}", patch.toString());
62+
List<String> logdata = new ArrayList<>();
63+
final Patch<String> patch = Patch.generate(
64+
orgList,
65+
revList,
66+
new HistogramDiff<String>().computeDiff(orgList, revList, new DiffAlgorithmListener() {
67+
@Override
68+
public void diffStart() {
69+
logdata.add("start");
70+
}
4971

50-
List<String> patched = patch.applyTo(orgList);
51-
assertEquals(revList, patched);
52-
}
53-
54-
@Test
55-
public void testDiffWithListener() throws PatchFailedException {
56-
List<String> orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A");
57-
List<String> revList = Arrays.asList("C", "B", "A", "B", "A", "C");
58-
59-
List<String> logdata = new ArrayList<>();
60-
final Patch<String> patch = Patch.generate(orgList, revList, new HistogramDiff<String>().computeDiff(orgList, revList, new DiffAlgorithmListener() {
61-
@Override
62-
public void diffStart() {
63-
logdata.add("start");
64-
}
72+
@Override
73+
public void diffStep(int value, int max) {
74+
logdata.add(value + " - " + max);
75+
}
6576

66-
@Override
67-
public void diffStep(int value, int max) {
68-
logdata.add(value + " - " + max);
69-
}
77+
@Override
78+
public void diffEnd() {
79+
logdata.add("end");
80+
}
81+
}));
82+
System.out.println(patch);
83+
assertNotNull(patch);
84+
assertEquals(3, patch.getDeltas().size());
85+
assertEquals(
86+
"Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [DeleteDelta, position: 3, lines: [A, B]], [InsertDelta, position: 7, lines: [B, A, C]]]}",
87+
patch.toString());
7088

71-
@Override
72-
public void diffEnd() {
73-
logdata.add("end");
74-
}
75-
}));
76-
System.out.println(patch);
77-
assertNotNull(patch);
78-
assertEquals(3, patch.getDeltas().size());
79-
assertEquals("Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [DeleteDelta, position: 3, lines: [A, B]], [InsertDelta, position: 7, lines: [B, A, C]]]}", patch.toString());
89+
List<String> patched = patch.applyTo(orgList);
90+
assertEquals(revList, patched);
8091

81-
List<String> patched = patch.applyTo(orgList);
82-
assertEquals(revList, patched);
83-
84-
System.out.println(logdata);
85-
assertEquals(19, logdata.size());
86-
}
92+
System.out.println(logdata);
93+
assertEquals(19, logdata.size());
94+
}
8795
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy