1 package com.jsql.model.injection.strategy.blind.patch;
2
3 import com.jsql.model.injection.strategy.blind.patch.DiffMatchPatch.Operation;
4
5
6
7
8 public class Diff implements Comparable<Diff> {
9
10
11
12
13 private Operation operation;
14
15
16
17
18 private String text;
19
20
21
22
23
24
25 public Diff(Operation operation, String text) {
26
27
28 this.operation = operation;
29 this.text = text;
30 }
31
32
33
34
35
36 @Override
37 public String toString() {
38
39 String prettyText = this.text.replace('\n', '\u00b6');
40 return "Diff(" + this.operation + ",\"" + prettyText + "\")";
41 }
42
43
44
45
46
47
48 @Override
49 public int hashCode() {
50
51 final int prime = 31;
52 int result = this.operation == null ? 0 : this.operation.hashCode();
53 result += prime * (this.text == null ? 0 : this.text.hashCode());
54 return result;
55 }
56
57
58
59
60
61
62 @Override
63 public boolean equals(Object obj) {
64
65 if (this == obj) {
66 return true;
67 }
68 if (obj == null) {
69 return false;
70 }
71 if (this.getClass() != obj.getClass()) {
72 return false;
73 }
74
75 Diff other = (Diff) obj;
76 if (this.operation != other.operation) {
77 return false;
78 }
79
80 if (this.text == null) {
81 return other.text == null;
82 } else {
83 return this.text.equals(other.text);
84 }
85 }
86
87 @Override
88 public int compareTo(Diff diff) {
89 return this.toString().equals(diff.toString()) ? 0 : 1;
90 }
91
92
93
94
95 public Operation getOperation() {
96 return this.operation;
97 }
98
99 public void setOperation(Operation operation) {
100 this.operation = operation;
101 }
102
103 public String getText() {
104 return this.text;
105 }
106
107 public void setText(String text) {
108 this.text = text;
109 }
110 }