mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix NPE bug
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package cn.hutool.core.lang.tree;
|
||||
|
||||
import cn.hutool.core.comparator.CompareUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -74,11 +76,11 @@ public interface Node<T> extends Comparable<Node<T>>, Serializable {
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems"})
|
||||
@Override
|
||||
default int compareTo(Node node) {
|
||||
final Comparable weight = this.getWeight();
|
||||
if (null != weight) {
|
||||
final Comparable weightOther = node.getWeight();
|
||||
return weight.compareTo(weightOther);
|
||||
if(null == node){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
final Comparable weight = this.getWeight();
|
||||
final Comparable weightOther = node.getWeight();
|
||||
return CompareUtil.compare(weight, weightOther);
|
||||
}
|
||||
}
|
||||
|
@@ -12,5 +12,4 @@ public class TreeBuilderTest {
|
||||
of.build();
|
||||
of.append(new ArrayList<>());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ public class TreeTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void sampleTree() {
|
||||
public void sampleTreeTest() {
|
||||
List<Tree<String>> treeList = TreeUtil.build(nodeList, "0");
|
||||
for (Tree<String> tree : treeList) {
|
||||
Assert.assertNotNull(tree);
|
||||
@@ -43,7 +43,7 @@ public class TreeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tree() {
|
||||
public void treeTest() {
|
||||
|
||||
//配置
|
||||
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
|
||||
@@ -66,5 +66,4 @@ public class TreeTest {
|
||||
|
||||
Assert.assertEquals(treeNodes.size(), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user