Libraries.Containers.TextTree Documentation

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Balance()This action will create a new TextTree containing the balanced contents of this tree.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Concatenate(Libraries.Containers.TextTree textTree)The Concatenate action creates a new TextTree where the provided tree is appended to the end of this tree.
Concatenate(text value)The Concatenate action creates a new TextTree where the provided text is appended to the end of this tree's text.
Delete(integer startIndex, integer endIndex)The Delete action creates a new TextTree which is a copy of this tree, then deletes all characters between the two given indices.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetCharacter(integer index)This action retrieves a character at the given index from the tree.
GetHashCode()This action gets the hash code for an object.
GetLeafSize()This action returns how many characters can be stored in each leaf of the TextTree.
GetLength()This action returns the length of the text stored in the TextTree.
GetText(integer startIndex, integer endIndex)This action returns the text between the two indices.
GetText()This action returns all of the text stored in the TextTree.
Initialize(text value)The Initialize action constructs the TextTree from a starting text value.
Initialize(text value, integer leafSize)The Initialize action constructs the TextTree from a starting text value.
Insert(integer index, text value)The Insert action creates a new TextTree and inserts the given text value into the tree at the provided index.
NeedsBalancing()This action returns true is the tree is imbalanced, or false if it is considered balanced.
SetLeafSize(integer size)This action sets how many characters should be stored in each leaf of the TextTree.

Actions Documentation

Balance()

This action will create a new TextTree containing the balanced contents of this tree. This is typically handled automatically by the tree itself during other operations which return new TextTrees.

Return

Libraries.Containers.TextTree: A new TextTree which is balanced and contains the same text as this TextTree. use Libraries.Containers.TextTree TextTree tree tree:Initialize("Hello world!") boolean shouldRebalance = tree:NeedsBalancing() output "shouldRebalance is " + shouldRebalance if shouldRebalance tree:Balance() end

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Example Code

Object o
        Object t
        integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Concatenate(Libraries.Containers.TextTree textTree)

The Concatenate action creates a new TextTree where the provided tree is appended to the end of this tree. All text in the parameter tree will appear after the text from this tree inside the returned value. This tree will not change as a result of this action.

Example Code

use Libraries.Containers.TextTree

    TextTree tree1
    tree1:Initialize("Hello ")

    TextTree tree2
    tree2:Initialize("world!")

    TextTree result = tree1:Concatenate(tree2)
    output result:GetText()

Parameters

Return

Libraries.Containers.TextTree: A new TextTree which contains the concatenation of the two trees.

Concatenate(text value)

The Concatenate action creates a new TextTree where the provided text is appended to the end of this tree's text. This tree will not change as a result of this action.

Example Code

use Libraries.Containers.TextTree

    TextTree tree
    tree:Initialize("Hello ")

    TextTree result = tree:Concatenate("world!")
    output result:GetText()

Parameters

Return

Libraries.Containers.TextTree: A new TextTree which contains the concatenation of this tree's text and the parameter text.

Delete(integer startIndex, integer endIndex)

The Delete action creates a new TextTree which is a copy of this tree, then deletes all characters between the two given indices. The first index is inclusive (the character at the first index will be deleted) and the second index is exclusive (the character at the second index is not deleted). This action creates a new TextTree, and has no effect on this tree.

Example Code

use Libraries.Containers.TextTree

    TextTree tree
    tree:Initialize("Hello world!")

    TextTree deleteTree = tree:Delete(5, tree:GetLength() - 1)
    output deleteTree:GetText()

Parameters

Return

Libraries.Containers.TextTree: A new TextTree containing this tree's text, minus the deleted portion.

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

GetCharacter(integer index)

This action retrieves a character at the given index from the tree.

Example Code

use Libraries.Containers.TextTree

    TextTree tree
    tree:Initialize("Hello world!")
    text character = tree:GetCharacter(1)
    output "The character at index 1 is '" + character + "'."

Parameters

Return

text: A single character located at the given index.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetLeafSize()

This action returns how many characters can be stored in each leaf of the TextTree.

Example Code

use Libraries.Containers.TextTree

    TextTree defaultTree
    defaultTree:Initialize("Hello world! What a lovely day!")
    output "The default tree stores text in " + defaultTree:GetLeafSize() + " character chunks."

    TextTree newTree
    newTree:SetLeafSize(10)
    newTree:Initialize("Hello world! What a lovely day!")
    output "The new tree stores text in " + newTree:GetLeafSize() + " character chunks."

Return

integer: How many characters can be stored in each leaf.

GetLength()

This action returns the length of the text stored in the TextTree.

Example Code

use Libraries.Containers.TextTree

    TextTree tree
    tree:Initialize("Hello world!")
    output "The length of the text in the tree is " + tree:GetLength()

Return

integer: The length of text in this TextTree.

GetText(integer startIndex, integer endIndex)

This action returns the text between the two indices. The first index is inclusive (the character at the first index is part of the returned text) and the second index is exclusive (the character at the second index is not part of the returned text).

Example Code

use Libraries.Containers.TextTree

    TextTree tree
    tree:Initialize("Hello world!")
    output tree:GetText(1, 10)

Parameters

Return

text: The text between the two indices.

GetText()

This action returns all of the text stored in the TextTree.

Example Code

use Libraries.Containers.TextTree

    TextTree tree
    tree:Initialize("Hello world!")
    output tree:GetText()

Return

text: The text stored in this TextTree.

Initialize(text value)

The Initialize action constructs the TextTree from a starting text value. The TextTree will store the given value, which may be retrieved or modified using the TextTree's other actions.

Example Code

use Libraries.Containers.TextTree

    TextTree tree
    tree:Initialize("Hello world! What a lovely day!")
    output tree:GetText()

Parameters

Initialize(text value, integer leafSize)

The Initialize action constructs the TextTree from a starting text value. The TextTree will store the given value, which may be retrieved or modified using the TextTree's other actions. The provided integer parameter will be used to set the maximum size of each leaf, in characters.

Example Code

use Libraries.Containers.TextTree

    TextTree defaultTree
    defaultTree:Initialize("Hello world! What a lovely day!")
    output "The default tree stores text in " + defaultTree:GetLeafSize() + " character chunks."

    TextTree newTree
    newTree:Initialize("Hello world! What a lovely day!", 10)
    output "The new tree stores text in " + newTree:GetLeafSize() + " character chunks."

Parameters

Insert(integer index, text value)

The Insert action creates a new TextTree and inserts the given text value into the tree at the provided index. The character that was previously located at that index will be positioned behind the newly inserted text. This action creates a new TextTree, and has no effect on this tree.

Example Code

use Libraries.Containers.TextTree

    TextTree tree
    tree:Initialize("Hello world!")

    TextTree insertTree = tree:Insert(11, " of tomorrow")
    output insertTree:GetText()

Parameters

Return

Libraries.Containers.TextTree: A new TextTree containing the inserted text.

NeedsBalancing()

This action returns true is the tree is imbalanced, or false if it is considered balanced. This is typically handled automatically by the tree itself.

Example Code

use Libraries.Containers.TextTree

    TextTree tree
    tree:Initialize("Hello world!")
    boolean shouldRebalance = tree:NeedsBalancing()
    output "shouldRebalance is " + shouldRebalance

    if shouldRebalance
        tree:Balance()
    end

Return

boolean: Whether or not the tree is currently imbalanced.

SetLeafSize(integer size)

This action sets how many characters should be stored in each leaf of the TextTree.

Example Code

use Libraries.Containers.TextTree

    TextTree defaultTree
    defaultTree:Initialize("Hello world! What a lovely day!")
    output "The default tree stores text in " + defaultTree:GetLeafSize() + " character chunks."

    TextTree newTree
    newTree:SetLeafSize(10)
    newTree:Initialize("Hello world! What a lovely day!")
    output "The new tree stores text in " + newTree:GetLeafSize() + " character chunks."

Parameters