/*
 * Copyright © 2019 by Data Virtuality GmbH
 */
package org.teiid.query.sql;

public class StreamPositionImpl implements StreamPositionAware {
	private static final long serialVersionUID = 4399163370436639215L;
	private int textStart;
	private int textEnd;

	public StreamPositionImpl(int textStart, int textEnd) {
		this.textStart = textStart;
		this.textEnd = textEnd;
	}

	public int getTextStart() {
		return textStart;
	}

	public int getTextEnd() {
		return textEnd;
	}

	@Override
	public void move(int delta) {
		textStart += delta;
		textEnd += delta;
	}

	public void recalc(int start, int length) {
		int newStart = textStart;
		int newEnd = textEnd;
		if (start < textStart) {
			newStart += length;
			newEnd += length;
		}
		textStart = newStart;
		textEnd = newEnd;
	}

	@Override
	public StreamPositionAware clone() {
		return new StreamPositionImpl(textStart, textEnd);
	}

	@Override
	public String toString() {
		return "StreamPositionImpl{" +
				textStart +
				", " + textEnd +
				'}';
	}
}
