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

ars.util.SimpleTree Maven / Gradle / Ivy

The newest version!
package ars.util;

import java.util.Map;
import java.util.HashMap;

/**
 * 树简单实现
 *
 * @author wuyongqiang
 */
public class SimpleTree extends AbstractTree {
    private static final long serialVersionUID = 1L;

    private String id;
    private String name;
    private Map attributes;

    public SimpleTree(String id) {
        this(id, id);
    }

    public SimpleTree(String id, String name) {
        this(id, name, new HashMap(0));
    }

    public SimpleTree(String id, String name, Map attributes) {
        if (id == null) {
            throw new IllegalArgumentException("Id must not be null");
        }
        if (name == null) {
            throw new IllegalArgumentException("Name must not be null");
        }
        this.id = id;
        this.name = name;
        this.attributes = attributes;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public Map getAttributes() {
        return attributes;
    }

    @Override
    public Map format() {
        Map values = super.format();
        values.put("id", this.id);
        values.put("name", this.name);
        values.put("attributes", this.attributes);
        return values;
    }

    @Override
    public int hashCode() {
        return 31 + this.id.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return this == obj || (obj != null && obj instanceof SimpleTree && this.id.equals(((SimpleTree) obj).getId()));
    }

    @Override
    public String toString() {
        return this.name;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy