Libraries
Search…
Implementation
Class: Node. Modules: StateHelper and KindHelper.

Constants

Attributes

back

A back Node instance reference, or nil.

data

A DataType type instance.

front

A front Node instance reference, or nil.

Methods

initialize(b_n = nil, dti = nil, f_n = nil)

1
def initialize(b_n = nil, dti = nil, f_n = nil)
2
3
self.back = b_n
4
self.data = dti
5
self.front = f_n
6
7
end
Copied!
Initializes a Node instance. Takes two Node arguments, b_n and f_n. b_n is back's assignment, and f_n is front's assignment. Takes one DataType type instance argument, dti. dti becomes the data reference. Returns a Node instance.

shallow_clone()

1
def shallow_clone()
2
3
n = Node.new(back(), data(), front())
4
if (frozen?())
5
return n.freeze()
6
else
7
return n
8
end
9
10
end
Copied!
Shallowly clones. The clone and self are not identical, and share the same attribute references. Returns the Node clone.

clone_df()

1
def clone_df()
2
3
b = back().clone()
4
d = data()
5
f = front().clone()
6
n = Node.new(b, d, f)
7
if (frozen?())
8
return n.freeze()
9
else
10
return n
11
end
12
13
end
Copied!
Deeply clones. No Node references are identical. data references are identical. Returns the clone Node. Mutating the attributes' references raises a FrozenError.

b()

1
def b()
2
return back().freeze()
3
end
Copied!
Getsback 's reference. Returns the Node, frozen.

data()

1
def data()
2
return @data
3
end
Copied!
Getsdata 's reference. Returns the DataType type instance.

f()

1
def f()
2
return front().freeze()
3
end
Copied!
Getsfront 's reference. Returns the Node, frozen.

data=(dti = nil)

1
def data=(dti = nil)
2
3
error = DataError.new()
4
unless (DataType.instance?(dti))
5
raise(error, error.message())
6
else
7
@data = dti
8
end
9
10
end
Copied!
Sets data. Takes a DataType type instance argument, dti. dti becomes the data setting. Returns the argument. In the case the argument is any type other than a DataType type instance, raises a DataError.

==(n = nil)

1
def ==(n = nil)
2
3
unless (n.instance_of?(Node))
4
return false
5
else
6
eq = (back().equal?(n.back_ref()) && (data().equal?(n.data())) &&
7
(front().equal?(n.front_ref())))
8
return eq
9
end
10
11
end
Copied!
Attribute equality operator. Takes a comparison instance, rhs. Returns true in the case self's attribute references and rhs' attribute references are identical instances. Returns false otherwise.

===(n = nil)

1
def ===(n = nil)
2
return equal?(n)
3
end
Copied!
Identity comparison operator. Takes a comparison instance, rhs. Returns true in the case self and the argument are identical instances. Returns false otherwise.

inspect()

1
def inspect()
2
3
df_singleton = DiagramFactory.instance()
4
diagram = df_singleton.diagram(self)
5
return diagram.form()
6
7
end
Copied!
Diagrammatically represents self. Returns the String formation.

back_ref() protected

1
def back_ref()
2
return back()
3
end
Copied!
Gets back's reference. Returns the Node or NilClass instance reference.

front_ref() protected

1
def front_ref()
2
return front()
3
end
Copied!
Gets front's reference. Returns the Node or NilClass instance reference.

back() private

1
def back()
2
return @back
3
end
Copied!
Gets back's reference. Returns the Node or NilClass instance reference.

front() private

1
def front()
2
return @front
3
end
Copied!
Gets front's reference. Returns the Node or NilClass instance reference.

back=(n = nil) private

1
def back=(n = nil)
2
3
error = NodeError.new()
4
if (!(n.instance_of?(Node) || n.nil?()))
5
raise(error, error.message())
6
else
7
@back = n
8
end
9
10
end
Copied!
Sets back. Takes a Node argument, n. n becomes back's setting. Returns the argument Node. In the case the argument is any type other than Node, raises a NodeError.

front=(n = nil) private

1
def front=(n = nil)
2
3
error = NodeError.new()
4
if (!(n.instance_of?(Node) || n.nil?()))
5
raise(error, error.message())
6
else
7
@front = n
8
end
9
10
end
Copied!
Sets front. Takes a Node argument, n. n becomes front's setting. Returns the argument Node. In the case the argument is any type other than Node, raises a NodeError.

State Predicates

back_attached()
1
def back_attached()
2
return !back().nil?()
3
end
Copied!
Returns true in the case back refers a Node instance. false otherwise.
front_attached()
1
def front_attached()
2
return !front().nil?()
3
end
Copied!
Returns true in the case front refers a Node instance. false otherwise.
no_attachments()
1
def no_attachments()
2
return(!back_attached() && !front_attached())
3
end
Copied!
Returns true in the case back and front refer nil. false otherwise.
empty()
1
def empty()
2
return data().nil?()
3
end
Copied!
Returns true in the case data refers nil. false otherwise.
both_attached()
1
def both_attached()
2
return (back_attached() && front_attached())
3
end
Copied!
Verifies back and front are attachments. Returns true in the case back and front refer Nodes. false otherwise.
lone()
1
def lone()
2
return no_attachments()
3
end
Copied!
Verifies the kind is 'lone'. A 'lone' Node is a Node bearing no attachments. Returns true in the case self's back reference and self's front references are nil. false otherwise.
common()
1
def common()
2
return (back_attached() && front_attached())
3
end
Copied!
Verifies the kind is 'common'. A 'common' Node is a fully attached Node. Returns true in the case both back and front refer Nodes. false otherwise.
base()
1
def base()
2
return(!back_attached() && front_attached())
3
end
Copied!
Returns true in the case back refers nil and front refers a Node instance. false otherwise.
pioneer()
1
def pioneer()
2
return(back_attached() && !front_attached())
3
end
Copied!
Returns true in the case back refers a Node instance and front refers nil. false otherwise.

Kind Helpers

    kind()
Last modified 1yr ago