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
316 public AnnotationSet get(String type, FeatureMap constraints) {
317 if (annotsByType == null)
318 indexByType();
319 AnnotationSet typeSet = get(type);
320 if (typeSet == null)
321 return null;
322 AnnotationSet resultSet = new AnnotationSetImpl(doc);
323 Iterator iter = typeSet.iterator();
324 while (iter.hasNext()) {
325 Annotation a = (Annotation) iter.next();
326
330 if( a.getFeatures().subsumes(constraints))
332 resultSet.add(a);
333 } if (resultSet.isEmpty())
335 return null;
336 return resultSet;
337 }
339
340 public AnnotationSet get(String type, Set featureNames) {
341 if (annotsByType == null)
342 indexByType();
343 AnnotationSet typeSet = null;
344 if (type != null) {
345 typeSet = get(type);
347 if (typeSet == null)
349 return null;
350 }
351 AnnotationSet resultSet = new AnnotationSetImpl(doc);
352 Iterator iter = null;
353 if (type != null)
354 iter = typeSet.iterator();
355 else
356 iter = annotsById.values().iterator();
357 while (iter.hasNext()) {
358 Annotation a = (Annotation) iter.next();
359 if (a.getFeatures().keySet().containsAll(featureNames))
363 resultSet.add(a);
364 } if (resultSet.isEmpty())
366 return null;
367 return resultSet;
368 }
370
376 public AnnotationSet get(Long offset) {
377 if (annotsByStartNode == null)
378 indexByStartOffset();
379 Node nextNode = (Node) nodesByOffset.getNextOf(offset);
381 if (nextNode == null) return null;
383 AnnotationSet res = (AnnotationSet) annotsByStartNode.get(nextNode.getId());
384 nextNode = (Node) nodesByOffset.getNextOf(new Long(offset.longValue() + 1));
386 while (res == null && nextNode != null) {
388 res = (AnnotationSet) annotsByStartNode.get(nextNode.getId());
389 nextNode = (Node) nodesByOffset.getNextOf(
391 new Long(nextNode.getOffset().longValue() + 1)
392 );
393 }
394 return res;
396 }
398
407 public AnnotationSet get(Long startOffset, Long endOffset) {
408 if (annotsByStartNode == null)
413 indexByStartOffset();
414 AnnotationSetImpl resultSet = new AnnotationSetImpl(doc);
415 Iterator nodesIter;
416 Iterator annotsIter;
417 Node currentNode;
418 Annotation currentAnnot;
419 nodesIter = nodesByOffset.headMap(startOffset).values().iterator();
422 while (nodesIter.hasNext()) {
423 currentNode = (Node) nodesIter.next();
424 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
425 if (fromPoint != null) {
426 annotsIter = (fromPoint).iterator();
427 while (annotsIter.hasNext()) {
428 currentAnnot = (Annotation) annotsIter.next();
429 if (currentAnnot.getEndNode().getOffset().compareTo(startOffset) > 0) {
430 resultSet.add(currentAnnot);
431 }
432 }
433 }
434 }
435 nodesIter = nodesByOffset.subMap(startOffset, endOffset).values().iterator();
438 while (nodesIter.hasNext()) {
439 currentNode = (Node) nodesIter.next();
440 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
441 if (fromPoint != null)
442 resultSet.addAllKeepIDs(fromPoint);
443 }
444 return resultSet;
445 }
447
453 public AnnotationSet getStrict(Long startOffset, Long endOffset) {
454 if (annotsByStartNode == null)
457 indexByStartOffset();
458 AnnotationSet resultSet = new AnnotationSetImpl(doc);
459 Iterator nodesIter;
460 Iterator annotsIter;
461 Node currentNode;
462 Annotation currentAnnot;
463 currentNode = (Node) nodesByOffset.get(startOffset);
465 if (currentNode != null) {
466 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
467 if (fromPoint != null) {
468 annotsIter = fromPoint.iterator();
469 while (annotsIter.hasNext()) {
470 currentAnnot = (Annotation) annotsIter.next();
471 if (currentAnnot.getEndNode().getOffset().compareTo(endOffset) == 0) {
472 resultSet.add(currentAnnot);
473 } } } } return resultSet;
478 }
480
490 public AnnotationSet get(String neededType, Long startOffset, Long endOffset) {
491 if (annotsByStartNode == null)
496 indexByStartOffset();
497 AnnotationSet resultSet = new AnnotationSetImpl(doc);
498 Iterator nodesIter;
499 Iterator annotsIter;
500 Node currentNode;
501 Annotation currentAnnot;
502 nodesIter = nodesByOffset.headMap(startOffset).values().iterator();
505 while (nodesIter.hasNext()) {
506 currentNode = (Node) nodesIter.next();
507 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
508 if (fromPoint != null) {
509 annotsIter = (fromPoint).iterator();
510 while (annotsIter.hasNext()) {
511 currentAnnot = (Annotation) annotsIter.next();
512 if (currentAnnot.getType().equals(neededType) &&
513 currentAnnot.getEndNode().getOffset().compareTo(startOffset) > 0
514 ) {
515 resultSet.add(currentAnnot);
516 } } }
519 }
520 nodesIter = nodesByOffset.subMap(startOffset, endOffset).values().iterator();
523 while (nodesIter.hasNext()) {
524 currentNode = (Node) nodesIter.next();
525 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
526 if (fromPoint != null) {
527 annotsIter = (fromPoint).iterator();
528 while (annotsIter.hasNext()) {
529 currentAnnot = (Annotation) annotsIter.next();
530 if (currentAnnot.getType().equals(neededType)) {
531 resultSet.add(currentAnnot);
532 } } } }
536 return resultSet;
537 }
539
540 public AnnotationSet get(String type, FeatureMap constraints, Long offset) {
541 AnnotationSet nextAnnots = (AnnotationSet) get(offset);
543 if (nextAnnots == null)
544 return null;
545 return nextAnnots.get(type, constraints);
547 }
549
553 public AnnotationSet getContained(Long startOffset, Long endOffset) {
554 if (annotsByStartNode == null)
557 indexByStartOffset();
558 AnnotationSet resultSet = new AnnotationSetImpl(doc);
559 Iterator nodesIter;
560 Iterator annotsIter;
561 Node currentNode;
562 Annotation currentAnnot;
563 nodesIter = nodesByOffset.subMap(startOffset, endOffset).values().iterator();
566 while (nodesIter.hasNext()) {
567 currentNode = (Node) nodesIter.next();
568 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
569 if (fromPoint == null)
570 continue;
571 Iterator annotIter = fromPoint.iterator();
574 while (annotIter.hasNext()) {
575 Annotation annot = (Annotation) annotIter.next();
576 if (annot.getEndNode().getOffset().compareTo(endOffset) <= 0)
577 resultSet.add(annot);
578 }
579 }
580 return resultSet;
581 }
583
584 public Node firstNode() {
585 indexByStartOffset();
586 if (nodesByOffset.isEmpty())
587 return null;
588 else
589 return (Node) nodesByOffset.get(nodesByOffset.firstKey());
590 }
592
593 public Node lastNode() {
594 indexByStartOffset();
595 indexByEndOffset();
596 if (nodesByOffset.isEmpty())
597 return null;
598 else
599 return (Node) nodesByOffset.get(nodesByOffset.lastKey());
600 }
602
606 public Node nextNode(Node node) {
607 indexByStartOffset();
608 indexByEndOffset();
609 return (Node) nodesByOffset.getNextOf(
610 new Long(node.getOffset().longValue() + 1)
611 );
612 }
613
614
617 public Integer add(Node start, Node end, String type, FeatureMap features) {
618 Integer id = doc.getNextAnnotationId();
620 Annotation a = new AnnotationImpl(id, start, end, type, features);
622 add(a);
624 return id;
625 }
627
628 public boolean add(Object o) throws ClassCastException {
629 Annotation a = (Annotation) o;
630 Object oldValue = annotsById.put(a.getId(), a);
631 if (annotsByType != null)
632 addToTypeIndex(a);
633 if (annotsByStartNode != null || annotsByEndNode != null)
634 addToOffsetIndex(a);
635 AnnotationSetEvent evt = new AnnotationSetEvent(
636 this,
637 AnnotationSetEvent.ANNOTATION_ADDED,
638 doc, a);
639 fireAnnotationAdded(evt);
640 fireGateEvent(evt);
641 return oldValue != a;
642 }
644
657 public boolean addAll(Collection c) {
658 Iterator annIter = c.iterator();
659 boolean changed = false;
660 while (annIter.hasNext()) {
661 Annotation a = (Annotation) annIter.next();
662 try {
663 add(a.getStartNode().getOffset(),
664 a.getEndNode().getOffset(),
665 a.getType(),
666 a.getFeatures());
667 changed = true;
668 }
669 catch (InvalidOffsetException ioe) {
670 throw new IllegalArgumentException(ioe.toString());
671 }
672 }
673 return changed;
674 }
675
676
689 protected boolean addAllKeepIDs(Collection c) {
690 Iterator annIter = c.iterator();
691 boolean changed = false;
692 while (annIter.hasNext()) {
693 Annotation a = (Annotation) annIter.next();
694 changed |= add(a);
695 }
696 return changed;
697 }
698
699
700 public Integer add(
701 Long start, Long end, String type, FeatureMap features
702 ) throws InvalidOffsetException {
703 if (!doc.isValidOffsetRange(start, end))
705 throw new InvalidOffsetException();
706 if (nodesByOffset == null) {
709 indexByStartOffset();
710 indexByEndOffset();
711 }
712 Node startNode = (Node) nodesByOffset.getNextOf(start);
714 if (startNode == null || !startNode.getOffset().equals(start))
715 startNode = new NodeImpl(doc.getNextNodeId(), start);
716 Node endNode = null;
717 if (start.equals(end))
718 endNode = startNode;
719 else
720 endNode = (Node) nodesByOffset.getNextOf(end);
721 if (endNode == null || !endNode.getOffset().equals(end))
722 endNode = new NodeImpl(doc.getNextNodeId(), end);
723 return add(startNode, endNode, type, features);
725 }
727
731 public void add(
732 Integer id, Long start, Long end, String type, FeatureMap features
733 ) throws InvalidOffsetException {
734 if (!doc.isValidOffsetRange(start, end))
736 throw new InvalidOffsetException();
737 if (nodesByOffset == null) {
740 indexByStartOffset();
741 indexByEndOffset();
742 }
743 Node startNode = (Node) nodesByOffset.getNextOf(start);
745 if (startNode == null || !startNode.getOffset().equals(start))
746 startNode = new NodeImpl(doc.getNextNodeId(), start);
747 Node endNode = null;
748 if (start.equals(end))
749 endNode = startNode;
750 else
751 endNode = (Node) nodesByOffset.getNextOf(end);
752 if (endNode == null || !endNode.getOffset().equals(end))
753 endNode = new NodeImpl(doc.getNextNodeId(), end);
754 Annotation a = new AnnotationImpl(id, startNode, endNode, type, features);
756 add(a);
757 }
759
760 protected void indexByType() {
761 if (annotsByType != null)
762 return;
763 annotsByType = new HashMap(Gate.HASH_STH_SIZE);
764 Annotation a;
765 Iterator annotIter = annotsById.values().iterator();
766 while (annotIter.hasNext())
767 addToTypeIndex( (Annotation) annotIter.next());
768 }
770
771 protected void indexByStartOffset() {
772 if (annotsByStartNode != null) return;
773 if (nodesByOffset == null) nodesByOffset = new RBTreeMap();
774 annotsByStartNode = new HashMap(Gate.HASH_STH_SIZE);
775 Iterator annotIter = annotsById.values().iterator();
776 while (annotIter.hasNext())
777 addToStartOffsetIndex( (Annotation) annotIter.next());
778 }
780
781 protected void indexByEndOffset() {
782 if (annotsByEndNode != null)
783 return;
784 if (nodesByOffset == null)
785 nodesByOffset = new RBTreeMap();
786 annotsByEndNode = new HashMap(Gate.HASH_STH_SIZE);
787 Annotation a;
788 Iterator annotIter = annotsById.values().iterator();
789 while (annotIter.hasNext())
790 addToEndOffsetIndex( (Annotation) annotIter.next());
791 }
793
796 void addToTypeIndex(Annotation a) {
797 if (annotsByType == null)
798 return;
799 String type = a.getType();
800 AnnotationSet sameType = (AnnotationSet) annotsByType.get(type);
801 if (sameType == null) {
802 sameType = new AnnotationSetImpl(doc);
803 annotsByType.put(type, sameType);
804 }
805 sameType.add(a);
806 }
808
811 void addToOffsetIndex(Annotation a) {
812 addToStartOffsetIndex(a);
813 addToEndOffsetIndex(a);
814 }
816
819 void addToStartOffsetIndex(Annotation a) {
820 Node startNode = a.getStartNode();
821 Node endNode = a.getEndNode();
822 Long start = startNode.getOffset();
823 Long end = endNode.getOffset();
824 if (nodesByOffset != null)
826 nodesByOffset.put(start, startNode);
827 if (annotsByStartNode == null)
829 return;
830 AnnotationSet thisNodeAnnots =
832 (AnnotationSet) annotsByStartNode.get(startNode.getId());
833 if (thisNodeAnnots == null) {
834 thisNodeAnnots = new AnnotationSetImpl(doc);
835 annotsByStartNode.put(startNode.getId(), thisNodeAnnots);
836 }
837 thisNodeAnnots.add(a);
839 }
841
844 void addToEndOffsetIndex(Annotation a) {
845 Node startNode = a.getStartNode();
846 Node endNode = a.getEndNode();
847 Long start = startNode.getOffset();
848 Long end = endNode.getOffset();
849 if (nodesByOffset != null)
851 nodesByOffset.put(end, endNode);
852 if (annotsByEndNode == null)
854 return;
855 AnnotationSet thisNodeAnnots =
857 (AnnotationSet) annotsByEndNode.get(endNode.getId());
858 if (thisNodeAnnots == null) {
859 thisNodeAnnots = new AnnotationSetImpl(doc);
860 annotsByEndNode.put(endNode.getId(), thisNodeAnnots);
861 }
862 thisNodeAnnots.add(a);
864 }
866
872 public void edit(Long start, Long end, DocumentContent replacement) {
873 indexByStartOffset();
875 indexByEndOffset();
876 if(end.compareTo(start) > 0){
877 List affectedNodes = new ArrayList(nodesByOffset.subMap(start,
880 new Long(end.longValue() + 1)).values());
881 NodeImpl firstNode = null;
884 if (!affectedNodes.isEmpty()) {
885 firstNode = (NodeImpl) affectedNodes.get(0);
886 List startingAnnotations = new ArrayList();
887 List endingAnnotations = new ArrayList();
888 for (int i = 1; i < affectedNodes.size(); i++) {
889 Node aNode = (Node) affectedNodes.get(i);
890 AnnotationSet annSet = (AnnotationSet) annotsByStartNode.get(aNode.
892 getId());
893 if (annSet != null)
894 startingAnnotations.addAll(annSet);
895 annSet = (AnnotationSet) annotsByEndNode.get(aNode.getId());
896 if (annSet != null)
897 endingAnnotations.addAll(annSet);
898 nodesByOffset.remove(aNode.getOffset());
900 annotsByStartNode.remove(aNode);
901 annotsByEndNode.remove(aNode);
902 }
903 Iterator annIter = startingAnnotations.iterator();
905 while (annIter.hasNext()) {
906 AnnotationImpl anAnnot = (AnnotationImpl) annIter.next();
907 anAnnot.start = firstNode;
908 addToStartOffsetIndex(anAnnot);
909 }
910 annIter = endingAnnotations.iterator();
911 while (annIter.hasNext()) {
912 AnnotationImpl anAnnot = (AnnotationImpl) annIter.next();
913 anAnnot.end = firstNode;
914 addToEndOffsetIndex(anAnnot);
915 }
916 nodesByOffset.remove(firstNode.getOffset());
919 firstNode.setOffset(start);
921 nodesByOffset.put(firstNode.getOffset(), firstNode);
923 }
924 }
925
926 boolean shouldPrepend = Gate.getUserConfig().
929 getBoolean(GateConstants.DOCEDIT_INSERT_PREPEND).booleanValue();
930
931 long s = start.longValue(), e = end.longValue();
932 long rlen = ( (replacement == null) ? 0 : replacement.size().longValue());
934
935 List nodesAfterReplacement = new ArrayList(
937 nodesByOffset.tailMap(start).values());
938
939 Iterator nodesAfterReplacementIter = nodesAfterReplacement.iterator();
941 while (nodesAfterReplacementIter.hasNext()) {
942 NodeImpl n = (NodeImpl) nodesAfterReplacementIter.next();
943 nodesByOffset.remove(n.getOffset());
944 }
945 nodesAfterReplacementIter = nodesAfterReplacement.iterator();
947 while (nodesAfterReplacementIter.hasNext()) {
948 NodeImpl n = (NodeImpl) nodesAfterReplacementIter.next();
949 long oldOffset = n.getOffset().longValue();
950 long newOffset = oldOffset - (e - s) + rlen;
952 if (oldOffset == s){
954 if(newOffset < s) newOffset = s;
956 if(shouldPrepend) newOffset = s;
958 }
959 n.setOffset(new Long(newOffset));
960 }
961 nodesAfterReplacementIter = nodesAfterReplacement.iterator();
963 while (nodesAfterReplacementIter.hasNext()) {
964 NodeImpl n = (NodeImpl) nodesAfterReplacementIter.next();
965 nodesByOffset.put(n.getOffset(), n);
966 }
967
968 }
976
977 public String getName() {
978 return name;
979 }
980
981
982 public Document getDocument() {
983 return doc;
984 }
985
986
989 public Set getAllTypes() {
990 indexByType();
991 return annotsByType.keySet();
992 }
993
994
999 public Object clone() throws CloneNotSupportedException {
1000 return super.clone();
1001 }
1002
1003
1007 public synchronized void removeAnnotationSetListener(AnnotationSetListener l) {
1008 if (annotationSetListeners != null && annotationSetListeners.contains(l)) {
1009 Vector v = (Vector) annotationSetListeners.clone();
1010 v.removeElement(l);
1011 annotationSetListeners = v;
1012 }
1013 }
1014
1015
1019 public synchronized void addAnnotationSetListener(AnnotationSetListener l) {
1020 Vector v = annotationSetListeners == null ? new Vector(2) :
1021 (Vector) annotationSetListeners.clone();
1022 if (!v.contains(l)) {
1023 v.addElement(l);
1024 annotationSetListeners = v;
1025 }
1026 }
1027
1028
1029
1053
1067 String name = null;
1068
1069 DocumentImpl doc;
1070
1071 protected HashMap annotsById;
1072
1073 Map annotsByType = null;
1074
1075 RBTreeMap nodesByOffset = null;
1076
1079 Map annotsByStartNode;
1080
1083 Map annotsByEndNode;
1084 protected transient Vector annotationSetListeners;
1085 private transient Vector gateListeners;
1086
1090 protected void fireAnnotationAdded(AnnotationSetEvent e) {
1091 if (annotationSetListeners != null) {
1092 Vector listeners = annotationSetListeners;
1093 int count = listeners.size();
1094 for (int i = 0; i < count; i++) {
1095 ( (AnnotationSetListener) listeners.elementAt(i)).annotationAdded(e);
1096 }
1097 }
1098 }
1099
1100
1104 protected void fireAnnotationRemoved(AnnotationSetEvent e) {
1105 if (annotationSetListeners != null) {
1106 Vector listeners = annotationSetListeners;
1107 int count = listeners.size();
1108 for (int i = 0; i < count; i++) {
1109 ( (AnnotationSetListener) listeners.elementAt(i)).annotationRemoved(e);
1110 }
1111 }
1112 }
1113
1114
1118 public synchronized void removeGateListener(GateListener l) {
1119 if (gateListeners != null && gateListeners.contains(l)) {
1120 Vector v = (Vector) gateListeners.clone();
1121 v.removeElement(l);
1122 gateListeners = v;
1123 }
1124 }
1125
1126
1130 public synchronized void addGateListener(GateListener l) {
1131 Vector v = gateListeners == null ? new Vector(2) :
1132 (Vector) gateListeners.clone();
1133 if (!v.contains(l)) {
1134 v.addElement(l);
1135 gateListeners = v;
1136 }
1137 }
1138
1139
1143 protected void fireGateEvent(GateEvent e) {
1144 if (gateListeners != null) {
1145 Vector listeners = gateListeners;
1146 int count = listeners.size();
1147 for (int i = 0; i < count; i++) {
1148 ( (GateListener) listeners.elementAt(i)).processGateEvent(e);
1149 }
1150 }
1151 }
1152
1153
1154 static final long serialVersionUID = 1479426765310434166L;
1155}