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

org.vertexium.Path Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium;

import org.vertexium.util.ArrayIterable;

import java.util.Arrays;
import java.util.Iterator;

public class Path implements Iterable {
    private final String[] vertexIds;

    public Path(String... vertexIds) {
        this.vertexIds = vertexIds;
    }

    public Path(Path path, String vertexId) {
        this.vertexIds = Arrays.copyOf(path.vertexIds, path.vertexIds.length + 1);
        this.vertexIds[this.vertexIds.length - 1] = vertexId;
    }

    public int length() {
        return this.vertexIds.length;
    }

    public String get(int i) {
        return this.vertexIds[i];
    }

    @Override
    public Iterator iterator() {
        return new ArrayIterable<>(this.vertexIds).iterator();
    }

    @Override
    public String toString() {
        return Arrays.toString(vertexIds);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Path pathOther = (Path) o;
        if (pathOther.vertexIds.length != vertexIds.length) {
            return false;
        }
        for (int i = 0; i < vertexIds.length; i++) {
            if (!pathOther.vertexIds[i].equals(vertexIds[i])) {
                return false;
            }
        }

        return true;
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(vertexIds);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy