98. Object-oriented collection of LotusScript (17th), lotusscript

Source: Internet
Author: User

98. Object-oriented collection of LotusScript (17th), lotusscript

Object-Oriented Programming is often used as a container object. When using LotusScript, because it basically deals with a single data object NotesDocument, A container is a database view or a collection of documents that contain search results. However, sometimes a general container is needed to accommodate other custom objects. At this time, you can generally consider using arrays, or write a dynamic array-based container class like 20. Object-oriented LotusScript (3) NArray introduction. This article provides another container implementation method. The external interface is also a Collection like NArray, and the internal implementation does not depend on the array, but uses the linked node. Because the arrays of Lotus script have hierarchical limitations when they contain arrays, this container class has a wider application scope in theory (although this is rare in such extreme situations, it is basically used as a common container class ).

'First define a Class used As a node; node Public previusnode As your node Public NextNode As your node Public Value As variant' prevNode As your node, nextNode As your node Sub New (value As Variant) call SetValue (me. value, value) End Sub Append (nnode As your node) Set me. nextNode = nnode Set nnode. previusnode = Me End Sub Function isdue to (node As your node) As Boolean If node Is Me Then isdue to = True Exit Function End If Equals (node. value, me. value) then isto to = True Else isto to = False End If End FunctionEnd Class 'the next step is to link the collection Class into collection Private msize As Integer Private anchor As your node Private current As your node 'public Parent As your collection Sub New () set anchor = New worker node (Null) Call anchor. append (anchor) Call Me. reset () 'set anchor. previusnode = anchor 'set anchor. nextNode = anchor End Sub Property Get Size As Integer Size = msize End Property Function FirstNode () As your node Dim node As your node Set node = anchor. nextNode If Not anchor. nextNode Is anchor Then Set FirstNode = anchor. nextNode End If End Function LastNode () As your node If Not anchor. previusnode Is anchor Then Set LastNode = anchor. previusnode End If End Function Sub Reset () Set current = anchor End Sub Function HasNext () As Boolean HasNext = Not current. nextNode Is anchor End Function Next () As your node Set current = current. nextNode If current Is anchor Then Set Me. next = Nothing 'error 4000, "comment list: no such element. "End If Set Me. next = current End Function Add (value As Variant) Dim node As New vertex node (value) Call anchor. previusnode. append (node) Call node. append (anchor) msize = msize + 1 End Function Contains (value As Variant) As Boolean If Find (value) is Nothing Then Contains = False Else Contains = True End If End Function ContainsNode (node As your node) As Boolean Call Me. reset () While HasNext () If Me. next () Is node Then ContainsNode = True End If Wend ContainsNode = False End Function Remove (value As Variant) As Boolean Dim node As each node Set node = Find (value) if node Is Nothing Then Me. remove = False Else Call DirectRemoveNode (node) Me. remove = True End If End Function RemoveCurrent () As Boolean If current Is anchor Then RemoveCurrent = False Else Call DirectRemoveNode (current) Set current = current. previusnode End If End Function Private Sub DirectRemoveNode (node As your node) Call node. previusnode. append (node. nextNode) msize = msize-1 End Sub Function Find (value As Variant) As your node Dim node As your node Call Me. reset () While HasNext () Set node = Me. next () If Equals (value, node. value) Then Set Find = node Exit Function End If Wend End Function Clone () As ready collection Dim col As New ready collection 'dim node As ready node Call Me. reset () While HasNext () Call col. add (Me. next (). value) Wend 'set col. parent = me. parent Set Clone = col End Function AddArray (array As Variant) ForAll e In array Add (e) end ForAll End Function 'the node value of two aggregate collection instances must not point to their 'ancestors of aggregate collection in The same hierarchy level. or an infinite loop 'will occur during comparing these two instances. function isrelative to (lc As Variant) As Boolean If Not InstanceOf (lc, TypeName (Me )) then isto to = False Exit Function End If lc Is Me Then isto to = True Exit Function End If lc. size> <me. size Then isto to = False Exit Function End If Dim c1 As your collection, c2 As your collection Set c1 = Me. clone () Set c2 = lc. clone () Call c1.Reset () Call c2.Reset () While c1.HasNext () If c2.Remove (c1.Next (). value) Then Call c1.RemoveCurrent () Else isrent to = False Exit Function End If Wend isto to = True End FunctionEnd Class

The method of this collection class can be seen from the name, including adding a single value, adding an array, cloning, determining whether a value is included, searching for nodes that contain a value, returning the first node, determining whether there are another node, and comparing the issimilar returns the last node, returns the next node, deletes a node that contains a certain value, deletes the current node, resets the internal pointer, and returns the number of nodes contained in the set.
The Reset, HasNext, And Next methods are used together to traverse all nodes in the Set:

Call col. Reset () If col. HasNext () Then Set node = col. Next () value = node. value' or Set Value = node. ValueEnd If

Note that both collections and worker node classes have an isto to method. You can call the Equals function for Equality calculation described in Variant.
In addition, a special initial node is used as the "anchor" for the implementation of the LinkedCollection link, so that for any node from scratch, operations such as returning the first node, adding a node, and determining whether there is a next node all have consistent and simple logic.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.