Newer
Older
RDLProofSystem / src / main / java / inference / rewrite / Position.java
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));
	}
	
	public boolean startWith(Position pos) {
		for (int i = 0; i < pos.size(); i++) {
			if (getPath(i) != pos.getPath(i)) {
				return false;
			}
		}
		return true;
	}
	
	public int size() {
		return paths.size();
	}
	
	private int getPath(int index) {
		if (index >= size()) {
			return -1;
		}
		return paths.get(index);
	}
	
	
	@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();
	}
	
}