package inference.rewrite;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import lombok.Getter;

public class Position {
	
	@Getter
	private List<Integer> paths;
	
	public Position(List<Integer> paths) {
		this.paths = Collections.unmodifiableList(paths);
	}
	
	public Position() {
		this.paths = Collections.unmodifiableList(List.of(0));
	}
	
	public Position addPath(int index) {
		List<Integer> nextPaths = new ArrayList<>(paths);
		nextPaths.add(index);
		return new Position(Collections.unmodifiableList(nextPaths));
	}
	
	@Override
	public boolean equals(Object another) {
		if (! (another instanceof Position)) {
			return false;
		}
		Position position = (Position) another;
		return paths.equals(position.getPaths());
	}
	
	@Override
	public int hashCode() {
		return this.paths.hashCode();
	}
	
	@Override
	public String toString() {
		return paths.toString();
	}
	
}
