All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dnbn.submerge.api.subtitle.common.SubtitleLine Maven / Gradle / Ivy

The newest version!
package com.github.dnbn.submerge.api.subtitle.common;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class SubtitleLine implements TimedLine {

	/**
	 * Serial Id
	 */
	private static final long serialVersionUID = 288560648398584309L;

	/**
	 * Subtitle Text. This is the actual text which will be displayed as a subtitle
	 * onscreen.
	 */
	protected List textLines = new ArrayList<>();

	/**
	 * Timecodes
	 */
	protected T time;

	/**
	 * Comparator that only compare timings
	 * 
	 * @return the comparator
	 */
	public static Comparator timeComparator = new Comparator() {

		@Override
		public int compare(TimedLine o1, TimedLine o2) {
			return o1.getTime().compareTo(o2.getTime());
		}
	};

	/**
	 * Constructor
	 */
	public SubtitleLine() {
		super();
	}

	/**
	 * Constructor
	 */
	public SubtitleLine(T time) {
		
		super();
		this.time = time;
	}

	@Override
	public boolean equals(Object obj) {
		
		if (this == obj) {
			return true;
		}
		if (obj == null || getClass() != obj.getClass()) {
			return false;
		}

		TimedLine other = (TimedLine) obj;
		return compareTo(other) == 0;
	}

	@Override
	public int compare(TimedLine o1, TimedLine o2) {

		return o1.compareTo(o2);
	}

	@Override
	public int compareTo(TimedLine o) {

		int compare = this.time.compareTo(o.getTime());
		if (compare == 0) {
			String thisText = String.join(",", this.textLines);
			String otherText = String.join(",", o.getTextLines());
			compare = thisText.compareTo(otherText);
		}

		return compare;
	}

	// ===================== getter and setter start =====================

	@Override
	public T getTime() {
		return this.time;
	}

	public void setTime(T time) {
		this.time = time;
	}

	@Override
	public List getTextLines() {
		return this.textLines;
	}

	public void setTextLines(List textLines) {
		this.textLines = textLines;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy