1
13
14 package gate.util;
15
16 import gate.*;
17
18
22 public class TestEqual {
23
29 public static boolean documentsEqual(Document doc1, Document doc2){
30 message = "";
31 if(doc1 == null ^ doc2 == null){
32 message = "Documents not equal: null<>non-null!";
33 return false;
34 }
35 if(doc1 == null) return true;
36 if(! check(doc1.getContent(), doc2.getContent())){
37 message = "Document contents different!";
38 return false;
39 }
40
41 if(! check(doc1.getAnnotations(), doc2.getAnnotations())){
42 message = "Documents default AS not equal!";
43 return false;
44 }
45
46 if(doc1 instanceof TextualDocument){
47 if(doc2 instanceof TextualDocument){
48 if(! check(((TextualDocument)doc1).getEncoding(),
49 ((TextualDocument)doc2).getEncoding())){
50 message = "Textual documents with different encodings!";
51 return false;
52 }
53 }else{
54 message = "Documents not equal: textual<>non-textual!";
55 return false;
56 }
57 }
58 if(! check(doc1.getFeatures(), doc2.getFeatures())){
59 message = "Documents features not equal!";
60 return false;
61 }
62
63
66 if(! check(doc1.getNamedAnnotationSets(),
67 doc2.getNamedAnnotationSets())){
68 message = "Documents named annots not equal!";
69 return false;
70 }
71
72
90 if(! check(doc1.getSourceUrl(), doc2.getSourceUrl())){
91 message = "Documents sourceURLs not equal!";
92 return false;
93 }
94 if(! (check(doc1.getSourceUrlStartOffset(),
95 doc2.getSourceUrlStartOffset())
96 &&
97 check(doc1.getSourceUrlEndOffset(),
98 doc2.getSourceUrlEndOffset()))){
99 message = "Documents sourceURLOffsets not equal!";
100 return false;
101 }
102 return true;
103 }
104
105
108 public static boolean annotationSetsEqual(AnnotationSet as1,
109 AnnotationSet as2) {
110 if(as1 == null ^ as2 == null) return false;
111 if(as1 == null) return true;
112 if(as1.size() != as2.size()) return false;
114 try{
115 if(! as1.containsAll(as2)) return false;
116 }catch(ClassCastException unused) {
117 return false;
118 }catch(NullPointerException unused) {
119 return false;
120 }
121
122
126 if (! check(as1.getName(), as2.getName())) return false;
128 return true;
129 }
131
132
133
134
135 static protected boolean check(Object a, Object b) {
136 if(a == null || b == null) return a == b;
137 else return a.equals(b);
138 }
140
143 public static String message = "";
144 }