Skip to content

Commit 42e1df3

Browse files
author
zhenya
committed
Added new method for searching phrases
1 parent ab5e293 commit 42e1df3

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/main/java/com/iusenko/subrip/PhraseUtils.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,32 @@ public static Phrase find(long timestamp, List<Phrase> phrases) {
1313
}
1414
return null;
1515
}
16+
17+
public static Phrase find(long start, long end, List<Phrase> phrases) {
18+
StringBuilder sb = new StringBuilder();
19+
int num = 0;
20+
Phrase phrase = new Phrase();
21+
for (Phrase p : phrases) {
22+
boolean a = p.startTime <= start && start < p.endTime;
23+
boolean b = start <= p.startTime && p.endTime <= end;
24+
// boolean c = phrase.startTime < end && end <= phrase.endTime;
25+
26+
if (b || a) {
27+
phrase.endTime = p.endTime;
28+
phrase.endTimeText = p.endTimeText;
29+
30+
if (num == 0) {
31+
phrase.startTime = p.startTime;
32+
phrase.startTimeText = p.startTimeText;
33+
num++;
34+
}
35+
36+
sb.append(p.text).append("\n\n");
37+
}
38+
}
39+
phrase.text = sb.toString().trim();
40+
41+
return phrase;
42+
}
43+
1644
}

0 commit comments

Comments
 (0)