129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2008 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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.source.projection.AnnotationBag;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import java.util.HashSet;
|
|
18 import java.util.Iterator;
|
|
19 import java.util.Set;
|
|
20
|
|
21 import dwtx.jface.text.source.Annotation;
|
|
22
|
|
23 /**
|
|
24 * A bag of annotations.
|
|
25 * <p>
|
|
26 * This class is not intended to be subclassed.
|
|
27 * </p>
|
|
28 *
|
|
29 * @since 3.0
|
|
30 * @noextend This class is not intended to be subclassed by clients.
|
|
31 */
|
|
32 public class AnnotationBag : Annotation {
|
|
33
|
|
34 private Set fAnnotations;
|
|
35
|
|
36 /**
|
|
37 * Creates a new annotation bag.
|
|
38 *
|
|
39 * @param type the annotation type
|
|
40 */
|
|
41 public AnnotationBag(String type) {
|
|
42 super(type, false, null);
|
|
43 }
|
|
44
|
|
45 /**
|
|
46 * Adds the given annotation to the annotation bag.
|
|
47 *
|
|
48 * @param annotation the annotation to add
|
|
49 */
|
|
50 public void add(Annotation annotation) {
|
|
51 if (fAnnotations is null)
|
|
52 fAnnotations= new HashSet(2);
|
|
53 fAnnotations.add(annotation);
|
|
54 }
|
|
55
|
|
56 /**
|
|
57 * Removes the given annotation from the annotation bag.
|
|
58 *
|
|
59 * @param annotation the annotation to remove
|
|
60 */
|
|
61 public void remove(Annotation annotation) {
|
|
62 if (fAnnotations !is null) {
|
|
63 fAnnotations.remove(annotation);
|
|
64 if (fAnnotations.isEmpty())
|
|
65 fAnnotations= null;
|
|
66 }
|
|
67 }
|
|
68
|
|
69 /**
|
|
70 * Returns whether the annotation bag is empty.
|
|
71 *
|
|
72 * @return <code>true</code> if the annotation bag is empty, <code>false</code> otherwise
|
|
73 */
|
|
74 public bool isEmpty() {
|
|
75 return fAnnotations is null;
|
|
76 }
|
|
77
|
|
78 /**
|
|
79 * Returns an iterator for all annotation inside this
|
|
80 * annotation bag or <code>null</code> if the bag is empty.
|
|
81 *
|
|
82 * @return an iterator for all annotations in the bag or <code>null</code>
|
|
83 * @since 3.1
|
|
84 */
|
|
85 public Iterator iterator() {
|
|
86 if (!isEmpty())
|
|
87 return fAnnotations.iterator();
|
|
88 return null;
|
|
89 }
|
|
90 }
|