package no.uio.ifi.trackfind.backend.data;

import lombok.*;

import java.util.Collection;

/**
 * Data type for representing metadata element (attribute or value) on front-end.
 *
 * @author Dmytro Titov
 */
@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class TreeNode implements Comparable<TreeNode> {

    private String category;
    private String value;
    private boolean attribute;
    private boolean array;
    private String type;
    private boolean hasValues;
    private int level;
    private String separator;
    private TreeNode parent;
    private Collection<String> children;

    @Setter(AccessLevel.NONE)
    @Getter(AccessLevel.NONE)
    private String path;
    @Setter(AccessLevel.NONE)
    @Getter(AccessLevel.NONE)
    private String sqlPath;

    /**
     * Gets path from the root node to current node.
     *
     * @return Sequence of attributes separated by some delimiter.
     */
    @EqualsAndHashCode.Include
    public String getPath() {
        if (path == null) { // double checked synchronization
            synchronized (this) {
                if (path == null) {
                    path = getPathInternally();
                }
            }
        }
        return path;
    }

    /**
     * Gets SQL path from the root node to current node.
     *
     * @return Sequence of attributes separated by some delimiter.
     */
    public String getSQLPath() {
        if (sqlPath == null) { // double checked synchronization
            synchronized (this) {
                if (sqlPath == null) {
                    sqlPath = getSQLPathInternally();
                }
            }
        }
        return sqlPath;
    }

    /**
     * Gets path from the root node to current node.
     *
     * @return Sequence of attributes separated by some delimiter.
     */
    private String getPathInternally() {
        StringBuilder path = new StringBuilder(toString());
        TreeNode parent = getParent();
        while (parent != null) {
            path.insert(0, parent.toString() + separator);
            parent = parent.getParent();
        }
        return path.toString();
    }

    /**
     * Gets SQL path from the root node to current node.
     *
     * @return Sequence of attributes separated by some delimiter.
     */
    private String getSQLPathInternally() {
        StringBuilder path = new StringBuilder("'" + toString() + "'");
        TreeNode parent = getParent();
        while (parent != null) {
            path.insert(0, "'" + parent.toString() + "'" + separator + (parent.isArray() ? "*->" : ""));
            parent = parent.getParent();
        }
        return path.toString() + (isArray() ? "*->" : "");
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int compareTo(TreeNode that) {
        return this.getPath().compareTo(that.getPath());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return value;
    }

}

@@ -990,887 +990,8 @@
 ) %7B%0A
-        if (path == null) %7B // double checked synchronization%0A            synchronized (this) %7B%0A                if (path == null) %7B%0A                    path = getPathInternally();%0A                %7D%0A            %7D%0A        %7D%0A        return path;%0A    %7D%0A%0A    /**%0A     * Gets SQL path from the root node to current node.%0A     *%0A     * @return Sequence of attributes separated by some delimiter.%0A     */%0A    public String getSQLPath() %7B%0A        if (sqlPath == null) %7B // double checked synchronization%0A            synchronized (this) %7B%0A                if (sqlPath == null) %7B%0A                    sqlPath = getSQLPathInternally();%0A                %7D%0A            %7D%0A        %7D%0A        return sqlPath;%0A    %7D%0A%0A    /**%0A     * Gets path from the root node to current node.%0A     *%0A     * @return Sequence of attributes separated by some delimiter.%0A     */%0A    private String getPathInternally() %7B%0A
     
@@ -1042,24 +1042,24 @@
 oString());%0A
+
         Tree
@@ -1415,30 +1415,29 @@
     */%0A    p
-rivate
+ublic
  String getS
@@ -1446,18 +1446,8 @@
 Path
-Internally
 () %7B

Remove internal getSQLPath and getPath