|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.core.internal.watson.ElementTree
public class ElementTree
An ElementTree can be viewed as a generic rooted tree that stores a hierarchy of elements. An element in the tree consists of a (name, data, children) 3-tuple. The name can be any String, and the data can be any Object. The children are a collection of zero or more elements that logically fall below their parent in the tree. The implementation makes no guarantees about the ordering of children. Elements in the tree are referenced by a key that consists of the names of all elements on the path from the root to that element in the tree. For example, if root node "a" has child "b", which has child "c", element "c" can be referenced in the tree using the key (/a/b/c). Keys are represented using IPath objects, where the Paths are relative to the root element of the tree.
Each ElementTree has a single root element that is created implicitly and
is always present in any tree. This root corresponds to the key (/),
or the singleton Path.ROOT
. The root element cannot be created
or deleted, and its data and name cannot be set. The root element's children
however can be modified (added, deleted, etc). The root path can be obtained
using the getRoot()
method.
ElementTrees are modified in generations. The method newEmptyDelta()
returns a new tree generation that can be modified arbitrarily by the user.
For the purpose of explanation, we call such a tree "active".
When the method immutable()
is called, that tree generation is
frozen, and can never again be modified. A tree must be immutable before
a new tree generation can start. Since all ancestor trees are immutable,
different active trees can have ancestors in common without fear of
thread corruption problems.
Internally, any single tree generation is simply stored as the
set of changes between itself and its most recent ancestor (its parent).
This compact delta representation allows chains of element trees to
be created at relatively low cost. Clients of the ElementTree can
instantaneously "undo" sets of changes by navigating up to the parent
tree using the getParent()
method.
Although the delta representation is compact, extremely long delta
chains make for a large structure that is potentially slow to query.
For this reason, the client is encouraged to minimize delta chain
lengths using the collapsing(int)
and makeComplete()
methods. The getDeltaDepth()
method can be used to
discover the length of the delta chain. The entire delta chain can
also be re-oriented in terms of the current element tree using the
reroot()
operation.
Classes are also available for tree serialization and navigation.
,
ElementTreeReader
,
ElementTreeWriter
,
Finally, why are ElementTrees in a package called "watson"?
- "It's ElementTree my dear Watson, ElementTree."
Constructor Summary | |
---|---|
ElementTree()
Creates a new empty element tree. |
Method Summary | |
---|---|
ElementTree |
collapseTo(ElementTree parent)
Collapses this tree so that the given ancestor becomes its immediate parent. |
void |
createElement(org.eclipse.core.runtime.IPath key,
java.lang.Object data)
Creates the indicated element and sets its element info. |
void |
createSubtree(org.eclipse.core.runtime.IPath key,
ElementTree subtree)
Creates or replaces the subtree below the given path with the given tree. |
void |
deleteElement(org.eclipse.core.runtime.IPath key)
Deletes the indicated element and its descendents. |
static int |
findOldest(ElementTree[] trees)
Given an array of element trees, returns the index of the oldest tree. |
int |
getChildCount(org.eclipse.core.runtime.IPath key)
Returns the number of children of the element specified by the given path. |
org.eclipse.core.runtime.IPath[] |
getChildren(org.eclipse.core.runtime.IPath key)
Returns the paths of the children of the element specified by the given path. |
DeltaDataTree |
getDataTree()
Returns the internal data tree. |
java.lang.Object |
getElementData(org.eclipse.core.runtime.IPath key)
Returns the element data for the given element identifier. |
java.lang.Object |
getElementDataIgnoreCase(org.eclipse.core.runtime.IPath key)
Returns the element data for the given element identifier. |
java.lang.String[] |
getNamesOfChildren(org.eclipse.core.runtime.IPath key)
Returns the names of the children of the specified element. |
ElementTree |
getParent()
Returns the parent tree, or null if there is no parent. |
org.eclipse.core.runtime.IPath |
getRoot()
Returns the root node of this tree. |
ElementTree |
getSubtree(org.eclipse.core.runtime.IPath key)
Returns the subtree rooted at the given key. |
IElementTreeData |
getTreeData()
Returns the user data associated with this tree. |
static boolean |
hasChanges(ElementTree newLayer,
ElementTree oldLayer,
IElementComparator comparator,
boolean inclusive)
Returns true if there have been changes in the tree between the two given layers. |
void |
immutable()
Makes this tree immutable (read-only); ignored if it is already immutable. |
boolean |
includes(org.eclipse.core.runtime.IPath key)
Returns true if this element tree includes an element with the given key, false otherwise. |
boolean |
includesIgnoreCase(org.eclipse.core.runtime.IPath key)
Returns true if this element tree includes an element with the given key, ignoring the case of the key, and false otherwise. |
boolean |
isImmutable()
Returns whether this tree is immutable. |
ElementTree |
mergeDeltaChain(org.eclipse.core.runtime.IPath path,
ElementTree[] trees)
Merges a chain of deltas for a certain subtree to this tree. |
ElementTree |
newEmptyDelta()
Creates a new element tree which is represented as a delta on this one. |
java.lang.Object |
openElementData(org.eclipse.core.runtime.IPath key)
Returns a mutable copy of the element data for the given path. |
void |
setElementData(org.eclipse.core.runtime.IPath key,
java.lang.Object data)
Sets the element for the given element identifier. |
void |
setTreeData(IElementTreeData data)
Sets the user data associated with this tree. |
void |
shareStrings(StringPool set)
|
java.lang.String |
toDebugString()
Returns a string representation of this element tree's structure suitable for debug purposes. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ElementTree()
Method Detail |
---|
public ElementTree collapseTo(ElementTree parent)
This operation should be used to collapse chains of element trees created by newEmptyDelta()/immutable().
This element tree must be immutable at the start of this operation, and will be immutable afterwards.
public void createElement(org.eclipse.core.runtime.IPath key, java.lang.Object data)
key
- element keydata
- element data, or null
public void createSubtree(org.eclipse.core.runtime.IPath key, ElementTree subtree)
key
- The path of the new subtree in this tree.getSubtree(IPath)
public void deleteElement(org.eclipse.core.runtime.IPath key)
public static int findOldest(ElementTree[] trees)
public int getChildCount(org.eclipse.core.runtime.IPath key)
public org.eclipse.core.runtime.IPath[] getChildren(org.eclipse.core.runtime.IPath key)
public DeltaDataTree getDataTree()
public java.lang.Object getElementData(org.eclipse.core.runtime.IPath key)
public java.lang.Object getElementDataIgnoreCase(org.eclipse.core.runtime.IPath key)
public java.lang.String[] getNamesOfChildren(org.eclipse.core.runtime.IPath key)
public ElementTree getParent()
null
if there is no parent.
public org.eclipse.core.runtime.IPath getRoot()
public ElementTree getSubtree(org.eclipse.core.runtime.IPath key)
createSubtree(IPath, ElementTree)
public IElementTreeData getTreeData()
public static boolean hasChanges(ElementTree newLayer, ElementTree oldLayer, IElementComparator comparator, boolean inclusive)
public void immutable()
public boolean includes(org.eclipse.core.runtime.IPath key)
public boolean includesIgnoreCase(org.eclipse.core.runtime.IPath key)
public boolean isImmutable()
public ElementTree mergeDeltaChain(org.eclipse.core.runtime.IPath path, ElementTree[] trees)
path
- The path of the subtree chain to mergetrees
- The chain of trees to merge. The trees can be
in any order, but they must all form a simple ancestral chain.
public ElementTree newEmptyDelta()
public java.lang.Object openElementData(org.eclipse.core.runtime.IPath key)
public void setElementData(org.eclipse.core.runtime.IPath key, java.lang.Object data)
key
- element identifierdata
- element info, or null
public void setTreeData(IElementTreeData data)
public void shareStrings(StringPool set)
public java.lang.String toDebugString()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |