Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e8b6281c46d95e5971acc057f78ff7eb9ebab939 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (c) 2002 IBM Corporation and others.
* All rights reserved.   This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
* 
* Contributors:
*   IBM - Initial API and implementation
*   Jens Lukowski/Innoopract - initial renaming/restructuring
* 
*/
package org.eclipse.wst.sse.core.internal.text;



import java.util.Enumeration;
import java.util.NoSuchElementException;

import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.util.Debug;


public class StructuredDocumentRegionEnumeration implements Enumeration {

	private int count;
	private IStructuredDocumentRegion head;
	private IStructuredDocumentRegion oldHead;

	/**
	 * StructuredDocumentRegionEnumeration constructor comment.
	 */
	public StructuredDocumentRegionEnumeration(IStructuredDocumentRegion newHead) {
		super();
		IStructuredDocumentRegion countNode = head = newHead;
		while (countNode != null) {
			count++;
			countNode = countNode.getNext();
		}
		if (Debug.DEBUG > 5) {
			System.out.println("N Nodes in StructuredDocumentRegionEnumeration Contructor: " + count); //$NON-NLS-1$
		}
	}

	/**
	 * StructuredDocumentRegionEnumeration constructor comment.
	 */
	public StructuredDocumentRegionEnumeration(IStructuredDocumentRegion start, IStructuredDocumentRegion end) {
		super();
		IStructuredDocumentRegion countNode = head = start;
		if ((start == null) || (end == null)) {
			// error condition
			count = 0;
			return;
		}
		//If both nodes are non-null, we assume there is always at least one item
		count = 1;
		while (countNode != end) {
			count++;
			countNode = countNode.getNext();
		}
		if (org.eclipse.wst.sse.core.util.Debug.DEBUG > 5) {
			System.out.println("N Nodes in StructuredDocumentRegionEnumeration Contructor: " + count); //$NON-NLS-1$
		}
	}

	/**
	 * hasMoreElements method comment.
	 */
	public synchronized boolean hasMoreElements() {
		return count > 0;
	}

	/**
	 * nextElement method comment.
	 */
	public synchronized Object nextElement() {
		if (count > 0) {
			count--;
			oldHead = head;
			head = head.getNext();
			return oldHead;
		}
		throw new NoSuchElementException("StructuredDocumentRegionEnumeration"); //$NON-NLS-1$
	}
}

Back to the top