tree

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ContainerKeyPostfix = "_container"

Variables

This section is empty.

Functions

func ExtractNodeDataFromList

func ExtractNodeDataFromList[T *Node[T]](list []*Node[T]) []T

func NewUUID

func NewUUID() uuid.UUID

Types

type Marshaller

type Marshaller[T any] interface {
	xml.Marshaler
	json.Marshaler
	encoding.TextMarshaler
	encoding.BinaryMarshaler
	Marshal(objectPtr any) (Provider[T], error)
}

type Node

type Node[T any] struct {
	ID     uuid.UUID `json:"id"`
	Data   T
	Type   string `json:"type"`
	IsOpen bool   `json:"open,omitempty"` // Container only
	// contains filtered or unexported fields
}

func NewNode

func NewNode[T any](typeKey string, isContainer bool, data T) *Node[T]

func (*Node[T]) AddChild

func (n *Node[T]) AddChild(child *Node[T])

func (*Node[T]) ApplyTo

func (n *Node[T]) ApplyTo(to *Node[T])

func (*Node[T]) Children

func (n *Node[T]) Children() []*Node[T]

func (*Node[T]) ChildrenElemByID

func (n *Node[T]) ChildrenElemByID()

func (*Node[T]) ChildrenElemByIndex

func (n *Node[T]) ChildrenElemByIndex()

func (*Node[T]) ChildrenElemByName

func (n *Node[T]) ChildrenElemByName()

func (*Node[T]) ChildrenElemByPath

func (n *Node[T]) ChildrenElemByPath()

func (*Node[T]) ChildrenElemByType

func (n *Node[T]) ChildrenElemByType()

func (*Node[T]) ChildrenLastElem

func (n *Node[T]) ChildrenLastElem()

func (*Node[T]) ChildrenLen

func (n *Node[T]) ChildrenLen()

func (*Node[T]) ChildrenMoveTo

func (n *Node[T]) ChildrenMoveTo()

func (*Node[T]) ChildrenRemoveByID

func (n *Node[T]) ChildrenRemoveByID()

func (*Node[T]) ChildrenRemoveByIndex

func (n *Node[T]) ChildrenRemoveByIndex()

func (*Node[T]) ChildrenRemoveByName

func (n *Node[T]) ChildrenRemoveByName()

func (*Node[T]) ChildrenRemoveByPath

func (n *Node[T]) ChildrenRemoveByPath()

func (*Node[T]) ChildrenReset

func (n *Node[T]) ChildrenReset()

func (*Node[T]) ChildrenSum

func (n *Node[T]) ChildrenSum(parent *Node[T]) *Node[T]

func (*Node[T]) ChildrenSwap

func (n *Node[T]) ChildrenSwap()

func (*Node[T]) Clone

func (n *Node[T]) Clone(newParent *Node[T], preserveID bool) *Node[T]

func (*Node[T]) Container

func (n *Node[T]) Container() bool

func (*Node[T]) CopyFrom

func (n *Node[T]) CopyFrom(from *Node[T])

func (*Node[T]) CreateItem

func (n *Node[T]) CreateItem(parent *Node[T], data T) *Node[T]

func (*Node[T]) Depth

func (n *Node[T]) Depth() int

func (*Node[T]) Enabled

func (n *Node[T]) Enabled() bool

func (*Node[T]) FindByID

func (n *Node[T]) FindByID(id uuid.UUID) *Node[T]

func (*Node[T]) FindByIndex

func (n *Node[T]) FindByIndex(id uuid.UUID) *Node[T]

func (*Node[T]) FindByName

func (n *Node[T]) FindByName(id uuid.UUID) *Node[T]

func (*Node[T]) FindByPath

func (n *Node[T]) FindByPath(id uuid.UUID) *Node[T]

func (*Node[T]) FindByType

func (n *Node[T]) FindByType(id uuid.UUID) *Node[T]

func (*Node[T]) Format

func (n *Node[T]) Format(root *Node[T]) string

func (*Node[T]) GetType

func (n *Node[T]) GetType() string

func (*Node[T]) HasChildren

func (n *Node[T]) HasChildren() bool

func (*Node[T]) InsertByID

func (n *Node[T]) InsertByID(id uuid.UUID) *Node[T]

func (*Node[T]) InsertByIndex

func (n *Node[T]) InsertByIndex(id uuid.UUID) *Node[T]

func (*Node[T]) InsertByName

func (n *Node[T]) InsertByName(id uuid.UUID) *Node[T]

func (*Node[T]) InsertByPath

func (n *Node[T]) InsertByPath(id uuid.UUID) *Node[T]

func (*Node[T]) InsertByType

func (n *Node[T]) InsertByType(id uuid.UUID) *Node[T]

func (*Node[T]) InsertItem

func (n *Node[T]) InsertItem(parentID uuid.UUID, data T) *Node[T]

func (*Node[T]) Marshal

func (n *Node[T]) Marshal(objectPtr any) (Provider[T], error)

func (*Node[T]) MarshalBinary

func (n *Node[T]) MarshalBinary() (data []byte, err error)

func (*Node[T]) MarshalJSON

func (n *Node[T]) MarshalJSON() ([]byte, error)

func (*Node[T]) MarshalText

func (n *Node[T]) MarshalText() (text []byte, err error)

func (*Node[T]) MarshalXML

func (n *Node[T]) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Node[T]) Open

func (n *Node[T]) Open() bool

func (*Node[T]) Parent

func (n *Node[T]) Parent() *Node[T]

func (*Node[T]) RemoveByID

func (n *Node[T]) RemoveByID(id uuid.UUID)

func (*Node[T]) RemoveByIndex

