Skip to main content
summaryrefslogtreecommitdiffstats
blob: bc1a5ac18530b16963e142e338a1478cfd40a78c (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
package org.eclipse.swt.examples.launcher;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved
 */

/**
 * Internal class used to store tree structures of ItemDescriptors
 */
class ItemTreeNode {
	private ItemTreeNode nextSibling;
	private ItemTreeNode firstChild;
	private ItemDescriptor descriptor;

	/**
	 * Constructs a leaf ItemTreeNode with a given descriptor.
	 * 
	 * @param descriptor the descriptor
	 */
	public ItemTreeNode(ItemDescriptor descriptor) {
		this.descriptor = descriptor;
	}

	/**
	 * Adds a node to the Tree in sorted order by name.
	 * 
	 * @param node the node to add. Note that node.nextSibling must be null
	 */
	public void addSortedNode(ItemTreeNode node) {
		if (firstChild == null) {
			firstChild = node;
		} else if (firstChild.descriptor.getName().compareTo(node.descriptor.getName()) > 0) {
			node.nextSibling = firstChild;
			firstChild = node;
		} else {
			ItemTreeNode cursor;
			for (cursor = firstChild; cursor.nextSibling != null; cursor = cursor.nextSibling) {
				ItemTreeNode sibling = cursor.nextSibling;
				if (sibling.descriptor.getName().compareTo(node.descriptor.getName()) > 0) break;
			}
			node.nextSibling = cursor.nextSibling;
			cursor.nextSibling = node;
		}
	}
	
	/**
	 * Returns the descriptor for this node.
	 * 
	 * @return the descriptor
	 */
	public ItemDescriptor getDescriptor() {
		return descriptor;
	}

	/**
	 * Returns the next sibling of this node.
	 * 
	 * @return the next sibling, or null if none
	 */
	public ItemTreeNode getNextSibling() {
		return nextSibling;
	}

	/**
	 * Returns the first child of this node.
	 * 
	 * @return the first child, or null if none
	 */
	public ItemTreeNode getFirstChild() {
		return firstChild;
	}
}

Back to the top