Skip to content

Commit

Permalink
fix: chapter.get(0)
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Mar 9, 2022
1 parent 45347d4 commit bfd754a
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TextReaderCore {
private Vector<Chapter> chapterList = new Vector<>(0);
private int chapterIndex;

private String noBlankChapterText;
private String noBlankChapterText = "";
private int positionInChapter = 0;

public void initStateService(){
Expand All @@ -47,6 +47,8 @@ public void initWithFile(VirtualFile file, int maxLineSize, Pattern pattern) thr
textFile = new TextFile(file);
chapterList = ChapterUtil.getChapters(textFile, maxLineSize, pattern);
chapterIndex = 0;
noBlankChapterText = "";
positionInChapter = 0;
saveState();
eventManage.notifyEvent(new ChapterChangeEvent(chapterList.get(chapterIndex)));
}
Expand All @@ -66,7 +68,7 @@ public Vector<Chapter> getChapters(){

public Chapter getChapter(){
Chapter chapter = null;
if(chapterIndex > 0 && chapterIndex < chapterList.size()){
if(chapterIndex >= 0 && chapterIndex < chapterList.size()){
chapter = chapterList.get(chapterIndex);
}
return chapter;
Expand Down Expand Up @@ -96,12 +98,9 @@ public String readChapterContent() throws IOException {
String text = "";
Chapter chapter = getChapter();
if(chapter != null){
long startTime = System.currentTimeMillis();
text = ChapterUtil.formatChapterContent(textFile, chapter);
noBlankChapterText = text.replaceFirst("\n", "##").replaceAll("\\s*", "");
positionInChapter = 0;
long endTime = System.currentTimeMillis();
System.out.println("time:" + (endTime - startTime));
}
return text;
}
Expand Down

0 comments on commit bfd754a

Please sign in to comment.