All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.leibnizcenter.util.immutabletree.ImmutableTree Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package org.leibnizcenter.util.immutabletree;

import com.google.common.collect.ImmutableList;
import org.leibnizcenter.util.Collections3;

import java.security.InvalidParameterException;
import java.util.List;

/**
 * Created by Maarten on 2016-04-11.
 */
public interface ImmutableTree {
    default int depth(Depth kind) {
        List children = getChildren();
        switch (kind) {
            case RightMostBranches:
                if (Collections3.isNullOrEmpty(children)) {
                    return 1;
                } else {
                    return 1 + children.get(children.size() - 1).depth(kind);
                }
            default:
                throw new InvalidParameterException();
        }
    }

    ImmutableTree replaceChild(int ix, ImmutableTree newChild);
    ImmutableList getChildren();

    ImmutableTree addChild(ImmutableTree nodeToAdd);

    /**
     * NOTE: we should add more for completeness, but not currently needed
     */
    enum Depth {
        RightMostBranches
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy