KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > dtree > NodeInfo


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.dtree;
12
13 /**
14  * <code>NodeInfo</code> objects are placeholders for information about a node.
15  * They provide a mechanism for comparing arbitrary data trees and for
16  * remembering a snapshot of what a node looked like.
17  *
18  */

19 public class NodeInfo {
20
21     private int type;
22     private Object JavaDoc data;
23     private String JavaDoc namesOfChildren[], namesOfDeletedChildren[];
24
25     /**
26      * Creates a new NodeInfo object
27      *
28      * @param type type of node
29      * @param data node's data
30      * @param children array of child names
31      * @param deleted array of deleted child names
32      */

33     public NodeInfo(int type, Object JavaDoc data, String JavaDoc[] children, String JavaDoc[] deleted) {
34         this.type = type;
35         this.data = data;
36         this.namesOfChildren = children;
37         this.namesOfDeletedChildren = deleted;
38     }
39
40     /**
41      * Get node's data
42      */

43     public Object JavaDoc getData() {
44         return data;
45     }
46
47     /**
48      * Returns an array of names of children of the node
49      */

50     public String JavaDoc[] getNamesOfChildren() {
51         return namesOfChildren;
52     }
53
54     /**
55      * Returns an array of names of deleted children of the node
56      */

57     public String JavaDoc[] getNamesOfDeletedChildren() {
58         return namesOfDeletedChildren;
59     }
60
61     public int getType() {
62         return type;
63     }
64
65     /**
66      * Returns true if the type of node carries data, false otherwise.
67      */

68     public boolean hasData() {
69         return (type == AbstractDataTreeNode.T_COMPLETE_NODE || type == AbstractDataTreeNode.T_DELTA_NODE);
70     }
71
72     /**
73      * Returns true if the receiver represents a complete node.
74      */

75     public boolean isComplete() {
76         return this.getType() == AbstractDataTreeNode.T_COMPLETE_NODE;
77     }
78
79     /**
80      * Returns true if the receiver represents a node that has been
81      * deleted from the tree, false otherwise.
82      */

83     public boolean isDeleted() {
84         return this.getType() == AbstractDataTreeNode.T_DELETED_NODE;
85     }
86
87     /**
88      * Returns true if the node carries delta information, false otherwise.
89      */

90     public boolean isDelta() {
91         int type = this.getType();
92         return (type == AbstractDataTreeNode.T_DELTA_NODE || type == AbstractDataTreeNode.T_NO_DATA_DELTA_NODE);
93     }
94
95     /**
96      * Returns whether the node represents an empty delta.
97      * The node represents an empty delta if has no data and no children.
98      */

99     public boolean isEmptyDelta() {
100         return (this.getType() == AbstractDataTreeNode.T_NO_DATA_DELTA_NODE && this.getNamesOfChildren().length == 0 && this.getNamesOfDeletedChildren().length == 0);
101     }
102
103     /**
104      * Returns true if the node is present in the tree, whether it
105      * be a complete node, delta node, deleted node or virtual node.
106      */

107     public boolean isPresent() {
108         return this.getType() != AbstractDataTreeNode.T_MISSING_NODE;
109     }
110
111     /**
112      * Returns a node info object describing a missing or deleted node.
113      */

114     static NodeInfo missing() {
115         return new NodeInfo(AbstractDataTreeNode.T_MISSING_NODE, null, //no data
116
new String JavaDoc[0], //no children
117
new String JavaDoc[0]); //no deleted children
118
}
119
120     public void setData(Object JavaDoc o) {
121         data = o;
122     }
123
124     public void setNamesOfChildren(String JavaDoc names[]) {
125         namesOfChildren = names;
126     }
127
128     public void setNamesOfDeletedChildren(String JavaDoc names[]) {
129         namesOfDeletedChildren = names;
130     }
131
132     public void setType(int type) {
133         this.type = type;
134     }
135 }
Popular Tags