
org.solovyev.common.collections.tree.Trees Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ---------------------------------------------------------------------
* Contact details
*
* Email: [email protected]
* Site: http://se.solovyev.org
*/
package org.solovyev.common.collections.tree;
import org.solovyev.common.collections.Collections;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public final class Trees {
private Trees() {
throw new AssertionError();
}
/*
**********************************************************************
*
* PUBLIC
*
**********************************************************************
*/
@Nonnull
public static MutableTree newLinkedTree(@Nullable N root) {
return LinkedTree.newInstance(root);
}
@Nonnull
public static MutableTree unmodifiableTree(@Nonnull MutableTree tree) {
return UnmodifiableTree.wrap(tree);
}
@Nonnull
public static MutableTree unmodifiableTree(@Nonnull Tree tree) {
return UnmodifiableTree.wrap(tree);
}
@Nonnull
public static TreeIterator newDepthTreeIterator(@Nonnull Tree tree) {
return new DepthTreeIterator(tree);
}
@Nonnull
public static TreeIterator newDepthTreeIterator(@Nonnull TreeNode teeNode) {
return new DepthTreeIterator(teeNode);
}
/*
**********************************************************************
*
* PACKAGE LOCAL
*
**********************************************************************
*/
@Nonnull
static List extends MutableTreeNode> unmodifiableMutableTreeNodes(@Nonnull Collection extends MutableTreeNode> treeNodes) {
final List> result = new ArrayList>(treeNodes.size());
for (MutableTreeNode treeNode : treeNodes) {
result.add(UnmodifiableTreeNode.wrap(treeNode));
}
return java.util.Collections.unmodifiableList(result);
}
@Nonnull
static List extends MutableTreeNode> unmodifiableTreeNodes(@Nonnull Collection extends TreeNode> treeNodes) {
final List> result = new ArrayList>(treeNodes.size());
for (TreeNode treeNode : treeNodes) {
result.add(UnmodifiableTreeNode.wrap(treeNode));
}
return java.util.Collections.unmodifiableList(result);
}
@Nonnull
static BinarySearchTreeNode newBinarySearchTreeNode(@Nullable T value) {
return newBinarySearchTreeNode(value, null);
}
@Nonnull
static BinarySearchTreeNode newBinarySearchTreeNode(T value, @Nullable BinarySearchTreeNode parent) {
return new BinarySearchTreeNode(value, parent);
}
@Nonnull
static BinarySearchTree newBinarySearchTree(@Nonnull BinarySearchTreeNode root) {
return new BinarySearchTree(root, Collections.naturalComparator());
}
@Nonnull
static BinarySearchTree newBinarySearchTree(@Nullable T value) {
return new BinarySearchTree(newBinarySearchTreeNode(value), Collections.naturalComparator());
}
@Nonnull
static PrefixTree newPrefixTree() {
return new PrefixTree();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy