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

com.jchanghong.core.lang.tree.Node Maven / Gradle / Ivy

The newest version!
package com.jchanghong.core.lang.tree;

/**
 * 节点接口,提供节点相关的的方法定义
 *
 * @param  ID类型
 * @author looly
 * @since 5.2.4
 */
public interface Node extends Comparable> {
	/**
	 * 获取ID
	 *
	 * @return ID
	 */
	T getId();

	/**
	 * 设置ID
	 *
	 * @param id ID
	 * @return this
	 */
	Node setId(T id);

	/**
	 * 获取父节点ID
	 *
	 * @return 父节点ID
	 */
	T getParentId();

	/**
	 * 设置父节点ID
	 *
	 * @param parentId 父节点ID
	 * @return this
	 */
	Node setParentId(T parentId);

	/**
	 * 获取节点标签名称
	 *
	 * @return 节点标签名称
	 */
	CharSequence getName();

	/**
	 * 设置节点标签名称
	 *
	 * @param name 节点标签名称
	 * @return this
	 */
	Node setName(CharSequence name);

	/**
	 * 获取权重
	 *
	 * @return 权重
	 */
	Comparable getWeight();

	/**
	 * 设置权重
	 *
	 * @param weight 权重
	 * @return this
	 */
	Node setWeight(Comparable weight);

	@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);
		}
		return 0;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy