Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
ponfee committed Jul 9, 2023
1 parent 3bf3af6 commit feff20f
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cn/ponfee/commons/tree/BaseNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @param <A> the attachment biz object type
* @author Ponfee
*/
public abstract class BaseNode<T extends Serializable & Comparable<? super T>, A> implements Serializable, Cloneable {
public abstract class BaseNode<T extends Serializable & Comparable<T>, A> implements Serializable, Cloneable {
private static final long serialVersionUID = -4116799955526185765L;

// -------------------------------------------------------------------基础信息
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/ponfee/commons/tree/FlatNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @param <A> the attachment biz object type
* @author Ponfee
*/
public final class FlatNode<T extends Serializable & Comparable<? super T>, A> extends BaseNode<T, A> {
public final class FlatNode<T extends Serializable & Comparable<T>, A> extends BaseNode<T, A> {
private static final long serialVersionUID = 5191371614061952661L;

private final boolean leaf; // 是否叶子节点
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/ponfee/commons/tree/MapTreeTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @param <A> the attachment biz object type
* @author Ponfee
*/
public class MapTreeTrait<T extends Serializable & Comparable<? super T>, A>
public class MapTreeTrait<T extends Serializable & Comparable<T>, A>
extends LinkedHashMap<String, Object> implements TreeTrait<T, A, MapTreeTrait<T, A>> {
private static final long serialVersionUID = -5799393887664198242L;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/ponfee/commons/tree/NodePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// hashCode()/equals() extends ImmutableArrayList
@JSONType(mappingTo = NodePath.FastjsonDeserializeMarker.class) // fastjson
@JsonDeserialize(using = NodePath.JacksonDeserializer.class) // jackson
public final class NodePath<T extends Serializable & Comparable<? super T>>
public final class NodePath<T extends Serializable & Comparable<T>>
extends ImmutableArrayList<T> implements Comparable<NodePath<T>> {

private static final long serialVersionUID = 9090552044337950223L;
Expand Down Expand Up @@ -109,7 +109,7 @@ public static class FastjsonDeserializeMarker { }
*
* @param <T>
*/
public static class FastjsonDeserializer<T extends Serializable & Comparable<? super T>> implements ObjectDeserializer {
public static class FastjsonDeserializer<T extends Serializable & Comparable<T>> implements ObjectDeserializer {
@Override
@SuppressWarnings("unchecked")
public NodePath<T> deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
Expand All @@ -128,7 +128,7 @@ public int getFastMatchToken() {

// -----------------------------------------------------custom jackson deserialize

public static class JacksonDeserializer<T extends Serializable & Comparable<? super T>> extends JsonDeserializer<NodePath<T>> {
public static class JacksonDeserializer<T extends Serializable & Comparable<T>> extends JsonDeserializer<NodePath<T>> {
@Override
@SuppressWarnings("unchecked")
public NodePath<T> deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/ponfee/commons/tree/PlainNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @param <A> the attachment biz object type
* @author Ponfee
*/
public final class PlainNode<T extends Serializable & Comparable<? super T>, A> extends BaseNode<T, A> {
public final class PlainNode<T extends Serializable & Comparable<T>, A> extends BaseNode<T, A> {
private static final long serialVersionUID = -2189191471047483877L;

public PlainNode(T nid, T pid, A attach) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
*
* @author Ponfee
*/
public class SiblingNodesComparator<T extends Serializable & Comparable<? super T>, A> {
public class SiblingNodesComparator<T extends Serializable & Comparable<T>, A> {

private final Comparator<TreeNode<T, A>> comparator;

private SiblingNodesComparator(Comparator<TreeNode<T, A>> comparator) {
this.comparator = comparator;
}

public static <T extends Serializable & Comparable<? super T>, A, U extends Comparable<? super U>> SiblingNodesComparator<T, A> comparing(Function<TreeNode<T, A>, U> first) {
public static <T extends Serializable & Comparable<T>, A, U extends Comparable<? super U>> SiblingNodesComparator<T, A> comparing(Function<TreeNode<T, A>, U> first) {
// default nullsLast and ASC
return comparing(first, false, true);
}

public static <T extends Serializable & Comparable<? super T>, A, U extends Comparable<? super U>> SiblingNodesComparator<T, A> comparing(Function<TreeNode<T, A>, U> first, boolean nullsFirst, boolean asc) {
public static <T extends Serializable & Comparable<T>, A, U extends Comparable<? super U>> SiblingNodesComparator<T, A> comparing(Function<TreeNode<T, A>, U> first, boolean nullsFirst, boolean asc) {
return new SiblingNodesComparator<>(Comparator.comparing(first, comparator(nullsFirst, asc)));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/ponfee/commons/tree/TreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @param <A> the attachment biz object type
* @author Ponfee
*/
public final class TreeNode<T extends Serializable & Comparable<? super T>, A> extends BaseNode<T, A> {
public final class TreeNode<T extends Serializable & Comparable<T>, A> extends BaseNode<T, A> {
private static final long serialVersionUID = -9081626363752680404L;

public static final String DEFAULT_ROOT_ID = "__ROOT__";
Expand Down Expand Up @@ -91,7 +91,7 @@ public final class TreeNode<T extends Serializable & Comparable<? super T>, A> e
}
}

public static <T extends Serializable & Comparable<? super T>, A> TreeNodeBuilder<T, A> builder(T nid) {
public static <T extends Serializable & Comparable<T>, A> TreeNodeBuilder<T, A> builder(T nid) {
return new TreeNodeBuilder<>(nid);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/ponfee/commons/tree/TreeNodeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @param <A> the attachment biz object type
* @author Ponfee
*/
public final class TreeNodeBuilder<T extends Serializable & Comparable<? super T>, A> {
public final class TreeNodeBuilder<T extends Serializable & Comparable<T>, A> {

private final T nid;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/ponfee/commons/tree/TreeTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @param <E> the TreeTrait type
* @author Ponfee
*/
public interface TreeTrait<T extends Serializable & Comparable<? super T>, A, E extends TreeTrait<T, A, E>> {
public interface TreeTrait<T extends Serializable & Comparable<T>, A, E extends TreeTrait<T, A, E>> {

/**
* Sets node list as children
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/test/tree/NodePathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ public void setPath(NodePath path) {
}
}

public static class NodePathBean2<T extends Serializable & Comparable<? super T>> implements java.io.Serializable {
public static class NodePathBean2<T extends Serializable & Comparable<T>> implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private int id;
private NodePath<T> path; //
private NodePath<T> path; //

public int getId() {
return id;
Expand Down

0 comments on commit feff20f

Please sign in to comment.