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

org.btrplace.model.Node Maven / Gradle / Ivy

The newest version!
/*
 * Copyright  2021 The BtrPlace Authors. All rights reserved.
 * Use of this source code is governed by a LGPL-style
 * license that can be found in the LICENSE.txt file.
 */

package org.btrplace.model;

/**
 * Model a node.
 * A node should not be instantiated directly. Use {@link Model#newNode()} instead.
 *
 * @author Fabien Hermenier
 * @see Model#newNode()
 */
public class Node implements Element,PhysicalElement {

  private final int id;

    /**
     * The element identifier
     */
    public static final String TYPE = "node";

    /**
     * Make a new node.
     *
     * @param i the node identifier.
     */
    public Node(int i) {
        this.id = i;
    }

    @Override
    public int id() {
        return id;
    }

    @Override
    public String toString() {
        return toString(id);
    }

    /**
     * Helper to stringify a Node.
     *
     * @param id the node identifier.
     * @return the string version of a node having the given identifier.
     */
    public static String toString(int id) {
        return TYPE + "#" + id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Node)) {
            return false;
        }

        Node node = (Node) o;

        return id == node.id();
    }

    @Override
    public int hashCode() {
        return id;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy