com.ibm.wala.util.graph.BasicTree Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.ibm.wala.util Show documentation
Show all versions of com.ibm.wala.util Show documentation
T. J. Watson Libraries for Analysis
The newest version!
/*
* Copyright (c) 2007 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*/
package com.ibm.wala.util.graph;
import com.ibm.wala.util.collections.SimpleVector;
import org.jspecify.annotations.Nullable;
/** A simple, extremely inefficient tree implementation */
public class BasicTree {
private final T value;
private final SimpleVector> children = new SimpleVector<>();
protected BasicTree(T value) {
this.value = value;
}
public static BasicTree make(T value) {
if (value == null) {
throw new IllegalArgumentException("null value");
}
return new BasicTree<>(value);
}
public T getRootValue() {
return value;
}
@Nullable
public T getChildValue(int i) {
if (children.get(i) == null) {
return null;
} else {
return children.get(i).getRootValue();
}
}
public BasicTree getChild(int i) {
return children.get(i);
}
public void setChild(int i, BasicTree tree) {
children.set(i, tree);
}
public int getMaxChildIndex() {
return children.getMaxIndex();
}
}