b86dea6800aa70b4ebc46a3b7a8c3ca8d2d44687
[phpeclipse.git] /
1 /*
2  * Copyright (c) 2002-2004 Widespace, OU and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     Igor Malinin - initial contribution
10  *
11  * $Id: XMLAnnotationIterator.java,v 1.2 2006-10-21 23:14:13 pombredanne Exp $
12  */
13 package net.sourceforge.phpeclipse.xml.ui.internal.text;
14
15 import java.util.Iterator;
16
17 import org.eclipse.jface.text.source.Annotation;
18 import org.eclipse.jface.text.source.IAnnotationModel;
19
20 /**
21  * @author Igor Malinin
22  */
23 public class XMLAnnotationIterator implements Iterator {
24         private boolean skipIrrelevants;
25
26         private Iterator iterator;
27
28         private Annotation next;
29
30         public XMLAnnotationIterator(IAnnotationModel model, boolean skipIrrelevants) {
31                 this.skipIrrelevants = skipIrrelevants;
32
33                 iterator = model.getAnnotationIterator();
34                 skip();
35         }
36
37         private void skip() {
38                 while (iterator.hasNext()) {
39                         Annotation next = (Annotation) iterator.next();
40                         if (next instanceof XMLAnnotation) {
41                                 if (skipIrrelevants) {
42                                         if (!next.isMarkedDeleted()) {
43                                                 this.next = next;
44                                                 return;
45                                         }
46                                 } else {
47                                         this.next = next;
48                                         return;
49                                 }
50                         }
51                 }
52
53                 this.next = null;
54         }
55
56         /*
57          * @see java.util.Iterator#hasNext()
58          */
59         public boolean hasNext() {
60                 return (next != null);
61         }
62
63         /*
64          * @see java.util.Iterator#next()
65          */
66         public Object next() {
67                 try {
68                         return next;
69                 } finally {
70                         skip();
71                 }
72         }
73
74         /*
75          * @see java.util.Iterator#remove()
76          */
77         public void remove() {
78                 throw new UnsupportedOperationException();
79         }
80 }