package be.iminds.ilabt.jfed.gts.model;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;

/**
 * User: twalcari
 * Date: 2/11/2016
 * Time: 17:25
 */
public interface GtsAdjacency {
    @Nonnull
    PortId getPortId1();

    @Nonnull
    PortId getPortId2();

    final class PortId {
        @Nullable
        private final String parentId;
        @Nonnull
        private final String portId;

        public PortId(@Nullable String parentId, @Nonnull String portId) {
            this.parentId = parentId;
            this.portId = portId;
        }

        @Nullable
        public String getParentId() {
            return parentId;
        }

        @Nonnull
        public String getPortId() {
            return portId;
        }


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

            PortId portId1 = (PortId) o;

            if (parentId != null ? !Objects.equals(parentId, portId1.parentId) : portId1.parentId != null) return false;
            return Objects.equals(portId, portId1.portId);
        }

        @Override
        public int hashCode() {
            int result = parentId != null ? parentId.hashCode() : 0;
            result = 31 * result + portId.hashCode();
            return result;
        }

        @Override
        public String toString() {
            return parentId + '#' + portId;
        }
    }
}
