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)

def initialize(b_n = nil, dti = nil, f_n = nil)
self.back = b_n
self.data = dti
self.front = f_n
end

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()

def shallow_clone()
n = Node.new(back(), data(), front())
if (frozen?())
return n.freeze()
else
return n
end
end

Shallowly clones. The clone and self are not identical, and share the same attribute references. Returns the Node clone.

clone_df()

def clone_df()
b = back().clone()
d = data()
f = front().clone()
n = Node.new(b, d, f)
if (frozen?())
return n.freeze()
else
return n
end
end

Deeply clones. No Node references are identical. data references are identical. Returns the clone Node. Mutating the attributes' references raises a FrozenError.

b()

def b()
return back().freeze()
end

Getsback 's reference. Returns the Node, frozen.

data()

def data()
return @data
end

Getsdata 's reference. Returns the DataType type instance.

f()

def f()
return front().freeze()
end

Getsfront 's reference. Returns the Node, frozen.

data=(dti = nil)

def data=(dti = nil)
error = DataError.new()
unless (DataType.instance?(dti))
raise(error, error.message())
else
@data = dti
end
end

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)

def ==(n = nil)
unless (n.instance_of?(Node))
return false
else
eq = (back().equal?(n.back_ref()) && (data().equal?(n.data())) &&
(front().equal?(n.front_ref())))
return eq
end
end

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)

def ===(n = nil)
return equal?(n)
end

Identity comparison operator. Takes a comparison instance, rhs. Returns true in the case self and the argument are identical instances. Returns false otherwise.

inspect()

def inspect()
df_singleton = DiagramFactory.instance()
diagram = df_singleton.diagram(self)
return diagram.form()
end

Diagrammatically represents self. Returns the String formation.

back_ref() protected

def back_ref()
return back()
end

Gets back's reference. Returns the Node or NilClass instance reference.

front_ref() protected

def front_ref()
return front()
end

Gets front's reference. Returns the Node or NilClass instance reference.

back() private

def back()
return @back
end

Gets back's reference. Returns the Node or NilClass instance reference.

front() private

def front()
return @front
end

Gets front's reference. Returns the Node or NilClass instance reference.

back=(n = nil) private

def back=(n = nil)
error = NodeError.new()
if (!(n.instance_of?(Node) || n.nil?()))
raise(error, error.message())
else
@back = n
end
end

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

def front=(n = nil)
error = NodeError.new()
if (!(n.instance_of?(Node) || n.nil?()))
raise(error, error.message())
else
@front = n
end
end

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()

def back_attached()
return !back().nil?()
end

Returns true in the case back refers a Node instance. false otherwise.

front_attached()

def front_attached()
return !front().nil?()
end

Returns true in the case front refers a Node instance. false otherwise.

no_attachments()

def no_attachments()
return(!back_attached() && !front_attached())
end

Returns true in the case back and front refer nil. false otherwise.

empty()

def empty()
return data().nil?()
end

Returns true in the case data refers nil. false otherwise.

both_attached()

def both_attached()
return (back_attached() && front_attached())
end

Verifies back and front are attachments. Returns true in the case back and front refer Nodes. false otherwise.

lone()

def lone()
return no_attachments()
end

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()

def common()
return (back_attached() && front_attached())
end

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()

def base()
return(!back_attached() && front_attached())
end

Returns true in the case back refers nil and front refers a Node instance. false otherwise.

pioneer()

def pioneer()
return(back_attached() && !front_attached())
end

Returns true in the case back refers a Node instance and front refers nil. false otherwise.

Kind Helpers

  • kind()