KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > source > projection > AnnotationBag


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.text.source.projection;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.eclipse.jface.text.source.Annotation;
18
19 /**
20  * A bag of annotations.
21  * <p>
22  * This class is not intended to be subclassed.
23  * </p>
24  *
25  * @since 3.0
26  */

27 public class AnnotationBag extends Annotation {
28
29     private Set JavaDoc fAnnotations;
30
31     /**
32      * Creates a new annotation bag.
33      *
34      * @param type the annotation type
35      */

36     public AnnotationBag(String JavaDoc type) {
37         super(type, false, null);
38     }
39
40     /**
41      * Adds the given annotation to the annotation bag.
42      *
43      * @param annotation the annotation to add
44      */

45     public void add(Annotation annotation) {
46         if (fAnnotations == null)
47             fAnnotations= new HashSet JavaDoc(2);
48         fAnnotations.add(annotation);
49     }
50
51     /**
52      * Removes the given annotation from the annotation bag.
53      *
54      * @param annotation the annotation to remove
55      */

56     public void remove(Annotation annotation) {
57         if (fAnnotations != null) {
58             fAnnotations.remove(annotation);
59             if (fAnnotations.isEmpty())
60                 fAnnotations= null;
61         }
62     }
63
64     /**
65      * Returns whether the annotation bag is empty.
66      *
67      * @return <code>true</code> if the annotation bag is empty, <code>false</code> otherwise
68      */

69     public boolean isEmpty() {
70         return fAnnotations == null;
71     }
72
73     /**
74      * Returns an iterator for all annotation inside this
75      * annotation bag or <code>null</code> if the bag is empty.
76      *
77      * @return an iterator for all annotations in the bag or <code>null</code>
78      * @since 3.1
79      */

80     public Iterator JavaDoc iterator() {
81         if (!isEmpty())
82             return fAnnotations.iterator();
83         return null;
84     }
85 }
86
Popular Tags