func (n *Node[T]) RemoveByIndex(id uuid.UUID)

func (*Node[T]) RemoveByName

func (n *Node[T]) RemoveByName(id uuid.UUID)

func (*Node[T]) RemoveByPath

func (n *Node[T]) RemoveByPath(id uuid.UUID)

func (*Node[T]) RemoveSelf

func (n *Node[T]) RemoveSelf(id uuid.UUID)

func (*Node[T]) SetChildren

func (n *Node[T]) SetChildren(children []*Node[T])

func (*Node[T]) SetFormatRowCallback

func (n *Node[T]) SetFormatRowCallback(formatRowCallback func(*Node[T]) string)

func (*Node[T]) SetHeader

func (n *Node[T]) SetHeader(header []string)

func (*Node[T]) SetOpen

func (n *Node[T]) SetOpen(open bool)

func (*Node[T]) SetParent

func (n *Node[T]) SetParent(parent *Node[T])

func (*Node[T]) SetType

func (n *Node[T]) SetType(t string)

func (*Node[T]) Sort

func (n *Node[T]) Sort(cmp func(a, b T) bool)

func (*Node[T]) String

func (n *Node[T]) String() string

func (*Node[T]) UUID

func (n *Node[T]) UUID() uuid.UUID

func (*Node[T]) Unmarshal

func (n *Node[T]) Unmarshal(tree Provider[T]) (objectPtr any, err error)

func (*Node[T]) UnmarshalBinary

func (n *Node[T]) UnmarshalBinary(data []byte) error

func (*Node[T]) UnmarshalJSON

func (n *Node[T]) UnmarshalJSON(bytes []byte) error

func (*Node[T]) UnmarshalText

func (n *Node[T]) UnmarshalText(text []byte) error

func (*Node[T]) UnmarshalXML

func (n *Node[T]) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

func (*Node[T]) UpdateByID

func (n *Node[T]) UpdateByID(id uuid.UUID, data T)

func (*Node[T]) UpdateByIndex

func (n *Node[T]) UpdateByIndex(id uuid.UUID, data T)

func (*Node[T]) UpdateByName

func (n *Node[T]) UpdateByName(id uuid.UUID, data T)

func (*Node[T]) UpdateByPath

func (n *Node[T]) UpdateByPath(id uuid.UUID, data T)

func (*Node[T]) UpdateByType

func (n *Node[T]) UpdateByType(id uuid.UUID, data T)

func (*Node[T]) Walk

func (n *Node[T]) Walk(callback func(node *Node[T]))

func (*Node[T]) WalkContainer

func (n *Node[T]) WalkContainer(callback func(node *Node[T]))

type Provider

type Provider[T any] interface {
	Walk(callback func(node *Node[T]))
	WalkContainer(callback func(node *Node[T]))
	Clone(newParent *Node[T], preserveID bool) *Node[T]
	CopyFrom(from *Node[T])
	ApplyTo(to *Node[T])
	UUID() uuid.UUID

	Depth() int
	Parent() *Node[T]
	SetParent(parent *Node[T])
	Sort(cmp func(a T, b T) bool)
	RemoveByID(id uuid.UUID)
	RemoveByName(id uuid.UUID)
	RemoveByIndex(id uuid.UUID)
	RemoveSelf(id uuid.UUID)
	RemoveByPath(id uuid.UUID)
	AddChild(child *Node[T])
	InsertItem(parentID uuid.UUID, data T) *Node[T]
	CreateItem(parent *Node[T], data T) *Node[T]
	InsertByID(id uuid.UUID) *Node[T]
	InsertByName(id uuid.UUID) *Node[T]
	InsertByIndex(id uuid.UUID) *Node[T]
	InsertByType(id uuid.UUID) *Node[T]
	InsertByPath(id uuid.UUID) *Node[T]
	FindByID(id uuid.UUID) *Node[T]
	FindByName(id uuid.UUID) *Node[T]
	FindByIndex(id uuid.UUID) *Node[T]
	FindByPath(id uuid.UUID) *Node[T]
	FindByType(id uuid.UUID) *Node[T]
	UpdateByID(id uuid.UUID, data T)
	UpdateByName(id uuid.UUID, data T)
	UpdateByIndex(id uuid.UUID, data T)
	UpdateByPath(id uuid.UUID, data T)
	UpdateByType(id uuid.UUID, data T)
	Container() bool
	HasChildren() bool
	Children() []*Node[T]
	SetChildren(children []*Node[T])

	GetType() string
	SetType(t string)
	Open() bool
	SetOpen(open bool)
	ChildrenLen()
	ChildrenSwap()
	ChildrenMoveTo()
	ChildrenLastElem()
	ChildrenElemByID()
	ChildrenElemByName()
	ChildrenElemByIndex()
	ChildrenElemByType()
	ChildrenElemByPath()
	ChildrenReset()
	ChildrenRemoveByID()
	ChildrenRemoveByName()
	ChildrenRemoveByIndex()
	ChildrenRemoveByPath()
	ChildrenSum(parent *Node[T]) *Node[T]
	SetHeader(header []string)
	SetFormatRowCallback(formatRowCallback func(*Node[T]) string)
	Format(root *Node[T]) string

	String() string
	Enabled() bool
	Marshaller[T]
	Unmarshaler[T]
	// contains filtered or unexported methods
}

func New

func New[T any]() Provider[T]

type Unmarshaler

type Unmarshaler[T any] interface {
	xml.Unmarshaler
	json.Unmarshaler
	encoding.TextUnmarshaler
	encoding.BinaryUnmarshaler
	Unmarshal(tree Provider[T]) (objectPtr any, err error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL