package jetbrains.mps.ide.depanalyzer;

/*Generated by MPS */

import java.util.List;
import java.util.Set;
import jetbrains.mps.ide.depanalyzer.DependencyUtil.Dependency;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import jetbrains.mps.internal.collections.runtime.SetSequence;
import java.util.HashSet;

public class DepPath {
  private final List<DepLink> myPath;
  private final Set<Dependency> mySeen;
  public DepPath() {
    myPath = ListSequence.fromList(new ArrayList<DepLink>());
    mySeen = SetSequence.fromSet(new HashSet<Dependency>());
  }
  public DepPath(DepPath toCopy) {
    myPath = ListSequence.fromListWithValues(new ArrayList<DepLink>(), toCopy.myPath);
    mySeen = SetSequence.fromSetWithValues(new HashSet<Dependency>(), toCopy.mySeen);
  }
  public void push(DepLink depLink) {
    SetSequence.fromSet(mySeen).addElement(depLink.getRoleModuleKey());
    ListSequence.fromList(myPath).addElement(depLink);
  }
  public void pop() {
    DepLink last = ListSequence.fromList(myPath).removeLastElement();
    SetSequence.fromSet(mySeen).removeElement(last.getRoleModuleKey());
  }
  public boolean seen(DepLink depLink) {
    return SetSequence.fromSet(mySeen).contains(depLink.getRoleModuleKey());
  }
  public DepLink peek() {
    return ListSequence.fromList(myPath).last();
  }
  public Iterable<DepLink> elements() {
    return myPath;
  }
  @Override
  public String toString() {
    return String.valueOf(myPath);
  }
  @Override
  public boolean equals(Object o) {
    if (!(o instanceof DepPath)) {
      return false;
    }
    DepPath p = (DepPath) o;
    List l1 = myPath;
    List l2 = p.myPath;
    return l1.equals(l2);
  }
  @Override
  public int hashCode() {
    List l = myPath;
    return l.hashCode();
  }
}
