-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDiffUtils.java
More file actions
78 lines (66 loc) · 2.89 KB
/
DiffUtils.java
File metadata and controls
78 lines (66 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.openquartz.javaobjdiff;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.openquartz.javaobjdiff.util.IteratorUtils;
/**
* @author svnee
*/
public class DiffUtils {
private static final String EMPTY = "";
private DiffUtils() {
}
public static <T> String diff(T source, T target, ToStringStyle toStringStyle, String... excludeField) {
return buildDiff(source, target, toStringStyle, excludeField).toString();
}
public static <T> String diff(T source, T target, String prefix, String... excludeField) {
ToStringStyle toStringStyle = new SimplePrefixToStringStyle(prefix);
return buildDiff(source, target, toStringStyle, excludeField).toString();
}
public static <T> String diff(T source, T target) {
return diff(source, target, EMPTY, new String[]{});
}
public static <T> String diff(T source, T target, String... excludeField) {
return diff(source, target, EMPTY, excludeField);
}
/**
* Compare differences and return {@link DiffResult} for more flexible operation and judgment.
*
* @param source Source object
* @param target Target object
* @param prefix Specified prefix, default is empty string
* @param excludeField Fields to exclude from comparison
* @param <T> Type of objects to compare
* @return {@link DiffResult}
*/
public static <T> DiffResult<T> diffObj(T source, T target, String prefix, String... excludeField) {
ToStringStyle toStringStyle = new SimplePrefixToStringStyle(prefix);
return buildDiff(source, target, toStringStyle, excludeField);
}
/**
* Compare differences and return {@link DiffResult} for more flexible operation and judgment.
*
* @param source Source object
* @param target Target object
* @param <T> Type of objects to compare
* @return {@link DiffResult}
*/
public static <T> DiffResult<T> diffObj(T source, T target) {
return diffObj(source, target, EMPTY, new String[]{});
}
/**
* Compare differences and return {@link DiffResult} for more flexible operation and judgment.
*
* @param source Source object
* @param target Target object
* @param excludeField Fields to exclude from comparison
* @param <T> Type of objects to compare
* @return {@link DiffResult}
*/
public static <T> DiffResult<T> diffObj(T source, T target, String... excludeField) {
return diffObj(source, target, EMPTY, excludeField);
}
private static <T> DiffResult<T> buildDiff(T source, T target, ToStringStyle toStringStyle, String... excludeField) {
CacheReflectionDiffBuilder<T> diffBuilder = new CacheReflectionDiffBuilder<>(source, target, toStringStyle);
diffBuilder.setExcludeFieldSet(IteratorUtils.toSet(excludeField));
return diffBuilder.build();
}
}