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 this.operation = operation;
28 this.text = text;
29 }
30
31
32
33
34
35 @Override
36 public String toString() {
37 String prettyText = this.text.replace('\n', '\u00b6');
38 return "Diff(" + this.operation + ",\"" + prettyText + "\")";
39 }
40
41
42
43
44
45
46 @Override
47 public int hashCode() {
48 final int prime = 31;
49 int result = this.operation == null ? 0 : this.operation.hashCode();
50 result += prime * (this.text == null ? 0 : this.text.hashCode());
51 return result;
52 }
53
54
55
56
57
58
59 @Override
60 public boolean equals(Object obj) {
61 if (this == obj) {
62 return true;
63 }
64 if (obj == null) {
65 return false;
66 }
67 if (this.getClass() != obj.getClass()) {
68 return false;
69 }
70
71 Diff other = (Diff) obj;
72 if (this.operation != other.operation) {
73 return false;
74 }
75
76 if (this.text == null) {
77 return other.text == null;
78 } else {
79 return this.text.equals(other.text);
80 }
81 }
82
83 @Override
84 public int compareTo(Diff diff) {
85 return this.toString().equals(diff.toString()) ? 0 : 1;
86 }
87
88
89
90
91 public Operation getOperation() {
92 return this.operation;
93 }
94
95 public void setOperation(Operation operation) {
96 this.operation = operation;
97 }
98
99 public String getText() {
100 return this.text;
101 }
102
103 public void setText(String text) {
104 this.text = text;
105 }
106 }