1
31
32 package gate.annotation;
33
34 import java.util.*;
35
36 import gate.*;
37 import gate.corpora.DocumentImpl;
38 import gate.event.*;
39 import gate.util.InvalidOffsetException;
40 import gate.util.RBTreeMap;
41
42
61 public class AnnotationSetImpl
62 extends AbstractSet
63 implements AnnotationSet {
64
65 private static final boolean DEBUG = false;
66
67
68 public AnnotationSetImpl(Document doc) {
69 annotsById = new HashMap();
71 this.doc = (DocumentImpl) doc;
72 }
74
75 public AnnotationSetImpl(Document doc, String name) {
76 this(doc);
77 this.name = name;
78 }
80
81
88
90 public AnnotationSetImpl(Collection c) throws ClassCastException {
91 this( ( (AnnotationSet) c).getDocument(), ( (AnnotationSet) c).getName());
92 if (c instanceof AnnotationSetImpl) {
93 AnnotationSetImpl theC = (AnnotationSetImpl) c;
94 annotsById = (HashMap) theC.annotsById.clone();
95 if (theC.annotsByEndNode != null) {
96 annotsByEndNode = (Map) ( (HashMap) theC.annotsByEndNode).clone();
97 annotsByStartNode = (Map) ( (HashMap) theC.annotsByStartNode).clone();
98 }
99 if (theC.annotsByType != null)
100 annotsByType = (Map) ( (HashMap) theC.annotsByType).clone();
101 if (theC.nodesByOffset != null) {
102 nodesByOffset = (RBTreeMap) theC.nodesByOffset.clone();
103 }
104 }
105 else
106 addAll(c);
107 }
109
111
114 class AnnotationSetIterator
115 implements Iterator {
116 private Iterator iter;
117 protected Annotation lastNext = null;
118 AnnotationSetIterator() {
119 iter = annotsById.values().iterator();
120 }
121
122 public boolean hasNext() {
123 return iter.hasNext();
124 }
125
126 public Object next() {
127 return (lastNext = (Annotation) iter.next());
128 }
129
130 public void remove() {
131 iter.remove();
133 removeFromTypeIndex(lastNext);
135 removeFromOffsetIndex(lastNext);
137 fireAnnotationRemoved(new AnnotationSetEvent(
140 AnnotationSetImpl.this,
141 AnnotationSetEvent.ANNOTATION_REMOVED,
142 getDocument(), (Annotation) lastNext));
143 } };
146
157 public class VerboseHashMap
158 extends HashMap {
159 VerboseHashMap() {
160 super(Gate.HASH_STH_SIZE);
161 }
163 public Object remove(Object key) {
164 Object res = super.remove(key);
165 if (res != null) {
166 if (owner == null) {
167 fireAnnotationRemoved(new AnnotationSetEvent(
168 AnnotationSetImpl.this,
169 AnnotationSetEvent.ANNOTATION_REMOVED,
170 getDocument(), (Annotation) res));
171 }
172 else {
173 owner.fireAnnotationRemoved(new AnnotationSetEvent(
174 AnnotationSetImpl.this,
175 AnnotationSetEvent.ANNOTATION_REMOVED,
176 getDocument(), (Annotation) res));
177 }
178 }
179 return res;
180 }
182 static final long serialVersionUID = -4832487354063073511L;
183
184
189 private transient AnnotationSetImpl owner;
190
191
196 public void setOwner(AnnotationSetImpl newOwner) {
197 this.owner = newOwner;
198 }
199 }
201
202 public Iterator iterator() {
203 return new AnnotationSetIterator();
204 }
205
206
207 public boolean remove(Object o) throws ClassCastException {
208 Annotation a = (Annotation) o;
209 boolean wasPresent = removeFromIdIndex(a);
210 if (wasPresent) {
211 removeFromTypeIndex(a);
212 removeFromOffsetIndex(a);
213 }
214 fireAnnotationRemoved(new AnnotationSetEvent(
216 AnnotationSetImpl.this,
217 AnnotationSetEvent.ANNOTATION_REMOVED,
218 getDocument(), a));
219
220 return wasPresent;
221 }
223
224
225 protected boolean removeFromIdIndex(Annotation a) {
226 if (annotsById.remove(a.getId()) == null)
227 return false;
228 return true;
229 }
231
232 protected void removeFromTypeIndex(Annotation a) {
233 if (annotsByType != null) {
234 AnnotationSet sameType = (AnnotationSet) annotsByType.get(a.getType());
235 if (sameType != null)
236 sameType.remove(a);
237 if (sameType.isEmpty()) annotsByType.remove(a.getType());
239 }
240 }
242
243 protected void removeFromOffsetIndex(Annotation a) {
244 if (nodesByOffset != null) {
245 }
249 if (annotsByStartNode != null) {
250 Integer id = a.getStartNode().getId();
251 AnnotationSet starterAnnots = (AnnotationSet) annotsByStartNode.get(id);
252 starterAnnots.remove(a);
253 if (starterAnnots.isEmpty()) annotsByStartNode.remove(id);
255 }
256 if (annotsByEndNode != null) {
257 Integer id = a.getEndNode().getId();
258 AnnotationSet endingAnnots = (AnnotationSet) annotsByEndNode.get(id);
259 endingAnnots.remove(a);
260 if (endingAnnots.isEmpty()) annotsByEndNode.remove(id);
262 }
263 }
265
266 public int size() {
267 return annotsById.size();
268 }
269
270
271 public Annotation get(Integer id) {
272 return (Annotation) annotsById.get(id);
273 }
275
276 public AnnotationSet get() {
277 AnnotationSetImpl resultSet = new AnnotationSetImpl(doc);
278 resultSet.addAllKeepIDs(annotsById.values());
279 if (resultSet.isEmpty())
280 return null;
281 return resultSet;
282 }
284
285 public AnnotationSet get(String type) {
286 if (annotsByType == null)
287 indexByType();
288 return (AnnotationSet) annotsByType.get(type);
295 }
297
298 public AnnotationSet get(Set types) throws ClassCastException {
299 if (annotsByType == null)
300 indexByType();
301 Iterator iter = types.iterator();
302 AnnotationSetImpl resultSet = new AnnotationSetImpl(doc);
303 while (iter.hasNext()) {
304 String type = (String) iter.next();
305 AnnotationSet as = (AnnotationSet) annotsByType.get(type);
306 if (as != null)
307 resultSet.addAllKeepIDs(as);
308 } if (resultSet.isEmpty())
311 return null;
312 return resultSet;
313 }
315
339 public AnnotationSet get(String type, FeatureMap constraints) {
340 if (annotsByType == null)
341 indexByType();
342 AnnotationSet typeSet = get(type);
343 if (typeSet == null)
344 return null;
345 AnnotationSet resultSet = new AnnotationSetImpl(doc);
346 Iterator iter = typeSet.iterator();
347 while (iter.hasNext()) {
348 Annotation a = (Annotation) iter.next();
349
353 if( a.getFeatures().subsumes(constraints))
355 resultSet.add(a);
356 } if (resultSet.isEmpty())
358 return null;
359 return resultSet;
360 }
362
363 public AnnotationSet get(String type, Set featureNames) {
364 if (annotsByType == null)
365 indexByType();
366 AnnotationSet typeSet = null;
367 if (type != null) {
368 typeSet = get(type);
370 if (typeSet == null)
372 return null;
373 }
374 AnnotationSet resultSet = new AnnotationSetImpl(doc);
375 Iterator iter = null;
376 if (type != null)
377 iter = typeSet.iterator();
378 else
379 iter = annotsById.values().iterator();
380 while (iter.hasNext()) {
381 Annotation a = (Annotation) iter.next();
382 if (a.getFeatures().keySet().containsAll(featureNames))
386 resultSet.add(a);
387 } if (resultSet.isEmpty())
389 return null;
390 return resultSet;
391 }
393
399 public AnnotationSet get(Long offset) {
400 if (annotsByStartNode == null)
401 indexByStartOffset();
402 Node nextNode = (Node) nodesByOffset.getNextOf(offset);
404 if (nextNode == null) return null;
406 AnnotationSet res = (AnnotationSet) annotsByStartNode.get(nextNode.getId());
407 nextNode = (Node) nodesByOffset.getNextOf(new Long(offset.longValue() + 1));
409 while (res == null && nextNode != null) {
411 res = (AnnotationSet) annotsByStartNode.get(nextNode.getId());
412 nextNode = (Node) nodesByOffset.getNextOf(
414 new Long(nextNode.getOffset().longValue() + 1)
415 );
416 }
417 return res;
419 }
421
430 public AnnotationSet get(Long startOffset, Long endOffset) {
431 if (annotsByStartNode == null)
436 indexByStartOffset();
437 AnnotationSetImpl resultSet = new AnnotationSetImpl(doc);
438 Iterator nodesIter;
439 Iterator annotsIter;
440 Node currentNode;
441 Annotation currentAnnot;
442 nodesIter = nodesByOffset.headMap(startOffset).values().iterator();
445 while (nodesIter.hasNext()) {
446 currentNode = (Node) nodesIter.next();
447 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
448 if (fromPoint != null) {
449 annotsIter = (fromPoint).iterator();
450 while (annotsIter.hasNext()) {
451 currentAnnot = (Annotation) annotsIter.next();
452 if (currentAnnot.getEndNode().getOffset().compareTo(startOffset) > 0) {
453 resultSet.add(currentAnnot);
454 }
455 }
456 }
457 }
458 nodesIter = nodesByOffset.subMap(startOffset, endOffset).values().iterator();
461 while (nodesIter.hasNext()) {
462 currentNode = (Node) nodesIter.next();
463 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
464 if (fromPoint != null)
465 resultSet.addAllKeepIDs(fromPoint);
466 }
467 return resultSet;
468 }
470
476 public AnnotationSet getStrict(Long startOffset, Long endOffset) {
477 if (annotsByStartNode == null)
480 indexByStartOffset();
481 AnnotationSet resultSet = new AnnotationSetImpl(doc);
482 Iterator nodesIter;
483 Iterator annotsIter;
484 Node currentNode;
485 Annotation currentAnnot;
486 currentNode = (Node) nodesByOffset.get(startOffset);
488 if (currentNode != null) {
489 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
490 if (fromPoint != null) {
491 annotsIter = fromPoint.iterator();
492 while (annotsIter.hasNext()) {
493 currentAnnot = (Annotation) annotsIter.next();
494 if (currentAnnot.getEndNode().getOffset().compareTo(endOffset) == 0) {
495 resultSet.add(currentAnnot);
496 } } } } return resultSet;
501 }
503
513 public AnnotationSet get(String neededType, Long startOffset, Long endOffset) {
514 if (annotsByStartNode == null)
519 indexByStartOffset();
520 AnnotationSet resultSet = new AnnotationSetImpl(doc);
521 Iterator nodesIter;
522 Iterator annotsIter;
523 Node currentNode;
524 Annotation currentAnnot;
525 nodesIter = nodesByOffset.headMap(startOffset).values().iterator();
528 while (nodesIter.hasNext()) {
529 currentNode = (Node) nodesIter.next();
530 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
531 if (fromPoint != null) {
532 annotsIter = (fromPoint).iterator();
533 while (annotsIter.hasNext()) {
534 currentAnnot = (Annotation) annotsIter.next();
535 if (currentAnnot.getType().equals(neededType) &&
536 currentAnnot.getEndNode().getOffset().compareTo(startOffset) > 0
537 ) {
538 resultSet.add(currentAnnot);
539 } } }
542 }
543 nodesIter = nodesByOffset.subMap(startOffset, endOffset).values().iterator();
546 while (nodesIter.hasNext()) {
547 currentNode = (Node) nodesIter.next();
548 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
549 if (fromPoint != null) {
550 annotsIter = (fromPoint).iterator();
551 while (annotsIter.hasNext()) {
552 currentAnnot = (Annotation) annotsIter.next();
553 if (currentAnnot.getType().equals(neededType)) {
554 resultSet.add(currentAnnot);
555 } } } }
559 return resultSet;
560 }
562
563 public AnnotationSet get(String type, FeatureMap constraints, Long offset) {
564 AnnotationSet nextAnnots = (AnnotationSet) get(offset);
566 if (nextAnnots == null)
567 return null;
568 return nextAnnots.get(type, constraints);
570 }
572
576 public AnnotationSet getContained(Long startOffset, Long endOffset) {
577 if (annotsByStartNode == null)
580 indexByStartOffset();
581 AnnotationSet resultSet = new AnnotationSetImpl(doc);
582 Iterator nodesIter;
583 Iterator annotsIter;
584 Node currentNode;
585 Annotation currentAnnot;
586 nodesIter = nodesByOffset.subMap(startOffset, endOffset).values().iterator();
589 while (nodesIter.hasNext()) {
590 currentNode = (Node) nodesIter.next();
591 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
592 if (fromPoint == null)
593 continue;
594 Iterator annotIter = fromPoint.iterator();
597 while (annotIter.hasNext()) {
598 Annotation annot = (Annotation) annotIter.next();
599 if (annot.getEndNode().getOffset().compareTo(endOffset) <= 0)
600 resultSet.add(annot);
601 }
602 }
603 return resultSet;
604 }
606
607 public Node firstNode() {
608 indexByStartOffset();
609 if (nodesByOffset.isEmpty())
610 return null;
611 else
612 return (Node) nodesByOffset.get(nodesByOffset.firstKey());
613 }
615
616 public Node lastNode() {
617 indexByStartOffset();
618 indexByEndOffset();
619 if (nodesByOffset.isEmpty())
620 return null;
621 else
622 return (Node) nodesByOffset.get(nodesByOffset.lastKey());
623 }
625
629 public Node nextNode(Node node) {
630 indexByStartOffset();
631 indexByEndOffset();
632 return (Node) nodesByOffset.getNextOf(
633 new Long(node.getOffset().longValue() + 1)
634 );
635 }
636
637
640 public Integer add(Node start, Node end, String type, FeatureMap features) {
641 Integer id = doc.getNextAnnotationId();
643 Annotation a = new AnnotationImpl(id, start, end, type, features);
645 add(a);
647 return id;
648 }
650
651 public boolean add(Object o) throws ClassCastException {
652 Annotation a = (Annotation) o;
653 Object oldValue = annotsById.put(a.getId(), a);
654 if (annotsByType != null)
655 addToTypeIndex(a);
656 if (annotsByStartNode != null || annotsByEndNode != null)
657 addToOffsetIndex(a);
658 AnnotationSetEvent evt = new AnnotationSetEvent(
659 this,
660 AnnotationSetEvent.ANNOTATION_ADDED,
661 doc, a);
662 fireAnnotationAdded(evt);
663 fireGateEvent(evt);
664 return oldValue != a;
665 }
667
680 public boolean addAll(Collection c) {
681 Iterator annIter = c.iterator();
682 boolean changed = false;
683 while (annIter.hasNext()) {
684 Annotation a = (Annotation) annIter.next();
685 try {
686 add(a.getStartNode().getOffset(),
687 a.getEndNode().getOffset(),
688 a.getType(),
689 a.getFeatures());
690 changed = true;
691 }
692 catch (InvalidOffsetException ioe) {
693 throw new IllegalArgumentException(ioe.toString());
694 }
695 }
696 return changed;
697 }
698
699
712 protected boolean addAllKeepIDs(Collection c) {
713 Iterator annIter = c.iterator();
714 boolean changed = false;
715 while (annIter.hasNext()) {
716 Annotation a = (Annotation) annIter.next();
717 changed |= add(a);
718 }
719 return changed;
720 }
721
722
723 public Integer add(
724 Long start, Long end, String type, FeatureMap features
725 ) throws InvalidOffsetException {
726 if (!doc.isValidOffsetRange(start, end))
728 throw new InvalidOffsetException();
729 if (nodesByOffset == null) {
732 indexByStartOffset();
733 indexByEndOffset();
734 }
735 Node startNode = (Node) nodesByOffset.getNextOf(start);
737 if (startNode == null || !startNode.getOffset().equals(start))
738 startNode = new NodeImpl(doc.getNextNodeId(), start);
739 Node endNode = null;
740 if (start.equals(end))
741 endNode = startNode;
742 else
743 endNode = (Node) nodesByOffset.getNextOf(end);
744 if (endNode == null || !endNode.getOffset().equals(end))
745 endNode = new NodeImpl(doc.getNextNodeId(), end);
746 return add(startNode, endNode, type, features);
748 }
750
754 public void add(
755 Integer id, Long start, Long end, String type, FeatureMap features
756 ) throws InvalidOffsetException {
757 if (!doc.isValidOffsetRange(start, end))
759 throw new InvalidOffsetException();
760 if (nodesByOffset == null) {
763 indexByStartOffset();
764 indexByEndOffset();
765 }
766 Node startNode = (Node) nodesByOffset.getNextOf(start);
768 if (startNode == null || !startNode.getOffset().equals(start))
769 startNode = new NodeImpl(doc.getNextNodeId(), start);
770 Node endNode = null;
771 if (start.equals(end))
772 endNode = startNode;
773 else
774 endNode = (Node) nodesByOffset.getNextOf(end);
775 if (endNode == null || !endNode.getOffset().equals(end))
776 endNode = new NodeImpl(doc.getNextNodeId(), end);
777 Annotation a = new AnnotationImpl(id, startNode, endNode, type, features);
779 add(a);
780 }
782
783 protected void indexByType() {
784 if (annotsByType != null)
785 return;
786 annotsByType = new HashMap(Gate.HASH_STH_SIZE);
787 Annotation a;
788 Iterator annotIter = annotsById.values().iterator();
789 while (annotIter.hasNext())
790 addToTypeIndex( (Annotation) annotIter.next());
791 }
793
794 protected void indexByStartOffset() {
795 if (annotsByStartNode != null) return;
796 if (nodesByOffset == null) nodesByOffset = new RBTreeMap();
797 annotsByStartNode = new HashMap(Gate.HASH_STH_SIZE);
798 Iterator annotIter = annotsById.values().iterator();
799 while (annotIter.hasNext())
800 addToStartOffsetIndex( (Annotation) annotIter.next());
801 }
803
804 protected void indexByEndOffset() {
805 if (annotsByEndNode != null)
806 return;
807 if (nodesByOffset == null)
808 nodesByOffset = new RBTreeMap();
809 annotsByEndNode = new HashMap(Gate.HASH_STH_SIZE);
810 Annotation a;
811 Iterator annotIter = annotsById.values().iterator();
812 while (annotIter.hasNext())
813 addToEndOffsetIndex( (Annotation) annotIter.next());
814 }
816
819 void addToTypeIndex(Annotation a) {
820 if (annotsByType == null)
821 return;
822 String type = a.getType();
823 AnnotationSet sameType = (AnnotationSet) annotsByType.get(type);
824 if (sameType == null) {
825 sameType = new AnnotationSetImpl(doc);
826 annotsByType.put(type, sameType);
827 }
828 sameType.add(a);
829 }
831
834 void addToOffsetIndex(Annotation a) {
835 addToStartOffsetIndex(a);
836 addToEndOffsetIndex(a);
837 }
839
842 void addToStartOffsetIndex(Annotation a) {
843 Node startNode = a.getStartNode();
844 Node endNode = a.getEndNode();
845 Long start = startNode.getOffset();
846 Long end = endNode.getOffset();
847 if (nodesByOffset != null)
849 nodesByOffset.put(start, startNode);
850 if (annotsByStartNode == null)
852 return;
853 AnnotationSet thisNodeAnnots =
855 (AnnotationSet) annotsByStartNode.get(startNode.getId());
856 if (thisNodeAnnots == null) {
857 thisNodeAnnots = new AnnotationSetImpl(doc);
858 annotsByStartNode.put(startNode.getId(), thisNodeAnnots);
859 }
860 thisNodeAnnots.add(a);
862 }
864
867 void addToEndOffsetIndex(Annotation a) {
868 Node startNode = a.getStartNode();
869 Node endNode = a.getEndNode();
870 Long start = startNode.getOffset();
871 Long end = endNode.getOffset();
872 if (nodesByOffset != null)
874 nodesByOffset.put(end, endNode);
875 if (annotsByEndNode == null)
877 return;
878 AnnotationSet thisNodeAnnots =
880 (AnnotationSet) annotsByEndNode.get(endNode.getId());
881 if (thisNodeAnnots == null) {
882 thisNodeAnnots = new AnnotationSetImpl(doc);
883 annotsByEndNode.put(endNode.getId(), thisNodeAnnots);
884 }
885 thisNodeAnnots.add(a);
887 }
889
895 public void edit(Long start, Long end, DocumentContent replacement) {
896 indexByStartOffset();
898 indexByEndOffset();
899 if(end.compareTo(start) > 0){
900 List affectedNodes = new ArrayList(nodesByOffset.subMap(start,
903 new Long(end.longValue() + 1)).values());
904 NodeImpl firstNode = null;
907 if (!affectedNodes.isEmpty()) {
908 firstNode = (NodeImpl) affectedNodes.get(0);
909 List startingAnnotations = new ArrayList();
910 List endingAnnotations = new ArrayList();
911 for (int i = 1; i < affectedNodes.size(); i++) {
912 Node aNode = (Node) affectedNodes.get(i);
913 AnnotationSet annSet = (AnnotationSet) annotsByStartNode.get(aNode.
915 getId());
916 if (annSet != null)
917 startingAnnotations.addAll(annSet);
918 annSet = (AnnotationSet) annotsByEndNode.get(aNode.getId());
919 if (annSet != null)
920 endingAnnotations.addAll(annSet);
921 nodesByOffset.remove(aNode.getOffset());
923 annotsByStartNode.remove(aNode);
924 annotsByEndNode.remove(aNode);
925 }
926 Iterator annIter = startingAnnotations.iterator();
928 while (annIter.hasNext()) {
929 AnnotationImpl anAnnot = (AnnotationImpl) annIter.next();
930 anAnnot.start = firstNode;
931 addToStartOffsetIndex(anAnnot);
932 }
933 annIter = endingAnnotations.iterator();
934 while (annIter.hasNext()) {
935 AnnotationImpl anAnnot = (AnnotationImpl) annIter.next();
936 anAnnot.end = firstNode;
937 addToEndOffsetIndex(anAnnot);
938 }
939 nodesByOffset.remove(firstNode.getOffset());
942 firstNode.setOffset(start);
944 nodesByOffset.put(firstNode.getOffset(), firstNode);
946 }
947 }
948
949 boolean shouldPrepend = Gate.getUserConfig().
952 getBoolean(GateConstants.DOCEDIT_INSERT_PREPEND).booleanValue();
953
954 long s = start.longValue(), e = end.longValue();
955 long rlen = ( (replacement == null) ? 0 : replacement.size().longValue());
957
958 List nodesAfterReplacement = new ArrayList(
960 nodesByOffset.tailMap(start).values());
961
962 Iterator nodesAfterReplacementIter = nodesAfterReplacement.iterator();
964 while (nodesAfterReplacementIter.hasNext()) {
965 NodeImpl n = (NodeImpl) nodesAfterReplacementIter.next();
966 nodesByOffset.remove(n.getOffset());
967 }
968 nodesAfterReplacementIter = nodesAfterReplacement.iterator();
970 while (nodesAfterReplacementIter.hasNext()) {
971 NodeImpl n = (NodeImpl) nodesAfterReplacementIter.next();
972 long oldOffset = n.getOffset().longValue();
973 long newOffset = oldOffset - (e - s) + rlen;
975 if (oldOffset == s){
977 if(newOffset < s) newOffset = s;
979 if(shouldPrepend) newOffset = s;
981 }
982 n.setOffset(new Long(newOffset));
983 }
984 nodesAfterReplacementIter = nodesAfterReplacement.iterator();
986 while (nodesAfterReplacementIter.hasNext()) {
987 NodeImpl n = (NodeImpl) nodesAfterReplacementIter.next();
988 nodesByOffset.put(n.getOffset(), n);
989 }
990
991 }
999
1000 public String getName() {
1001 return name;
1002 }
1003
1004
1005 public Document getDocument() {
1006 return doc;
1007 }
1008
1009
1012 public Set getAllTypes() {
1013 indexByType();
1014 return annotsByType.keySet();
1015 }
1016
1017
1022 public Object clone() throws CloneNotSupportedException {
1023 return super.clone();
1024 }
1025
1026
1030 public synchronized void removeAnnotationSetListener(AnnotationSetListener l) {
1031 if (annotationSetListeners != null && annotationSetListeners.contains(l)) {
1032 Vector v = (Vector) annotationSetListeners.clone();
1033 v.removeElement(l);
1034 annotationSetListeners = v;
1035 }
1036 }
1037
1038
1042 public synchronized void addAnnotationSetListener(AnnotationSetListener l) {
1043 Vector v = annotationSetListeners == null ? new Vector(2) :
1044 (Vector) annotationSetListeners.clone();
1045 if (!v.contains(l)) {
1046 v.addElement(l);
1047 annotationSetListeners = v;
1048 }
1049 }
1050
1051
1052
1076
1090 String name = null;
1091
1092 DocumentImpl doc;
1093
1094 protected HashMap annotsById;
1095
1096 Map annotsByType = null;
1097
1098 RBTreeMap nodesByOffset = null;
1099
1102 Map annotsByStartNode;
1103
1106 Map annotsByEndNode;
1107 protected transient Vector annotationSetListeners;
1108 private transient Vector gateListeners;
1109
1113 protected void fireAnnotationAdded(AnnotationSetEvent e) {
1114 if (annotationSetListeners != null) {
1115 Vector listeners = annotationSetListeners;
1116 int count = listeners.size();
1117 for (int i = 0; i < count; i++) {
1118 ( (AnnotationSetListener) listeners.elementAt(i)).annotationAdded(e);
1119 }
1120 }
1121 }
1122
1123
1127 protected void fireAnnotationRemoved(AnnotationSetEvent e) {
1128 if (annotationSetListeners != null) {
1129 Vector listeners = annotationSetListeners;
1130 int count = listeners.size();
1131 for (int i = 0; i < count; i++) {
1132 ( (AnnotationSetListener) listeners.elementAt(i)).annotationRemoved(e);
1133 }
1134 }
1135 }
1136
1137
1141 public synchronized void removeGateListener(GateListener l) {
1142 if (gateListeners != null && gateListeners.contains(l)) {
1143 Vector v = (Vector) gateListeners.clone();
1144 v.removeElement(l);
1145 gateListeners = v;
1146 }
1147 }
1148
1149
1153 public synchronized void addGateListener(GateListener l) {
1154 Vector v = gateListeners == null ? new Vector(2) :
1155 (Vector) gateListeners.clone();
1156 if (!v.contains(l)) {
1157 v.addElement(l);
1158 gateListeners = v;
1159 }
1160 }
1161
1162
1166 protected void fireGateEvent(GateEvent e) {
1167 if (gateListeners != null) {
1168 Vector listeners = gateListeners;
1169 int count = listeners.size();
1170 for (int i = 0; i < count; i++) {
1171 ( (GateListener) listeners.elementAt(i)).processGateEvent(e);
1172 }
1173 }
1174 }
1175
1176
1177 static final long serialVersionUID = 1479426765310434166L;
1178}