TEISegmentImpl.java 1.76 KB
package ipipan.clarin.tei.impl.entities;

import ipipan.clarin.tei.api.entities.TEIParagraph;
import ipipan.clarin.tei.api.entities.TEISegment;

/**
 *
 * @author mlenart
 */
class TEISegmentImpl extends TEIAbstractEntity implements TEISegment {

	private TEIParagraph paragraph;
	private int offset;
	private int length;
	private String orth;
	private final boolean nps;
	private int choiceNum = 0;
	private boolean rejected = false;

	public TEISegmentImpl(TEIParagraph paragraph, String id, int offset,
			int length, boolean nps) {
		super(id);
		this.paragraph = paragraph;
		this.offset = offset;
		this.length = length;
		this.nps = nps;
		this.orth = null;
	}

	public TEISegmentImpl(String id, String orth, boolean nps) {
		super(id);
		this.orth = orth;
		this.nps = nps;

		this.offset = -1;
		this.length = -1;
		this.paragraph = null;
	}

	@Override
	public TEIParagraph getParagraph() {
		return paragraph;
	}

	@Override
	public void setParagraph(TEIParagraph paragraph) {
		this.paragraph = paragraph;
	}

	@Override
	public int getOffset() {
		return offset;
	}

	@Override
	public void setOffset(int offset) {
		this.offset = offset;
	}

	@Override
	public int getLength() {
		if (orth != null) {
			return orth.length();
		} else {
			return length;
		}
	}

	@Override
	public boolean hasNps() {
		return nps;
	}

	@Override
	public String getOrth() {
		if (orth != null) {
			return orth;
		} else {
			return paragraph.getText().substring(offset, offset + length);
		}
	}

	@Override
	public int getChoiceNum() {
		return choiceNum;
	}

	@Override
	public void setChoiceNum(int choiceNum) {
		this.choiceNum = choiceNum;
	}

	@Override
	public boolean isRejected() {
		return rejected;
	}

	@Override
	public void setRejected(boolean rejected) {
		this.rejected = rejected;
	}
}