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 annotsIter;
483 Node currentNode;
484 Annotation currentAnnot;
485 currentNode = (Node) nodesByOffset.get(startOffset);
487 if (currentNode != null) {
488 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
489 if (fromPoint != null) {
490 annotsIter = fromPoint.iterator();
491 while (annotsIter.hasNext()) {
492 currentAnnot = (Annotation) annotsIter.next();
493 if (currentAnnot.getEndNode().getOffset().compareTo(endOffset) == 0) {
494 resultSet.add(currentAnnot);
495 } } } } return resultSet;
500 }
502
512 public AnnotationSet get(String neededType, Long startOffset, Long endOffset) {
513 if (annotsByStartNode == null)
518 indexByStartOffset();
519 AnnotationSet resultSet = new AnnotationSetImpl(doc);
520 Iterator nodesIter;
521 Iterator annotsIter;
522 Node currentNode;
523 Annotation currentAnnot;
524 nodesIter = nodesByOffset.headMap(startOffset).values().iterator();
527 while (nodesIter.hasNext()) {
528 currentNode = (Node) nodesIter.next();
529 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
530 if (fromPoint != null) {
531 annotsIter = (fromPoint).iterator();
532 while (annotsIter.hasNext()) {
533 currentAnnot = (Annotation) annotsIter.next();
534 if (currentAnnot.getType().equals(neededType) &&
535 currentAnnot.getEndNode().getOffset().compareTo(startOffset) > 0
536 ) {
537 resultSet.add(currentAnnot);
538 } } }
541 }
542 nodesIter = nodesByOffset.subMap(startOffset, endOffset).values().iterator();
545 while (nodesIter.hasNext()) {
546 currentNode = (Node) nodesIter.next();
547 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
548 if (fromPoint != null) {
549 annotsIter = (fromPoint).iterator();
550 while (annotsIter.hasNext()) {
551 currentAnnot = (Annotation) annotsIter.next();
552 if (currentAnnot.getType().equals(neededType)) {
553 resultSet.add(currentAnnot);
554 } } } }
558 return resultSet;
559 }
561
562 public AnnotationSet get(String type, FeatureMap constraints, Long offset) {
563 AnnotationSet nextAnnots = (AnnotationSet) get(offset);
565 if (nextAnnots == null)
566 return null;
567 return nextAnnots.get(type, constraints);
569 }
571
575 public AnnotationSet getContained(Long startOffset, Long endOffset) {
576 if (annotsByStartNode == null)
579 indexByStartOffset();
580 AnnotationSet resultSet = new AnnotationSetImpl(doc);
581 Iterator nodesIter;
582 Node currentNode;
583 nodesIter = nodesByOffset.subMap(startOffset, endOffset).values().iterator();
586 while (nodesIter.hasNext()) {
587 currentNode = (Node) nodesIter.next();
588 Set fromPoint = (Set) annotsByStartNode.get(currentNode.getId());
589 if (fromPoint == null)
590 continue;
591 Iterator annotIter = fromPoint.iterator();
594 while (annotIter.hasNext()) {
595 Annotation annot = (Annotation) annotIter.next();
596 if (annot.getEndNode().getOffset().compareTo(endOffset) <= 0)
597 resultSet.add(annot);
598 }
599 }
600 return resultSet;
601 }
603
604 public Node firstNode() {
605 indexByStartOffset();
606 if (nodesByOffset.isEmpty())
607 return null;
608 else
609 return (Node) nodesByOffset.get(nodesByOffset.firstKey());
610 }
612
613 public Node lastNode() {
614 indexByStartOffset();
615 indexByEndOffset();
616 if (nodesByOffset.isEmpty())
617 return null;
618 else
619 return (Node) nodesByOffset.get(nodesByOffset.lastKey());
620 }
622
626 public Node nextNode(Node node) {
627 indexByStartOffset();
628 indexByEndOffset();
629 return (Node) nodesByOffset.getNextOf(
630 new Long(node.getOffset().longValue() + 1)
631 );
632 }
633
634 protected static AnnotationFactory annFactory;
635
636
640 public static void setAnnotationFactory (AnnotationFactory newFactory) {
641 annFactory = newFactory;
642 }
643
644 static {
645 setAnnotationFactory(new DefaultAnnotationFactory());
647 }
648
649
652 public Integer add(Node start, Node end, String type, FeatureMap features) {
653 Integer id = doc.getNextAnnotationId();
655 annFactory.createAnnotationInSet(this, id, start, end, type, features);
657 return id;
658 }
660
661 public boolean add(Object o) throws ClassCastException {
662 Annotation a = (Annotation) o;
663 Object oldValue = annotsById.put(a.getId(), a);
664 if (annotsByType != null)
665 addToTypeIndex(a);
666 if (annotsByStartNode != null || annotsByEndNode != null)
667 addToOffsetIndex(a);
668 AnnotationSetEvent evt = new AnnotationSetEvent(
669 this,
670 AnnotationSetEvent.ANNOTATION_ADDED,
671 doc, a);
672 fireAnnotationAdded(evt);
673 fireGateEvent(evt);
674 return oldValue != a;
675 }
677
690 public boolean addAll(Collection c) {
691 Iterator annIter = c.iterator();
692 boolean changed = false;
693 while (annIter.hasNext()) {
694 Annotation a = (Annotation) annIter.next();
695 try {
696 add(a.getStartNode().getOffset(),
697 a.getEndNode().getOffset(),
698 a.getType(),
699 a.getFeatures());
700 changed = true;
701 }
702 catch (InvalidOffsetException ioe) {
703 throw new IllegalArgumentException(ioe.toString());
704 }
705 }
706 return changed;
707 }
708
709
722 protected boolean addAllKeepIDs(Collection c) {
723 Iterator annIter = c.iterator();
724 boolean changed = false;
725 while (annIter.hasNext()) {
726 Annotation a = (Annotation) annIter.next();
727 changed |= add(a);
728 }
729 return changed;
730 }
731
732
733 public Integer add(
734 Long start, Long end, String type, FeatureMap features
735 ) throws InvalidOffsetException {
736 if (!doc.isValidOffsetRange(start, end))
738 throw new InvalidOffsetException();
739 if (nodesByOffset == null) {
742 indexByStartOffset();
743 indexByEndOffset();
744 }
745 Node startNode = (Node) nodesByOffset.getNextOf(start);
747 if (startNode == null || !startNode.getOffset().equals(start))
748 startNode = new NodeImpl(doc.getNextNodeId(), start);
749 Node endNode = null;
750 if (start.equals(end))
751 endNode = startNode;
752 else
753 endNode = (Node) nodesByOffset.getNextOf(end);
754 if (endNode == null || !endNode.getOffset().equals(end))
755 endNode = new NodeImpl(doc.getNextNodeId(), end);
756 return add(startNode, endNode, type, features);
758 }
760
764 public void add(
765 Integer id, Long start, Long end, String type, FeatureMap features
766 ) throws InvalidOffsetException {
767 if (!doc.isValidOffsetRange(start, end))
769 throw new InvalidOffsetException();
770 if (nodesByOffset == null) {
773 indexByStartOffset();
774 indexByEndOffset();
775 }
776 Node startNode = (Node) nodesByOffset.getNextOf(start);
778 if (startNode == null || !startNode.getOffset().equals(start))
779 startNode = new NodeImpl(doc.getNextNodeId(), start);
780 Node endNode = null;
781 if (start.equals(end))
782 endNode = startNode;
783 else
784 endNode = (Node) nodesByOffset.getNextOf(end);
785 if (endNode == null || !endNode.getOffset().equals(end))
786 endNode = new NodeImpl(doc.getNextNodeId(), end);
787 annFactory.createAnnotationInSet(this, id, startNode, endNode, type, features);
789 }
791
792 protected void indexByType() {
793 if (annotsByType != null)
794 return;
795 annotsByType = new HashMap(Gate.HASH_STH_SIZE);
796 Iterator annotIter = annotsById.values().iterator();
797 while (annotIter.hasNext())
798 addToTypeIndex( (Annotation) annotIter.next());
799 }
801
802 protected void indexByStartOffset() {
803 if (annotsByStartNode != null) return;
804 if (nodesByOffset == null) nodesByOffset = new RBTreeMap();
805 annotsByStartNode = new HashMap(Gate.HASH_STH_SIZE);
806 Iterator annotIter = annotsById.values().iterator();
807 while (annotIter.hasNext())
808 addToStartOffsetIndex( (Annotation) annotIter.next());
809 }
811
812 protected void indexByEndOffset() {
813 if (annotsByEndNode != null)
814 return;
815 if (nodesByOffset == null)
816 nodesByOffset = new RBTreeMap();
817 annotsByEndNode = new HashMap(Gate.HASH_STH_SIZE);
818 Iterator annotIter = annotsById.values().iterator();
819 while (annotIter.hasNext())
820 addToEndOffsetIndex( (Annotation) annotIter.next());
821 }
823
826 void addToTypeIndex(Annotation a) {
827 if (annotsByType == null)
828 return;
829 String type = a.getType();
830 AnnotationSet sameType = (AnnotationSet) annotsByType.get(type);
831 if (sameType == null) {
832 sameType = new AnnotationSetImpl(doc);
833 annotsByType.put(type, sameType);
834 }
835 sameType.add(a);
836 }
838
841 void addToOffsetIndex(Annotation a) {
842 addToStartOffsetIndex(a);
843 addToEndOffsetIndex(a);
844 }
846
849 void addToStartOffsetIndex(Annotation a) {
850 Node startNode = a.getStartNode();
851 Long start = startNode.getOffset();
852 if (nodesByOffset != null)
854 nodesByOffset.put(start, startNode);
855 if (annotsByStartNode == null)
857 return;
858 AnnotationSet thisNodeAnnots =
860 (AnnotationSet) annotsByStartNode.get(startNode.getId());
861 if (thisNodeAnnots == null) {
862 thisNodeAnnots = new AnnotationSetImpl(doc);
863 annotsByStartNode.put(startNode.getId(), thisNodeAnnots);
864 }
865 thisNodeAnnots.add(a);
867 }
869
872 void addToEndOffsetIndex(Annotation a) {
873 Node endNode = a.getEndNode();
874 Long end = endNode.getOffset();
875 if (nodesByOffset != null)
877 nodesByOffset.put(end, endNode);
878 if (annotsByEndNode == null)
880 return;
881 AnnotationSet thisNodeAnnots =
883 (AnnotationSet) annotsByEndNode.get(endNode.getId());
884 if (thisNodeAnnots == null) {
885 thisNodeAnnots = new AnnotationSetImpl(doc);
886 annotsByEndNode.put(endNode.getId(), thisNodeAnnots);
887 }
888 thisNodeAnnots.add(a);
890 }
892
898 public void edit(Long start, Long end, DocumentContent replacement) {
899 indexByStartOffset();
901 indexByEndOffset();
902 if(end.compareTo(start) > 0){
903 List affectedNodes = new ArrayList(nodesByOffset.subMap(start,
906 new Long(end.longValue() + 1)).values());
907 NodeImpl firstNode = null;
910 if (!affectedNodes.isEmpty()) {
911 firstNode = (NodeImpl) affectedNodes.get(0);
912 List startingAnnotations = new ArrayList();
913 List endingAnnotations = new ArrayList();
914 for (int i = 1; i < affectedNodes.size(); i++) {
915 Node aNode = (Node) affectedNodes.get(i);
916 AnnotationSet annSet = (AnnotationSet) annotsByStartNode.get(aNode.
918 getId());
919 if (annSet != null)
920 startingAnnotations.addAll(annSet);
921 annSet = (AnnotationSet) annotsByEndNode.get(aNode.getId());
922 if (annSet != null)
923 endingAnnotations.addAll(annSet);
924 nodesByOffset.remove(aNode.getOffset());
926 annotsByStartNode.remove(aNode);
927 annotsByEndNode.remove(aNode);
928 }
929 Iterator annIter = startingAnnotations.iterator();
931 while (annIter.hasNext()) {
932 AnnotationImpl anAnnot = (AnnotationImpl) annIter.next();
933 anAnnot.start = firstNode;
934 addToStartOffsetIndex(anAnnot);
935 }
936 annIter = endingAnnotations.iterator();
937 while (annIter.hasNext()) {
938 AnnotationImpl anAnnot = (AnnotationImpl) annIter.next();
939 anAnnot.end = firstNode;
940 addToEndOffsetIndex(anAnnot);
941 }
942 nodesByOffset.remove(firstNode.getOffset());
945 firstNode.setOffset(start);
947 nodesByOffset.put(firstNode.getOffset(), firstNode);
949 }
950 }
951
952 boolean shouldPrepend = Gate.getUserConfig().
955 getBoolean(GateConstants.DOCEDIT_INSERT_PREPEND).booleanValue();
956
957 long s = start.longValue(), e = end.longValue();
958 long rlen = ( (replacement == null) ? 0 : replacement.size().longValue());
960
961 List nodesAfterReplacement = new ArrayList(
963 nodesByOffset.tailMap(start).values());
964
965 Iterator nodesAfterReplacementIter = nodesAfterReplacement.iterator();
967 while (nodesAfterReplacementIter.hasNext()) {
968 NodeImpl n = (NodeImpl) nodesAfterReplacementIter.next();
969 nodesByOffset.remove(n.getOffset());
970 }
971 nodesAfterReplacementIter = nodesAfterReplacement.iterator();
973 while (nodesAfterReplacementIter.hasNext()) {
974 NodeImpl n = (NodeImpl) nodesAfterReplacementIter.next();
975 long oldOffset = n.getOffset().longValue();
976 long newOffset = oldOffset - (e - s) + rlen;
978 if (oldOffset == s){
980 if(newOffset < s) newOffset = s;
982 if(shouldPrepend) newOffset = s;
984 }
985 n.setOffset(new Long(newOffset));
986 }
987 nodesAfterReplacementIter = nodesAfterReplacement.iterator();
989 while (nodesAfterReplacementIter.hasNext()) {
990 NodeImpl n = (NodeImpl) nodesAfterReplacementIter.next();
991 nodesByOffset.put(n.getOffset(), n);
992 }
993
994 }
1002
1003 public String getName() {
1004 return name;
1005 }
1006
1007
1008 public Document getDocument() {
1009 return doc;
1010 }
1011
1012
1015 public Set getAllTypes() {
1016 indexByType();
1017 return annotsByType.keySet();
1018 }
1019
1020
1025 public Object clone() throws CloneNotSupportedException {
1026 return super.clone();
1027 }
1028
1029
1033 public synchronized void removeAnnotationSetListener(AnnotationSetListener l) {
1034 if (annotationSetListeners != null && annotationSetListeners.contains(l)) {
1035 Vector v = (Vector) annotationSetListeners.clone();
1036 v.removeElement(l);
1037 annotationSetListeners = v;
1038 }
1039 }
1040
1041
1045 public synchronized void addAnnotationSetListener(AnnotationSetListener l) {
1046 Vector v = annotationSetListeners == null ? new Vector(2) :
1047 (Vector) annotationSetListeners.clone();
1048 if (!v.contains(l)) {
1049 v.addElement(l);
1050 annotationSetListeners = v;
1051 }
1052 }
1053
1054
1055
1079
1093 String name = null;
1094
1095 DocumentImpl doc;
1096
1097 protected HashMap annotsById;
1098
1099 Map annotsByType = null;
1100
1101 RBTreeMap nodesByOffset = null;
1102
1105 Map annotsByStartNode;
1106
1109 Map annotsByEndNode;
1110 protected transient Vector annotationSetListeners;
1111 private transient Vector gateListeners;
1112
1116 protected void fireAnnotationAdded(AnnotationSetEvent e) {
1117 if (annotationSetListeners != null) {
1118 Vector listeners = annotationSetListeners;
1119 int count = listeners.size();
1120 for (int i = 0; i < count; i++) {
1121 ( (AnnotationSetListener) listeners.elementAt(i)).annotationAdded(e);
1122 }
1123 }
1124 }
1125
1126
1130 protected void fireAnnotationRemoved(AnnotationSetEvent e) {
1131 if (annotationSetListeners != null) {
1132 Vector listeners = annotationSetListeners;
1133 int count = listeners.size();
1134 for (int i = 0; i < count; i++) {
1135 ( (AnnotationSetListener) listeners.elementAt(i)).annotationRemoved(e);
1136 }
1137 }
1138 }
1139
1140
1144 public synchronized void removeGateListener(GateListener l) {
1145 if (gateListeners != null && gateListeners.contains(l)) {
1146 Vector v = (Vector) gateListeners.clone();
1147 v.removeElement(l);
1148 gateListeners = v;
1149 }
1150 }
1151
1152
1156 public synchronized void addGateListener(GateListener l) {
1157 Vector v = gateListeners == null ? new Vector(2) :
1158 (Vector) gateListeners.clone();
1159 if (!v.contains(l)) {
1160 v.addElement(l);
1161 gateListeners = v;
1162 }
1163 }
1164
1165
1169 protected void fireGateEvent(GateEvent e) {
1170 if (gateListeners != null) {
1171 Vector listeners = gateListeners;
1172 int count = listeners.size();
1173 for (int i = 0; i < count; i++) {
1174 ( (GateListener) listeners.elementAt(i)).processGateEvent(e);
1175 }
1176 }
1177 }
1178
1179
1180 static final long serialVersionUID = 1479426765310434166L;
1181}