package com.neusoft.smart.pos.dto.user;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import java.util.Collection;

@Data
@RequiredArgsConstructor
@AllArgsConstructor
public class TreeNode<K, V> {
    @NonNull
    private K key;
    @NonNull
    private V value;
    private Collection<TreeNode<K, V>> children;

    public void addChild(TreeNode<K, V> treeNode) {
        if (this.children == null) this.children = new ArrayList<>();
        this.children.add(treeNode);
    }

    public void addChildren(Collection<TreeNode<K, V>> treeNodes) {
        if (this.children == null) this.children = new ArrayList<>();
        this.children.addAll(treeNodes);
    }

    public boolean isLeaf() {
        return this.children == null || this.children.isEmpty();
    }
}
