1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.primefaces.extensions.model.monaco;
23
24 import java.io.Serializable;
25
26 import org.primefaces.shaded.owasp.encoder.Encode;
27
28
29
30
31
32
33 public class MonacoDiffEditorModel implements Serializable {
34 private static final long serialVersionUID = 1L;
35
36 private final static MonacoDiffEditorModel EMPTY = new MonacoDiffEditorModel();
37
38 private final String originalValue;
39
40 private final String modifiedValue;
41
42 public MonacoDiffEditorModel() {
43 this.originalValue = "";
44 this.modifiedValue = "";
45 }
46
47 public MonacoDiffEditorModel(String originalValue, String modifiedValue) {
48 this.originalValue = originalValue != null ? originalValue : "";
49 this.modifiedValue = modifiedValue != null ? modifiedValue : "";
50 }
51
52 public MonacoDiffEditorModel withOriginal(String originalValue) {
53 return new MonacoDiffEditorModel(originalValue, modifiedValue);
54 }
55
56 public MonacoDiffEditorModel withModified(String modifiedValue) {
57 return new MonacoDiffEditorModel(originalValue, modifiedValue);
58 }
59
60
61
62
63 public String getOriginalValue() {
64 return originalValue;
65 }
66
67
68
69
70 public String getModifiedValue() {
71 return modifiedValue;
72 }
73
74 @Override
75 public int hashCode() {
76 final int prime = 31;
77 int result = 1;
78 result = prime * result + ((modifiedValue == null) ? 0 : modifiedValue.hashCode());
79 result = prime * result + ((originalValue == null) ? 0 : originalValue.hashCode());
80 return result;
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) {
86 return true;
87 }
88 if (obj == null) {
89 return false;
90 }
91 if (getClass() != obj.getClass()) {
92 return false;
93 }
94 MonacoDiffEditorModel other = (MonacoDiffEditorModel) obj;
95 if (modifiedValue == null) {
96 if (other.modifiedValue != null) {
97 return false;
98 }
99 }
100 else if (!modifiedValue.equals(other.modifiedValue)) {
101 return false;
102 }
103 if (originalValue == null) {
104 if (other.originalValue != null) {
105 return false;
106 }
107 }
108 else if (!originalValue.equals(other.originalValue)) {
109 return false;
110 }
111 return true;
112 }
113
114
115
116
117 public boolean isEmpty() {
118 return originalValue != null && !originalValue.isEmpty() && modifiedValue != null && !modifiedValue.isEmpty();
119 }
120
121 @Override
122 public String toString() {
123 return "[\"" + Encode.forJava(originalValue) + "\",\"" + Encode.forJava(modifiedValue) + "\"]";
124 }
125
126
127
128
129 public static MonacoDiffEditorModel empty() {
130 return EMPTY;
131 }
132 }