com.microsoft.tfs.core.clients.versioncontrol.sparsetree
Class SparseTree<T>

java.lang.Object
  extended by com.microsoft.tfs.core.clients.versioncontrol.sparsetree.SparseTree<T>

public class SparseTree<T>
extends java.lang.Object


Nested Class Summary
static interface SparseTree.EnumNodeCallback<T>
          The EnumNodeCallback is used when enumerating the nodes in the store.
 class SparseTree.EnumSubTreeEnumerator
           
static interface SparseTree.ModifyInPlaceCallback<T>
          The ModifyInPlaceCallback is used when a caller wants to look up a node in the tree with a certain token and then change the referenced object for that token, with only a single lookup in the tree.
 
Constructor Summary
SparseTree(char tokenSeparator)
          Tokens have variable length segments that are separated by the set of characters given to the constructor.
SparseTree(char tokenSeparator, java.util.Comparator<java.lang.String> tokenComparison)
          Tokens have variable length segments that are separated by the set of characters given to the constructor.
SparseTree(char tokenSeparator, int fixedElementLength, java.util.Comparator<java.lang.String> tokenComparison)
           
SparseTree(java.util.Comparator<java.lang.String> tokenComparison)
          Tokens are assumed to contain fixed length segments (ie.
SparseTree(int fixedElementLength)
          Tokens have fixed length segments that are separated by the element length provided.
SparseTree(int fixedElementLength, java.util.Comparator<java.lang.String> tokenComparison)
          Tokens have fixed length segments that are separated by the length provided.
 
Method Summary
 void add(java.lang.String token, T referencedObject)
          This is used to add an object to the store at a specific path
 void add(java.lang.String token, T referencedObject, boolean overwrite)
          This is used to add an object to the store at a specific path
 void clear()
          Clears all of the tokens in the store.
 KeyValuePair<java.lang.String,T>[] EnumChildren(java.lang.String token)
          Given a token that is in the store, returns the children of that node in the SparseTree.
 java.lang.Iterable<EnumeratedSparseTreeNode<T>> EnumParents(java.lang.String token, EnumParentsOptions options)
          Queries the SparseTree for the parents of the provided token.
 boolean EnumParents(java.lang.String token, SparseTree.EnumNodeCallback<T> callback)
          Enumerates all parents of the specified token.
 boolean EnumParents(java.lang.String token, SparseTree.EnumNodeCallback<T> callback, EnumParentsOptions options, SparseTreeAdditionalData additionalData, java.lang.Object param)
          Enumerates all parents of the specified token.
 java.lang.Iterable<T> EnumParentsReferencedObjects(java.lang.String token, EnumParentsOptions options)
          Queries the SparseTree for the parents of the provided token.
 java.lang.Iterable<EnumeratedSparseTreeNode<T>> EnumRoots()
          This enumerates all the immediate children of the root node of the tree -- that is, all entries in the SparseTree which have no parent.
 java.lang.Iterable<T> EnumRootsReferencedObjects()
          This enumerates all the immediate children of the root node of the tree -- that is, all entries in the SparseTree which have no parent.
 java.lang.Iterable<EnumeratedSparseTreeNode<T>> EnumSubTree(java.lang.String token, EnumSubTreeOptions options, int depth)
          This will enumerate the entire subtree of the path supplied.
 boolean EnumSubTree(java.lang.String token, SparseTree.EnumNodeCallback<T> callback)
          This will enumerate the entire subtree of the path supplied.
 boolean EnumSubTree(java.lang.String token, SparseTree.EnumNodeCallback<T> callback, EnumSubTreeOptions options, int depth, SparseTreeAdditionalData additionalData, java.lang.Object param)
          This will enumerate the entire subtree of the path supplied.
 java.lang.Iterable<T> EnumSubTreeReferencedObjects(java.lang.String token, EnumSubTreeOptions options, int depth)
          This will enumerate the entire subtree of the path supplied.
 T get(java.lang.String token)
           
 T get(java.lang.String token, boolean exactMatch)
           
 int getCount()
          Returns the number of key/value pairs in this SparseTree.
 int getFixedElementLength()
          The optional element length.
 char getTokenSeparator()
          The optional separator character.
 boolean isSubItem(java.lang.String item, java.lang.String parent)
          Given an item and a possible parent, returns true if item is a subitem of parent given the token separator or fixed element length.
 void modifyInPlace(java.lang.String token, SparseTree.ModifyInPlaceCallback<T> callback, java.lang.Object param)
          Given a token, invokes the callback provided.
 boolean remove(java.lang.String token, boolean removeChildren)
          Removes a token from the store.
 void set(java.lang.String token, T referencedObject)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SparseTree

public SparseTree(char tokenSeparator)
Tokens have variable length segments that are separated by the set of characters given to the constructor. Tokens are compared with an OrdinalIgnoreCase comparison.

Parameters:
tokenSeparator - The set of valid token separator characters.

SparseTree

public SparseTree(int fixedElementLength)
Tokens have fixed length segments that are separated by the element length provided. Tokens are compared with an OrdinalIgnoreCase comparison

Parameters:
fixedElementLength - The fixed element length to separate the tokens by.

SparseTree

public SparseTree(java.util.Comparator<java.lang.String> tokenComparison)
Tokens are assumed to contain fixed length segments (ie. OrdinalPaths). Tokens are compared with the StringComparison method supplied.

Parameters:
tokenComparison - The type of comparison to use when comparing tokens.

SparseTree

public SparseTree(char tokenSeparator,
                  java.util.Comparator<java.lang.String> tokenComparison)
Tokens have variable length segments that are separated by the set of characters given to the constructor. Tokens are compared with the StringComparison method supplied

Parameters:
tokenSeparator - The token separator character.
tokenComparison - The type of comparison to use when comparing tokens.

SparseTree

public SparseTree(int fixedElementLength,
                  java.util.Comparator<java.lang.String> tokenComparison)
Tokens have fixed length segments that are separated by the length provided. Tokens are compared with the StringComparison method supplied

Parameters:
fixedElementLength - The fixed element length to separate the tokens by.
tokenComparison - The type of comparison to use when comparing tokens.

SparseTree

public SparseTree(char tokenSeparator,
                  int fixedElementLength,
                  java.util.Comparator<java.lang.String> tokenComparison)
Method Detail

add

public void add(java.lang.String token,
                T referencedObject)
This is used to add an object to the store at a specific path

Parameters:
token - The token we are adding.
referencedObject - The referencedObject we are adding.

add

public void add(java.lang.String token,
                T referencedObject,
                boolean overwrite)
This is used to add an object to the store at a specific path

Parameters:
token - The token we are adding.
referencedObject - The referencedObject we are adding.
overwrite - If true and an object already exists for this token, that object will be removed and this one will take its place.

modifyInPlace

public void modifyInPlace(java.lang.String token,
                          SparseTree.ModifyInPlaceCallback<T> callback,
                          java.lang.Object param)
Given a token, invokes the callback provided. The callback will be provided with the referenced object for that token, if one exists. The callback then should return the new referenced object for the token. The tree will be updated accordingly.

Parameters:
token - Token to look up
callback - Callback to invoke
param - Object passed through for your own use

remove

public boolean remove(java.lang.String token,
                      boolean removeChildren)
Removes a token from the store. If recurse is true, all of the children of the token will be removed as well.

Parameters:
token - The token to remove.
removeChildren - True if all of the children should be removed as well.
Returns:
True if something was removed.

get

public T get(java.lang.String token)

get

public T get(java.lang.String token,
             boolean exactMatch)

set

public void set(java.lang.String token,
                T referencedObject)

clear

public void clear()
Clears all of the tokens in the store.


EnumChildren

public KeyValuePair<java.lang.String,T>[] EnumChildren(java.lang.String token)
                                                throws KeyNotFoundException
Given a token that is in the store, returns the children of that node in the SparseTree. Because this data structure is a SparseTree, the children may not be immediate children, but there are no items in the SparseTree between token and the returned children. This method can be used to find the root(s) of the SparseTree by passing null as the token to query. If you are not sure, you probably want to be calling EnumSubTree with a depth value of 1 instead.

Parameters:
token - Token to query (null for the root)
Returns:
Array of referenced objects
Throws:
KeyNotFoundException

EnumParents

public boolean EnumParents(java.lang.String token,
                           SparseTree.EnumNodeCallback<T> callback)
Enumerates all parents of the specified token. Only nodes that have been specifically added to the SparseTree are enumerated. There is no requirement that the specified token exist in the tree. If it does exist, it is the first node enumerated. The provided callback can return true at any time to halt the enumeration.

Parameters:
token - The token whose parents should be enumerated
callback - The callback invoked for each enumerated node
Returns:
True if the enumeration was stopped by callback

EnumParents

public boolean EnumParents(java.lang.String token,
                           SparseTree.EnumNodeCallback<T> callback,
                           EnumParentsOptions options,
                           SparseTreeAdditionalData additionalData,
                           java.lang.Object param)
Enumerates all parents of the specified token. Only nodes that have been specifically added to the SparseTree are enumerated, unless the EnumerateSparseNodes flag is passed as part of the options parameter. There is no requirement that the specified token exist in the tree. If it does exist, it is the first node enumerated. The provided callback can return true at any time to halt the enumeration.

Parameters:
token - The token whose parents we are enumerating.
callback - The callback to make each time we hit a node.
options - EnumParentsOptions flags to control behavior
additionalData - If provided, this instance of SparseTreeAdditionalData will be populated with additional data and passed to you each time the callback is invoked. Can be null.
param - Object passed through for your own use
Returns:
True if we should halt our enumeration

EnumParents

public java.lang.Iterable<EnumeratedSparseTreeNode<T>> EnumParents(java.lang.String token,
                                                                   EnumParentsOptions options)
Queries the SparseTree for the parents of the provided token. Only nodes that have been specifically added to the SparseTree are enumerated, unless the EnumerateSparseNodes flag is passed as part of the options parameter. There is no requirement that the specified token exist in the tree. Nodes are enumerated from token to the root of the tree in a streaming fashion. Do not modify the SparseTree while enumerating.

Parameters:
token - The token whose parents to retrieve
options - EnumParentsOptions flags to control behavior
Returns:
The parents of the provided token

EnumParentsReferencedObjects

public java.lang.Iterable<T> EnumParentsReferencedObjects(java.lang.String token,
                                                          EnumParentsOptions options)
Queries the SparseTree for the parents of the provided token. Only nodes that have been specifically added to the SparseTree are enumerated, unless the EnumerateSparseNodes flag is passed as part of the options parameter. There is no requirement that the specified token exist in the tree. Nodes are enumerated from token to the root of the tree in a streaming fashion. Do not modify the SparseTree while enumerating.

Parameters:
token - The token whose parents to retrieve
options - EnumParentsOptions flags to control behavior

EnumSubTree

public boolean EnumSubTree(java.lang.String token,
                           SparseTree.EnumNodeCallback<T> callback)
This will enumerate the entire subtree of the path supplied. The root of the subtree will not be enumerated. Only elements that have been specifically added to the SparseTree are returned. The traversal of the tree is depth-first.

Parameters:
token - The token whose subtree to enumerate
callback - The callback we are invoking on each node
Returns:
True if we should stop our enumeration.

EnumSubTree

public boolean EnumSubTree(java.lang.String token,
                           SparseTree.EnumNodeCallback<T> callback,
                           EnumSubTreeOptions options,
                           int depth,
                           SparseTreeAdditionalData additionalData,
                           java.lang.Object param)
This will enumerate the entire subtree of the path supplied. The root of the subtree will not be enumerated unless the EnumerateSubTreeRoot flag is specified. Only elements that have been specifically added to the SparseTree are returned, unless the EnumerateSparseNodes flag is specified. The traversal of the tree is depth-first. A parameter may be passed through for your own use.

Parameters:
token - The token whose subtree to enumerate
callback - The callback we are invoking on each node
options - EnumSubTreeOptions flags to control behavior
depth - The depth of the enumeration. Default is Int32.MaxValue
additionalData - If provided, this instance of SparseTreeAdditionalData will be populated with additional data and passed to you each time the callback is invoked.
param - Object passed through for your own use
Returns:
True if we should stop our enumeration.

EnumSubTree

public java.lang.Iterable<EnumeratedSparseTreeNode<T>> EnumSubTree(java.lang.String token,
                                                                   EnumSubTreeOptions options,
                                                                   int depth)
This will enumerate the entire subtree of the path supplied. The root of the subtree will not be enumerated unless the EnumerateSubTreeRoot flag is specified. Only elements that have been specifically added to the SparseTree are returned, unless the EnumerateSparseNodes flag is specified. The traversal of the tree is depth-first.

Parameters:
token - The token whose parents to retrieve
options - EnumSubTreeOptions flags to control behavior
depth -
Returns:
The children of the provided token

EnumSubTreeReferencedObjects

public java.lang.Iterable<T> EnumSubTreeReferencedObjects(java.lang.String token,
                                                          EnumSubTreeOptions options,
                                                          int depth)
This will enumerate the entire subtree of the path supplied. The root of the subtree will not be enumerated unless the EnumerateSubTreeRoot flag is specified. Only elements that have been specifically added to the SparseTree are returned, unless the EnumerateSparseNodes flag is specified. The traversal of the tree is depth-first.

Parameters:
token - The token whose parents to retrieve
options - EnumSubTreeOptions flags to control behavior
depth -
Returns:
The children of the provided token

EnumRoots

public java.lang.Iterable<EnumeratedSparseTreeNode<T>> EnumRoots()
This enumerates all the immediate children of the root node of the tree -- that is, all entries in the SparseTree which have no parent.

Returns:
all immediate children of the root node of the tree.

EnumRootsReferencedObjects

public java.lang.Iterable<T> EnumRootsReferencedObjects()
This enumerates all the immediate children of the root node of the tree -- that is, all entries in the SparseTree which have no parent.

Returns:
all immediate children of the root node of the tree.

isSubItem

public boolean isSubItem(java.lang.String item,
                         java.lang.String parent)
Given an item and a possible parent, returns true if item is a subitem of parent given the token separator or fixed element length. This check does NOT depend on the state of the tree and is based solely on the contents of the passed strings.

Parameters:
item - Item to check
parent - Potential parent of item
Returns:
True if parent is a parent of item

getCount

public int getCount()
Returns the number of key/value pairs in this SparseTree.


getTokenSeparator

public char getTokenSeparator()
The optional separator character. If this is the null character, there is no separator and the token assumed to be a fixed length meaning the FixedElementLength will be used to split the tokens.


getFixedElementLength

public int getFixedElementLength()
The optional element length. If this is -1, a variable length token is assumed and the TokenSeparator will be used to split the tokens.



© 2015 Microsoft. All rights reserved.