View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  package org.opencastproject.subtitleparser;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  public abstract class SubtitleCue {
27    private String id;            // Id of cue. 1 or c1
28    private long startTime;       // Start time in ms
29    private long endTime;         // Stop time in ms
30    private List<String> lines;   // Lines that make up the text
31  
32    protected SubtitleCue(SubtitleCue cue) {
33      this.id = cue.getId();
34      this.startTime = cue.getStartTime();
35      this.endTime = cue.getEndTime();
36      this.lines = cue.getLines();
37    }
38  
39    protected SubtitleCue() {
40      this.lines = new ArrayList<>();
41    }
42  
43    /**
44     * A single subtitle segment
45     * @param startTime in milliseconds
46     * @param endTime in milliseconds
47     */
48    protected SubtitleCue(long startTime, long endTime) {
49      this.startTime = startTime;
50      this.endTime = endTime;
51      this.lines = new ArrayList<>();
52    }
53  
54    /**
55     * A single subtitle segment
56     * @param startTime in milliseconds
57     * @param endTime in milliseconds
58     * @param lines the text. Each string will be seperated by a newline
59     */
60    protected SubtitleCue(long startTime, long endTime, List<String> lines) {
61      this.startTime = startTime;
62      this.endTime = endTime;
63      this.lines = lines;
64    }
65  
66    public String getId() {
67      return this.id;
68    }
69  
70    public void setId(String id) {
71      this.id = id;
72    }
73  
74    public long getStartTime() {
75      return this.startTime;
76    }
77  
78    public void setStartTime(long startTime) {
79      this.startTime = startTime;
80    }
81  
82    public long getEndTime() {
83      return this.endTime;
84    }
85  
86    public void setEndTime(long endTime) {
87      this.endTime = endTime;
88    }
89  
90    public List<String> getLines() {
91      return this.lines;
92    }
93  
94    public void setLines(List<String> lines) {
95      this.lines = lines;
96    }
97  
98    public void addLine(String line) {
99      this.lines.add(line);
100   }
101 
102   public String getText() {
103     String[] lineArray = lines.toArray(new String[lines.size()]);
104     return String.join("\n", lineArray);
105   }
106 
107   @Override
108   public String toString() {
109     return this.getText();
110   }
111 }